| | |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.backends.SchemaTestMatchingRuleImpl; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.SchemaHandler; |
| | | import org.opends.server.core.SchemaHandler.SchemaUpdater; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | @SuppressWarnings("javadoc") |
| | | public class AddSchemaFileTaskTestCase extends TasksTestCase |
| | | { |
| | | private static List<MatchingRule> matchingRulesToRemove = new ArrayList<>(); |
| | | private static List<String> matchingRulesToRemove = new ArrayList<>(); |
| | | |
| | | /** |
| | | * Make sure that the Directory Server is running. |
| | |
| | | TestCaseUtils.startServer(); |
| | | } |
| | | |
| | | private SchemaHandler getSchemaHandler() |
| | | { |
| | | return DirectoryServer.getInstance().getServerContext().getSchemaHandler(); |
| | | } |
| | | |
| | | @AfterClass |
| | | public void deregisterMatchingRules() throws Exception |
| | | { |
| | | for (MatchingRule matchingRule : matchingRulesToRemove) |
| | | getSchemaHandler().updateSchema(new SchemaUpdater() |
| | | { |
| | | org.opends.server.types.Schema schema = DirectoryServer.getSchema(); |
| | | schema.deregisterMatchingRuleUse(schema.getMatchingRuleUse(matchingRule)); |
| | | schema.deregisterMatchingRule(matchingRule); |
| | | } |
| | | @Override |
| | | public void update(SchemaBuilder builder) throws DirectoryException |
| | | { |
| | | for (String mrOid : matchingRulesToRemove) |
| | | { |
| | | builder.removeMatchingRule(mrOid); |
| | | builder.removeMatchingRuleUse(mrOid); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void registerNewMatchingRule(String name, String oid) throws DirectoryException |
| | | private void registerNewMatchingRule(final String name, final String oid) throws DirectoryException |
| | | { |
| | | MatchingRule matchingRule = new SchemaBuilder(Schema.getCoreSchema()) |
| | | .buildMatchingRule(oid) |
| | | .syntaxOID(CoreSchema.getDirectoryStringSyntax().getOID()) |
| | | .names(name) |
| | | .implementation(new SchemaTestMatchingRuleImpl()) |
| | | .addToSchema() |
| | | .toSchema() |
| | | .getMatchingRule(oid); |
| | | DirectoryServer.getSchema().registerMatchingRules(Arrays.asList(matchingRule), false); |
| | | matchingRulesToRemove.add(matchingRule); |
| | | getSchemaHandler().updateSchema(new SchemaUpdater() |
| | | { |
| | | @Override |
| | | public void update(SchemaBuilder builder) throws DirectoryException |
| | | { |
| | | builder |
| | | .buildMatchingRule(oid) |
| | | .syntaxOID(CoreSchema.getDirectoryStringSyntax().getOID()) |
| | | .names(name) |
| | | .implementation(new SchemaTestMatchingRuleImpl()) |
| | | .addToSchema(); |
| | | } |
| | | }); |
| | | matchingRulesToRemove.add(oid); |
| | | } |
| | | |
| | | private String getSchemaDirectory() |
| | | { |
| | | return DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath(); |
| | | } |
| | | |
| | | /** |
| | |
| | | // milliseconds to make sure that any potential updates to the last |
| | | // modification time that it won't have any chance of happening in the same |
| | | // millisecond as the last update. |
| | | long beforeModifyTimestamp = |
| | | DirectoryServer.getSchema().getYoungestModificationTime(); |
| | | long beforeModifyTimestamp = getSchemaHandler().getYoungestModificationTime(); |
| | | Thread.sleep(2); |
| | | |
| | | |
| | | registerNewMatchingRule("testAddValidSchemaFileMatch", "1.3.6.1.4.1.26027.1.999.23"); |
| | | |
| | | |
| | | String schemaDirectory = getSchemaDirectory(); |
| | | |
| | | String[] fileLines = |
| | |
| | | assertEquals(resultCode, 0); |
| | | |
| | | waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); |
| | | assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == |
| | | beforeModifyTimestamp); |
| | | assertFalse(getSchemaHandler().getYoungestModificationTime() == beforeModifyTimestamp); |
| | | } |
| | | |
| | | /** |
| | |
| | | // milliseconds to make sure that any potential updates to the last |
| | | // modification time that it won't have any chance of happening in the same |
| | | // millisecond as the last update. |
| | | long beforeModifyTimestamp = |
| | | DirectoryServer.getSchema().getYoungestModificationTime(); |
| | | long beforeModifyTimestamp = getSchemaHandler().getYoungestModificationTime(); |
| | | Thread.sleep(2); |
| | | |
| | | registerNewMatchingRule("testAddMultipleValidSchemaFiles1Match", "1.3.6.1.4.1.26027.1.999.24"); |
| | |
| | | assertEquals(resultCode, 0); |
| | | |
| | | waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); |
| | | assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == |
| | | beforeModifyTimestamp); |
| | | assertFalse(getSchemaHandler().getYoungestModificationTime() == beforeModifyTimestamp); |
| | | } |
| | | |
| | | private void writeLines(File file, String[] lines) throws IOException |
| | |
| | | // milliseconds to make sure that any potential updates to the last |
| | | // modification time that it won't have any chance of happening in the same |
| | | // millisecond as the last update. |
| | | long beforeModifyTimestamp = |
| | | DirectoryServer.getSchema().getYoungestModificationTime(); |
| | | long beforeModifyTimestamp = getSchemaHandler().getYoungestModificationTime(); |
| | | Thread.sleep(2); |
| | | |
| | | |
| | |
| | | assertEquals(resultCode, 0); |
| | | |
| | | waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr)); |
| | | assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() == |
| | | beforeModifyTimestamp); |
| | | assertFalse(getSchemaHandler().getYoungestModificationTime() == beforeModifyTimestamp); |
| | | } |
| | | |
| | | /** |
| | |
| | | assertFalse(resultCode == 0); |
| | | invalidFile.delete(); |
| | | } |
| | | |
| | | private String getSchemaDirectory() |
| | | { |
| | | return DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath(); |
| | | } |
| | | } |