opendj-server-legacy/src/main/java/org/opends/server/plugins/ReferentialIntegrityPlugin.java
@@ -43,6 +43,7 @@ import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.config.server.ConfigChangeResult; import org.forgerock.opendj.config.server.ConfigException; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.ldap.AttributeDescription; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.DN; @@ -50,7 +51,6 @@ import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.SearchScope; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.server.config.meta.PluginCfgDefn; import org.forgerock.opendj.server.config.meta.ReferentialIntegrityPluginCfgDefn.CheckReferencesScopeCriteria; import org.forgerock.opendj.server.config.server.PluginCfg; @@ -150,15 +150,6 @@ */ public static final String DELETE_DNS="deleteDNs"; /** The buffered reader that is used to read the log file by the background thread. */ private BufferedReader reader; /** * The buffered writer that is used to write update records in the log * when the plugin is in background processing mode. */ private BufferedWriter writer; /** * Specifies the mapping between the attribute type (specified in the * attributeTypes list) and the filter which the plugin should use @@ -741,7 +732,7 @@ /** * Sets up the log file that the plugin can write update recored to and * the background thread can use to read update records from. The specifed * the background thread can use to read update records from. The specified * log file name is the name to use for the file. If the file exists from * a previous run, use it. * @@ -770,24 +761,12 @@ } /** * Sets up a buffered writer that the plugin can use to write update records * with. * Returns a buffered writer that the plugin can use to write update records with. * * @throws IOException If a new file writer cannot be created. */ private void setupWriter() throws IOException { writer=new BufferedWriter(new FileWriter(logFile, true)); } /** * Sets up a buffered reader that the background thread can use to read * update records with. * * @throws IOException If a new file reader cannot be created. */ private void setupReader() throws IOException { reader=new BufferedReader(new FileReader(logFile)); private BufferedWriter setupWriter() throws IOException { return new BufferedWriter(new FileWriter(logFile, true)); } /** @@ -802,16 +781,13 @@ private void writeLog(Map<DN,DN> modDNmap) { synchronized(logFile) { try try (BufferedWriter writer = setupWriter()) { setupWriter(); for(Map.Entry<DN,DN> mapEntry : modDNmap.entrySet()) { writer.write(mapEntry.getKey() + "\t" + mapEntry.getValue()); writer.newLine(); } writer.flush(); writer.close(); } catch (IOException io) { @@ -829,16 +805,13 @@ private void writeLog(Set<DN> deleteDNset) { synchronized(logFile) { try try (BufferedWriter writer = setupWriter()) { setupWriter(); for (DN deletedEntryDN : deleteDNset) { writer.write(deletedEntryDN.toString()); writer.newLine(); } writer.flush(); writer.close(); } catch (IOException io) { @@ -864,7 +837,8 @@ return; } setupReader(); try (BufferedReader reader = new BufferedReader(new FileReader(logFile))) { String line; while((line=reader.readLine()) != null) { try { @@ -883,7 +857,7 @@ logger.error(ERR_PLUGIN_REFERENT_CANNOT_DECODE_STRING_AS_DN, e.getMessage()); } } reader.close(); } logFile.delete(); logFile.createNewFile(); } catch (IOException io) { opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -30,6 +30,7 @@ import java.io.File; import java.io.InputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -67,6 +68,7 @@ import org.opends.server.types.SearchFilter; import org.opends.server.util.CollectionUtils; import org.opends.server.util.ServerConstants; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -87,6 +89,25 @@ assertNotNull(schemaBackend); } @AfterClass public void removeFilesCreatedInTests() { final File schemaDir = DirectoryServer.getEnvironmentConfig().getSchemaDirectory(); final List<String> filesCreatedInTests = Arrays.asList( "98-schema-test-attrtype.ldif", "98-schema-test-replaceattrtype.ldif", "98-schema-test-oc.ldif", "98-schema-test-nameform.ldif", "98-schema-test-dcr.ldif", "98-schema-test-dsr.ldif", "98-schema-test-mru.ldif"); for (String fileCreatedInTests : filesCreatedInTests) { new File(schemaDir, fileCreatedInTests).delete(); } } /** * Tests the {@code initializeBackend} method by providing a null * configuration entry. @@ -827,12 +848,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddAttributeTypeObsoleteEMR() throws Exception public void testAddAttributeTypeObsoleteEMR() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddATObsoleteEMRMatch", "1.3.6.1.4.1.26027.1.999.20", true); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -845,6 +867,12 @@ runModify(argsNotPermissive(), ldif, System.err, CONSTRAINT_VIOLATION); } finally { deregisterAttributeType("testaddatobsoleteemr-oid"); deregisterMatchingRule(matchingRule); } } /** * Tests the behavior of the schema backend when attempting to add a new @@ -1163,12 +1191,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testRemoveAttributeTypeReferencedByMRU() throws Exception public void testRemoveAttributeTypeReferencedByMRU() throws Exception { MatchingRule matchingRule = getMatchingRule("testRemoveATRefByMRUMatch", "1.3.6.1.4.1.26027.1.999.17", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -1196,13 +1225,36 @@ runModify(argsNotPermissive(), ldif, UNWILLING_TO_PERFORM); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testremoveatrefbymrumru")); assertMatchingRuleUseExistsWithName(matchingRule, "testremoveatrefbymrumru"); assertTrue(DirectoryServer.getSchema().hasAttributeType(attrName)); } finally { DirectoryServer.getSchema(); deregisterMatchingRuleUse(matchingRule); deregisterAttributeType("testremoveatrefbymruat-oid"); deregisterMatchingRule(matchingRule); } } private void deregisterAttributeType(String nameOrOid) throws DirectoryException { org.opends.server.types.Schema schema = DirectoryServer.getSchema(); schema.deregisterAttributeType(schema.getAttributeType(nameOrOid)); } private void deregisterMatchingRuleUse(MatchingRule matchingRule) throws DirectoryException { org.opends.server.types.Schema schema = DirectoryServer.getSchema(); schema.deregisterMatchingRuleUse(schema.getMatchingRuleUse(matchingRule)); } private void deregisterMatchingRule(MatchingRule matchingRule) throws DirectoryException { DirectoryServer.getSchema().deregisterMatchingRule(matchingRule); } /** * Tests the behavior of the schema backend when attempting to add a new @@ -3587,12 +3639,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseSuccessful() throws Exception public void testAddMatchingRuleUseSuccessful() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUSuccessfulMatch", "1.3.6.1.4.1.26027.1.999.10", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3605,10 +3658,13 @@ runModify(argsNotPermissive(), ldif, System.err, SUCCESS); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testaddmrusuccessful")); assertMatchingRuleUseExistsWithName(matchingRule, "testaddmrusuccessful"); } finally { deregisterMatchingRuleUse(matchingRule); deregisterMatchingRule(matchingRule); } } /** @@ -3618,12 +3674,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseToAltSchemaFile() throws Exception public void testAddMatchingRuleUseToAltSchemaFile() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUToAltSchemaFileMatch", "1.3.6.1.4.1.26027.1.999.18", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3635,19 +3692,21 @@ assertSchemaDoesNotHaveMatchingRuleUse(matchingRule); File schemaFile = new File(SchemaConfigManager.getSchemaDirectoryPath(), "98-schema-test-mru.ldif"); File schemaFile = new File(SchemaConfigManager.getSchemaDirectoryPath(), "98-schema-test-mru.ldif"); assertFalse(schemaFile.exists()); runModify(argsNotPermissive(), ldif, System.err, SUCCESS); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testaddmrutoaltschemafile")); assertMatchingRuleUseExistsWithName(matchingRule, "testaddmrutoaltschemafile"); assertTrue(schemaFile.exists()); } finally { deregisterMatchingRuleUse(matchingRule); deregisterMatchingRule(matchingRule); } } /** * Tests the behavior of the schema backend when attempting to replace an @@ -3656,12 +3715,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testReplaceMatchingRuleUseSuccessful() throws Exception public void testReplaceMatchingRuleUseSuccessful() throws Exception { MatchingRule matchingRule = getMatchingRule("testReplaceMRUSuccessfulMatch", "1.3.6.1.4.1.26027.1.999.11", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3681,9 +3741,13 @@ runModify(argsPermissive(), ldif, System.err, SUCCESS); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testreplacemrusuccessful")); assertMatchingRuleUseExistsWithName(matchingRule, "testreplacemrusuccessful"); } finally { deregisterMatchingRuleUse(matchingRule); deregisterMatchingRule(matchingRule); } } /** @@ -3693,12 +3757,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testRemoveAndAddMatchingRuleUse() throws Exception public void testRemoveAndAddMatchingRuleUse() throws Exception { MatchingRule matchingRule = getMatchingRule("testRemoveAndAddMRUMatch", "1.3.6.1.4.1.26027.1.999.12", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3723,10 +3788,13 @@ runModify(argsNotPermissive(), ldif, System.err, SUCCESS); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testremoveandaddmru")); assertMatchingRuleUseExistsWithName(matchingRule, "testremoveandaddmru"); } finally { deregisterMatchingRuleUse(matchingRule); deregisterMatchingRule(matchingRule); } } /** @@ -3737,12 +3805,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseMRConflict() throws Exception public void testAddMatchingRuleUseMRConflict() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUMRConflictMatch", "1.3.6.1.4.1.26027.1.999.14", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3762,10 +3831,20 @@ runModify(argsNotPermissive(), ldif, ATTRIBUTE_OR_VALUE_EXISTS); MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertMatchingRuleUseExistsWithName(matchingRule, "testaddmrumrconflict"); } finally { deregisterMatchingRuleUse(matchingRule); deregisterMatchingRule(matchingRule); } } private void assertMatchingRuleUseExistsWithName(MatchingRule matchingRule, String mruName) { MatchingRuleUse mru = DirectoryServer.getSchema().getMatchingRuleUse(matchingRule); assertNotNull(mru); assertTrue(mru.hasName("testaddmrumrconflict")); assertTrue(mru.hasName(mruName)); } /** @@ -3796,12 +3875,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseAttributeTypeUndefined() throws Exception public void testAddMatchingRuleUseAttributeTypeUndefined() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUATUndefinedMatch", "1.3.6.1.4.1.26027.1.999.16", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3815,6 +3895,11 @@ runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION); } finally { deregisterMatchingRule(matchingRule); } } /** * Tests the behavior of the schema backend when attempting to add a new @@ -3823,13 +3908,14 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseAttributeTypeMultipleUndefined() throws Exception public void testAddMatchingRuleUseAttributeTypeMultipleUndefined() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUATMultipleUndefinedMatch", "1.3.6.1.4.1.26027.1.999.19", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3843,6 +3929,11 @@ runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION); } finally { deregisterMatchingRule(matchingRule); } } private void assertSchemaDoesNotHaveMatchingRuleUse(MatchingRule matchingRule) { @@ -3859,12 +3950,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseObsoleteMatchingRule() throws Exception public void testAddMatchingRuleUseObsoleteMatchingRule() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUObsoleteMRMatch", "1.3.6.1.4.1.26027.1.999.21", true); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3877,6 +3969,11 @@ runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION); } finally { deregisterMatchingRule(matchingRule); } } /** * Tests the behavior of the schema backend when attempting to add a new @@ -3885,12 +3982,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testAddMatchingRuleUseObsoleteAttributeType() throws Exception public void testAddMatchingRuleUseObsoleteAttributeType() throws Exception { MatchingRule matchingRule = getMatchingRule("testAddMRUObsoleteATMatch", "1.3.6.1.4.1.26027.1.999.22", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3908,6 +4006,12 @@ runModify(argsNotPermissive(), ldif, CONSTRAINT_VIOLATION); } finally { deregisterAttributeType("testaddmruobsoleteat-oid"); deregisterMatchingRule(matchingRule); } } private void runModify(String[] args, String ldifContent, ResultCode expectedRC) { @@ -3947,12 +4051,13 @@ * @throws Exception If an unexpected problem occurs. */ @Test public void testRemoveMatchingRuleUseSuccessful() throws Exception public void testRemoveMatchingRuleUseSuccessful() throws Exception { MatchingRule matchingRule = getMatchingRule("testRemoveMRUSuccessfulMatch", "1.3.6.1.4.1.26027.1.999.13", false); DirectoryServer.registerMatchingRule(matchingRule, false); DirectoryServer.getSchema().registerMatchingRule(matchingRule, false); try { String ldif = toLdif( "dn: cn=schema", "changetype: modify", @@ -3972,6 +4077,11 @@ runModify(argsNotPermissive(), ldif, System.err, SUCCESS); assertSchemaDoesNotHaveMatchingRuleUse(matchingRule); } finally { deregisterMatchingRule(matchingRule); } } /** * Tests the behavior of the schema backend when attempting to add another opendj-server-legacy/src/test/java/org/opends/server/schema/CollationMatchingRuleTest.java
@@ -17,10 +17,11 @@ package org.opends.server.schema; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.forgerock.opendj.ldap.DN; import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.SearchScope; import org.opends.server.TestCaseUtils; import org.opends.server.controls.ServerSideSortRequestControl; import org.opends.server.controls.VLVRequestControl; @@ -28,27 +29,27 @@ import org.opends.server.protocols.internal.SearchRequest; import org.opends.server.tools.LDAPModify; import org.opends.server.types.Control; import org.forgerock.opendj.ldap.DN; import org.opends.server.types.Entry; import org.opends.server.types.LDAPException; import org.opends.server.types.SearchResultEntry; import org.opends.server.util.CollectionUtils; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static java.util.Arrays.*; import static org.forgerock.opendj.ldap.SearchScope.*; import static org.opends.server.protocols.internal.InternalClientConnection.*; import static org.opends.server.protocols.internal.Requests.*; import static org.testng.Assert.*; /** * Integration tests for collation matching rules. */ /** Integration tests for collation matching rules. */ @SuppressWarnings("javadoc") public final class CollationMatchingRuleTest extends SchemaTestCase { /** * Ensures that the Directory Server is running before executing the * testcases. * Ensures that the Directory Server is running before executing the testcases. * * @throws Exception If an unexpected problem occurs. */ @@ -64,7 +65,6 @@ user4 = DN.valueOf("cn=user4,dc=example,dc=com"); } /** * Test to verify an ADD of an entry containing international characters. * @throws Exception If an unexpected problem occurs. @@ -96,148 +96,83 @@ assertEquals(err,0); } /** * Test to search the collation equality matching rule using OID. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation equality matching rule using OID. */ @Test(dependsOnMethods = "addEntry") public void searchCollationEqualityUsingOID() throws Exception { //Search the collation rule with OID of en and no suffix in the filter. SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "cn:1.3.6.1.4.1.42.2.27.9.4.34.1:=sanchez"); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "cn:1.3.6.1.4.1.42.2.27.9.4.34.1:=sanchez"); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation equality matching rule using language Tag. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation equality matching rule using language Tag. */ @Test(dependsOnMethods = "addEntry") public void searchCollationEqualityUsingLanguageTag() throws Exception { //Search the collation rule with language tag of en and no suffix //in the filter. SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "cn:en:=sanchez"); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "cn:en:=sanchez"); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation Less than matching rule using OID and suffix. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation Less than matching rule using OID and suffix. */ @Test(dependsOnMethods = "addEntry") public void searchCollationLTUsingOIDSuffix() throws Exception { //Search the collation rule with OID of es and suffix in the filter. String filter = "departmentnumber:1.3.6.1.4.1.42.2.27.9.4.49.1.1:=abc120"; SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, filter); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, filter); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation Less than Equal to matching rule using * Language Tag and suffix. * Test to search the collation Less than Equal to matching rule using Language Tag and suffix. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) @Test(dependsOnMethods = "addEntry") public void searchCollationLTEUsingLanguageSuffix() throws Exception { //Search the collation rule with tag of fr and suffix in the filter. SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "carLicense:fr.2:=ebe2"); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "carLicense:fr.2:=ebe2"); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation Greater than matching rule using language * tag. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation Greater than matching rule using language tag. */ @Test(dependsOnMethods = "addEntry") public void searchCollationGTUsingLanguage() throws Exception { //Search the collation rule with tag of fr in the filter. SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "carLicense:fr.5:=ebe1"); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "carLicense:fr.5:=ebe1"); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation Greater than Equal to matching rule using * language tag. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation Greater than Equal to matching rule using language tag. */ @Test(dependsOnMethods = "addEntry") public void searchCollationGTEUsingLanguage() throws Exception { //Search the collation rule with tag of es and suffix in the filter. SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "departmentnumber:es.4:=abc111"); InternalSearchOperation searchOperation = getRootConnection().processSearch(request); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned. assertNotNull(e); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "departmentnumber:es.4:=abc111"); searchCollationAtLeastOneEntryReturned(request); } /** * Test to search the collation substring matching rule using * language tag and suffix. */ @Test(dependsOnMethods = {"org.opends.server.schema."+ "CollationMatchingRuleTest.addEntry"}) /** Test to search the collation substring matching rule using language tag and suffix. */ @Test(dependsOnMethods = "addEntry") public void searchCollationSubstring() throws Exception { /*Search the collation rule with tag of en and suffix in the filter. *It searches for string quebec against the value of sn which is * Qu\u00e9bec. */ SearchRequest request = newSearchRequest("uid=user,o=test", SearchScope.WHOLE_SUBTREE, "sn:en.6:=*u*bec"); SearchRequest request = newSearchRequest("uid=user,o=test", WHOLE_SUBTREE, "sn:en.6:=*u*bec"); searchCollationAtLeastOneEntryReturned(request); } private void searchCollationAtLeastOneEntryReturned(SearchRequest request) { InternalSearchOperation searchOperation = getRootConnection().processSearch(request); searchOperation.run(); assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); List<SearchResultEntry> entries = searchOperation.getSearchEntries(); SearchResultEntry e = entries.get(0); //An entry must be returned for sn=quebec. assertNotNull(e); assertNotNull(entries.get(0)); } private DN user1; @@ -245,7 +180,6 @@ private DN user3; private DN user4; /** * Test to verify the Sort control works well with the Collation * Less-than-equal-to matching rule and French Locale. @@ -253,17 +187,11 @@ @Test public void testSortControlLTERule() throws Exception { ArrayList<DN> expectedDNOrder = new ArrayList<>(); expectedDNOrder.add(user4); expectedDNOrder.add(user3); expectedDNOrder.add(user2); expectedDNOrder.add(user1); ArrayList<Control> requestControls = new ArrayList<>(); requestControls.add(new ServerSideSortRequestControl("displayname:fr")); ValidateSortControl("displayname:fr-FR.6:=A*", expectedDNOrder, requestControls); List<DN> expectedDNOrder = asList(user4, user3, user2, user1); List<Control> requestControls = serverSideSortControl("displayname:fr"); validateSortControl("displayname:fr-FR.6:=A*", expectedDNOrder, requestControls); } /** * Test to verify the Sort control works with Collation equality * matching rule and Spanish locale. @@ -271,17 +199,11 @@ @Test public void testSortControlEQRule() throws Exception { ArrayList<DN> expectedDNOrder = new ArrayList<>(); expectedDNOrder.add(user4); expectedDNOrder.add(user3); expectedDNOrder.add(user2); expectedDNOrder.add(user1); ArrayList<Control> requestControls = new ArrayList<>(); requestControls.add(new ServerSideSortRequestControl("displayname:es")); ValidateSortControl("displayname:es.6:=A*", expectedDNOrder, requestControls); List<DN> expectedDNOrder = asList(user4, user3, user2, user1); List<Control> requestControls = serverSideSortControl("displayname:es"); validateSortControl("displayname:es.6:=A*", expectedDNOrder, requestControls); } /** * Test to verify the Sort control works with Collation greater * than matching rule and English locale in a descending order. @@ -289,47 +211,35 @@ @Test public void testSortControlGTRule() throws Exception { ArrayList<DN> expectedDNOrder = new ArrayList<>(); expectedDNOrder.add(user1); expectedDNOrder.add(user2); expectedDNOrder.add(user3); expectedDNOrder.add(user4); ArrayList<Control> requestControls = new ArrayList<>(); requestControls.add(new ServerSideSortRequestControl("-displayname:en")); ValidateSortControl("displayname:en-US.6:=A*", expectedDNOrder, requestControls); List<DN> expectedDNOrder = asList(user1, user2, user3, user4); List<Control> requestControls = serverSideSortControl("-displayname:en"); validateSortControl("displayname:en-US.6:=A*", expectedDNOrder, requestControls); } /** * Tests the Sort control with the VLV control using a collation equality * matching rule. */ /** Tests the Sort control with the VLV control using a collation equality matching rule. */ @Test public void testVLVSortControl() throws Exception { ArrayList<DN> expectedDNOrder = new ArrayList<>(); expectedDNOrder.add(user4); expectedDNOrder.add(user3); expectedDNOrder.add(user2); expectedDNOrder.add(user1); ArrayList<Control> requestControls = new ArrayList<>(); requestControls.add(new ServerSideSortRequestControl("displayname:fr")); requestControls.add(new VLVRequestControl(0, 4, 1, 0)); ValidateSortControl("objectclass=inetOrgPerson", expectedDNOrder, requestControls); List<DN> expectedDNOrder = asList(user4, user3, user2, user1); List<Control> requestControls = CollectionUtils.<Control> newArrayList( new ServerSideSortRequestControl("displayname:fr"), new VLVRequestControl(0, 4, 1, 0)); validateSortControl("objectclass=inetOrgPerson", expectedDNOrder, requestControls); } private List<Control> serverSideSortControl(String sortOrderString) throws LDAPException { return Arrays.<Control> asList(new ServerSideSortRequestControl(sortOrderString)); } private void ValidateSortControl(String searchFilter, ArrayList<DN> expectedDNOrder, ArrayList<Control> requestControls) throws Exception private void validateSortControl(String searchFilter, List<DN> expectedDNOrder, List<Control> requestControls) throws Exception { try { populateEntriesForControl(); SearchRequest request = newSearchRequest(DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, searchFilter) SearchRequest request = newSearchRequest(DN.valueOf("dc=example,dc=com"), WHOLE_SUBTREE, searchFilter) .addControl(requestControls); InternalSearchOperation internalSearch = getRootConnection().processSearch(request); assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); @@ -351,7 +261,6 @@ return results; } private void populateEntriesForControl() throws Exception { TestCaseUtils.clearBackend("userRoot", "dc=example,dc=com");