Skip to content

Commit c0959dd

Browse files
committed
UY-968 code reuse in tests
1 parent 5abd2f0 commit c0959dd

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

ldap/src/test/java/pl/edu/icm/unity/ldap/console/LDAPAuthenticatorConfigurationTest.java

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ public void serializationIsIdempotentForMinimalConfigUsedTemplateBasedDNResolvin
5353
.get();
5454
sourceCfg.put("retrieval.password.enableAssociation", "false");
5555

56-
LdapConfiguration processor = new LdapConfiguration();
57-
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), LdapPasswordVerificator.NAME,
58-
msg);
59-
String converted = processor.toProperties(LdapPasswordVerificator.NAME, msg);
60-
61-
Properties result = ConfigurationComparator.fromString(converted, PREFIX).get();
56+
Properties result = parsePropertiesAndBack(sourceCfg, LdapPasswordVerificator.NAME);
6257

6358
createComparator(PREFIX, META)
6459
.ignoringSuperflous("embeddedTranslationProfile", "additionalSearch.1.scope", "validUsersFilter")
@@ -74,11 +69,7 @@ public void serializationIsIdempotentForMinimalCertConfigUsedTemplateBasedDNReso
7469
.update("userDNTemplate", "cn={USERNAME}").get();
7570
sourceCfg.put("retrieval.tls.enableAssociation", "false");
7671

77-
LdapConfiguration processor = new LdapConfiguration();
78-
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), LdapCertVerificator.NAME,
79-
msg);
80-
String converted = processor.toProperties(LdapCertVerificator.NAME, msg);
81-
Properties result = ConfigurationComparator.fromString(converted, PREFIX).get();
72+
Properties result = parsePropertiesAndBack(sourceCfg, LdapCertVerificator.NAME);
8273

8374
createComparator(PREFIX, META)
8475
.ignoringSuperflous("embeddedTranslationProfile", "additionalSearch.1.scope")
@@ -93,11 +84,8 @@ public void serializationIsIdempotentForMinimalExplicitDefaultsConfigUsedTemplat
9384
Properties sourceCfg = ConfigurationGenerator.generateMinimalWithDefaults(PREFIX, META)
9485
.update("userDNTemplate", "cn={USERNAME}").get();
9586
sourceCfg.put("retrieval.password.enableAssociation", "false");
96-
LdapConfiguration processor = new LdapConfiguration();
97-
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), LdapPasswordVerificator.NAME,
98-
msg);
99-
String converted = processor.toProperties(LdapPasswordVerificator.NAME, msg);
100-
Properties result = ConfigurationComparator.fromString(converted, PREFIX).get();
87+
88+
Properties result = parsePropertiesAndBack(sourceCfg, LdapPasswordVerificator.NAME);
10189

10290
createComparator(PREFIX, META).ignoringMissing("translationProfile")
10391
.ignoringSuperflous("embeddedTranslationProfile", "additionalSearch.1.scope")
@@ -119,11 +107,9 @@ public void serializationIsIdempotentForCompleteNonDefaultConfigUsedTemplateBase
119107
Properties sourceCfgRet = ConfigurationGenerator.generateCompleteWithNonDefaults(
120108
PasswordRetrievalProperties.P, PasswordRetrievalProperties.defaults).get();
121109
sourceCfg.putAll(sourceCfgRet);
122-
LdapConfiguration processor = new LdapConfiguration();
123-
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), LdapPasswordVerificator.NAME,
124-
msg);
125-
String converted = processor.toProperties(LdapPasswordVerificator.NAME, msg);
126-
Properties result = ConfigurationComparator.fromString(converted, PREFIX).get();
110+
111+
Properties result = parsePropertiesAndBack(sourceCfg, LdapPasswordVerificator.NAME);
112+
127113
createComparator(PREFIX, META)
128114
.ignoringMissing("translationProfile").checkMatching(result, sourceCfg);
129115
}
@@ -142,11 +128,8 @@ public void serializationIsIdempotentForCompleteNonDefaultConfigUsedLdapSearchDN
142128
Properties sourceCfgRet = ConfigurationGenerator.generateCompleteWithNonDefaults(
143129
PasswordRetrievalProperties.P, PasswordRetrievalProperties.defaults).get();
144130
sourceCfg.putAll(sourceCfgRet);
145-
LdapConfiguration processor = new LdapConfiguration();
146-
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), LdapPasswordVerificator.NAME,
147-
msg);
148-
String converted = processor.toProperties(LdapPasswordVerificator.NAME, msg);
149-
Properties result = ConfigurationComparator.fromString(converted, PREFIX).get();
131+
132+
Properties result = parsePropertiesAndBack(sourceCfg, LdapPasswordVerificator.NAME);
150133

151134
createComparator(PREFIX, META)
152135
.withAlias(PREFIX + "additionalSearch.searchUserDN.filter", PREFIX + "additionalSearch.1.filter")
@@ -156,4 +139,14 @@ public void serializationIsIdempotentForCompleteNonDefaultConfigUsedLdapSearchDN
156139
.withExpectedChange("userDNSearchKey", "searchUserDN")
157140
.checkMatching(result, sourceCfg);
158141
}
142+
143+
private Properties parsePropertiesAndBack(Properties sourceCfg, String verificatorType)
144+
{
145+
LdapConfiguration processor = new LdapConfiguration();
146+
processor.fromProperties(ConfigurationComparator.getAsString(sourceCfg), verificatorType,
147+
msg);
148+
String converted = processor.toProperties(verificatorType, msg);
149+
150+
return ConfigurationComparator.fromString(converted, PREFIX).get();
151+
}
159152
}

0 commit comments

Comments
 (0)