mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
12.02.2016 3fa56f675fdf8c49c9cb2abcfd478172e5acfe53
OPENDJ-3089 Remove all remaining references to server Schema class

- replace all references to server Schema by code using SchemaHandler / SDK
Schema
- modify SchemaHandler.SchemaUpdater interface in order to mutualize the
call to build the final Schema
14 files modified
305 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java 25 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/AciSyntax.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java 26 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/CoreSchemaProvider.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/SubtreeSpecificationSyntax.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java 14 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java 82 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/SchemaHandlerTestCase.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/schema/CertificateSyntaxTest.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/schema/CoreSchemaProviderTestCase.java 18 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/schema/CountryStringSyntaxTest.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/tasks/AddSchemaFileTaskTestCase.java 81 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java
@@ -90,7 +90,6 @@
import org.opends.server.util.StaticUtils;
import com.forgerock.opendj.util.OperatingSystem;
import com.sun.corba.se.spi.ior.WriteContents;
/**
 * Responsible for loading the server schema.
@@ -268,17 +267,10 @@
  }
  /**
   * Update the schema using the provided schema updater.
   * <p>
   * An implicit lock is performed, so it is in general not necessary
   * to call the {code lock()}  and {code unlock() methods.
   * However, these method should be used if/when the SchemaBuilder passed
   * as an argument to the updater is not used to return the schema
   * (see for example usage in {@code CoreSchemaProvider} class). This
   * case should remain exceptional.
   * Updates the schema using the provided schema updater.
   *
   * @param updater
   *          the updater that returns a new schema
   *          the updater that performs modifications on the schema builder
   * @throws DirectoryException if there is any problem updating the schema
   */
  public void updateSchema(SchemaUpdater updater) throws DirectoryException
@@ -286,7 +278,9 @@
    exclusiveLock.lock();
    try
    {
      switchSchema(updater.update(new SchemaBuilder(schema)));
      SchemaBuilder schemaBuilder = new SchemaBuilder(schema);
      updater.update(schemaBuilder);
      switchSchema(schemaBuilder.toSchema());
    }
    finally
    {
@@ -386,9 +380,9 @@
      updateSchema(new SchemaUpdater()
      {
        @Override
        public Schema update(SchemaBuilder builder)
        public void update(SchemaBuilder builder)
        {
          return builder.setOption(option, newValue).toSchema();
          builder.setOption(option, newValue);
        }
      });
    }
@@ -1051,14 +1045,13 @@
  public interface SchemaUpdater
  {
    /**
     * Returns an updated schema.
     * Updates the schema using the provided schema builder.
     *
     * @param builder
     *          The builder on the current schema
     * @return the new schema
     * @throws DirectoryException
     *          If an error occurs during the schema update
     */
    Schema update(SchemaBuilder builder) throws DirectoryException;
    void update(SchemaBuilder builder) throws DirectoryException;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/schema/AciSyntax.java
@@ -24,9 +24,9 @@
import org.forgerock.opendj.ldap.schema.Syntax;
import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
import org.opends.server.api.AttributeSyntax;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.core.ServerContext;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Schema.SchemaUpdater;
/**
 * This class implements the access control information (aci) attribute syntax.
@@ -50,12 +50,12 @@
      throws ConfigException, DirectoryException
  {
    // Add the Aci syntax to the "new" schema
    serverContext.getSchema().updateSchema(new SchemaUpdater()
    serverContext.getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public Schema update(SchemaBuilder builder)
      public void update(SchemaBuilder builder)
      {
        return addAciSyntax(builder).toSchema();
        addAciSyntax(builder);
      }
    });
  }
opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java
@@ -42,9 +42,10 @@
import org.forgerock.opendj.server.config.server.CollationMatchingRuleCfg;
import org.opends.server.api.MatchingRuleFactory;
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.opends.server.types.InitializationException;
import org.opends.server.types.Schema.SchemaUpdater;
import org.opends.server.util.CollectionUtils;
/**
@@ -83,14 +84,14 @@
  {
    // The core schema contains all supported collation matching rules so read it for initialization.
    // The server's schemaNG may have different things configured slightly differently
    org.opends.server.types.Schema schema = DirectoryServer.getSchema();
    SchemaHandler schemaHandler = DirectoryServer.getInstance().getServerContext().getSchemaHandler();
    Schema coreSchema = CoreSchema.getInstance();
    // on startup, the SDK already has existing matching rules
    // remove them all before letting the server set them all up
    // according to what this factory decides must be setup
    final Set<MatchingRule> defaultMatchingRules = getCollationMatchingRules(coreSchema.getMatchingRules());
    unregisterMatchingRules(schema, defaultMatchingRules);
    unregisterMatchingRules(schemaHandler, defaultMatchingRules);
    matchingRules.putAll(collectConfiguredMatchingRules(configuration, coreSchema));
    // Save this configuration.
@@ -100,21 +101,20 @@
    currentConfig.addCollationChangeListener(this);
  }
  private void unregisterMatchingRules(org.opends.server.types.Schema schema,
      final Collection<MatchingRule> matchingRules) throws ConfigException
  private void unregisterMatchingRules(SchemaHandler schemaHandler, final Collection<MatchingRule> matchingRules)
      throws ConfigException
  {
    try
    {
      schema.updateSchema(new SchemaUpdater()
      schemaHandler.updateSchema(new SchemaUpdater()
      {
        @Override
        public Schema update(SchemaBuilder builder)
        public void update(SchemaBuilder builder)
        {
          for (final MatchingRule rule : matchingRules)
          {
            builder.removeMatchingRule(rule.getNameOrOID());
          }
          return builder.toSchema();
        }
      });
    }
@@ -200,8 +200,9 @@
    // Since we have come here it means that this Factory is enabled
    // and there is a change in the CollationMatchingRuleFactory's configuration.
    final org.opends.server.types.Schema serverSchema = DirectoryServer.getSchema();
    final Collection<MatchingRule> existingCollationRules = getCollationMatchingRules(serverSchema.getMatchingRules());
    SchemaHandler schemaHandler = DirectoryServer.getInstance().getServerContext().getSchemaHandler();
    final Collection<MatchingRule> existingCollationRules =
        getCollationMatchingRules(schemaHandler.getSchema().getMatchingRules());
    matchingRules.clear();
    final Map<String, MatchingRule> configuredMatchingRules =
@@ -219,10 +220,10 @@
    }
    try
    {
      serverSchema.updateSchema(new SchemaUpdater()
      schemaHandler.updateSchema(new SchemaUpdater()
      {
        @Override
        public Schema update(SchemaBuilder builder)
        public void update(SchemaBuilder builder)
        {
          Collection<MatchingRule> defaultMatchingRules = CoreSchema.getInstance().getMatchingRules();
          for (MatchingRule rule : defaultMatchingRules)
@@ -246,7 +247,6 @@
            // removed
            builder.removeMatchingRule(ruleToRemove.getOID());
          }
          return builder.toSchema();
        }
      });
    }
opendj-server-legacy/src/main/java/org/opends/server/schema/CoreSchemaProvider.java
@@ -23,14 +23,13 @@
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.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.server.config.server.CoreSchemaCfg;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.core.ServerContext;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Schema.SchemaUpdater;
/** Provides the core schema, which includes core matching rules and syntaxes. */
public class CoreSchemaProvider implements SchemaProvider<CoreSchemaCfg>,
@@ -123,17 +122,14 @@
  public ConfigChangeResult applyConfigurationChange(final CoreSchemaCfg configuration)
  {
    final ConfigChangeResult ccr = new ConfigChangeResult();
    // TODO : the server schema should probably be renamed to something like ServerSchema
    // Even after migration to SDK schema, it will be probably be kept
    try
    {
      serverContext.getSchema().updateSchema(new SchemaUpdater()
      serverContext.getSchemaHandler().updateSchema(new SchemaUpdater()
      {
        @Override
        public Schema update(SchemaBuilder builder)
        public void update(SchemaBuilder builder)
        {
          updateSchemaFromConfiguration(builder, configuration);
          return builder.toSchema();
        }
      });
    }
opendj-server-legacy/src/main/java/org/opends/server/schema/SubtreeSpecificationSyntax.java
@@ -27,10 +27,10 @@
import org.forgerock.opendj.ldap.schema.Syntax;
import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
import org.opends.server.api.AttributeSyntax;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.core.ServerContext;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Schema.SchemaUpdater;
import org.opends.server.types.SubtreeSpecification;
/**
@@ -58,12 +58,12 @@
      throws ConfigException, DirectoryException
  {
    // Add the subtree specification syntax to the "new" schema
    serverContext.getSchema().updateSchema(new SchemaUpdater()
    serverContext.getSchemaHandler().updateSchema(new SchemaUpdater()
    {
      @Override
      public Schema update(SchemaBuilder builder)
      public void update(SchemaBuilder builder)
      {
        return addSubtreeSpecificationSyntax(builder).toSchema();
        addSubtreeSpecificationSyntax(builder);
      }
    });
  }
opendj-server-legacy/src/main/java/org/opends/server/types/DirectoryConfig.java
@@ -105,16 +105,6 @@
  }
  /**
   * Retrieves a reference to the Directory Server schema.
   *
   * @return  A reference to the Directory Server schema.
   */
  public static Schema getSchema()
  {
    return DirectoryServer.getSchema();
  }
  /**
   * Registers the provided alert generator with the Directory Server.
   *
   * @param  alertGenerator  The alert generator to register.
opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
@@ -20,7 +20,9 @@
import java.io.File;
import org.forgerock.opendj.config.server.ServerManagementContext;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.config.ConfigurationHandler;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.ServerContext;
import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.types.InitializationException;
@@ -60,10 +62,18 @@
    return this;
  }
  public ServerContextBuilder schema(org.opends.server.types.Schema schema)
  public ServerContextBuilder schema(Schema schema)
  {
    when(serverContext.getSchema()).thenReturn(schema);
    when(serverContext.getSchemaNG()).thenReturn(schema.getSchemaNG());
    when(serverContext.getSchemaNG()).thenReturn(schema);
    return this;
  }
  public ServerContextBuilder schemaHandler(SchemaHandler handler)
  {
    when(serverContext.getSchemaHandler()).thenReturn(handler);
    when(serverContext.getSchema()).thenReturn(handler.getSchema());
    when(serverContext.getSchemaNG()).thenReturn(handler.getSchema());
    return this;
  }
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -46,7 +46,6 @@
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.forgerock.opendj.ldap.schema.MatchingRuleUse;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.server.config.server.SchemaBackendCfg;
import org.forgerock.util.Utils;
@@ -55,6 +54,8 @@
import org.opends.server.core.DeleteOperationBasis;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperationBasis;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.SchemaHandler.SchemaUpdater;
import org.opends.server.core.ServerContext;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
@@ -1237,23 +1238,47 @@
    }
  }
  private void deregisterAttributeType(String nameOrOid) throws DirectoryException
  private void updateSchema(SchemaUpdater updater) throws DirectoryException
  {
    org.opends.server.types.Schema schema = DirectoryServer.getSchema();
    schema.deregisterAttributeType(schema.getAttributeType(nameOrOid));
    SchemaHandler schemaHandler = DirectoryServer.getInstance().getServerContext().getSchemaHandler();
    schemaHandler.updateSchema(updater);
  }
  private void deregisterMatchingRuleUse(MatchingRule matchingRule) throws DirectoryException
  private void deregisterAttributeType(final String nameOrOid) throws DirectoryException
  {
    org.opends.server.types.Schema schema = DirectoryServer.getSchema();
    schema.deregisterMatchingRuleUse(schema.getMatchingRuleUse(matchingRule));
    updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder.removeAttributeType(nameOrOid);
      }
    });
  }
  private void deregisterMatchingRule(MatchingRule matchingRule) throws DirectoryException
  private void deregisterMatchingRuleUse(final MatchingRule matchingRule) throws DirectoryException
  {
    DirectoryServer.getSchema().deregisterMatchingRule(matchingRule);
    updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder.removeMatchingRuleUse(matchingRule.getOID());
      }
    });
  }
  private void deregisterMatchingRule(final MatchingRule matchingRule) throws DirectoryException
  {
    updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder.removeMatchingRule(matchingRule.getOID());
      }
    });
  }
  /**
   * Tests the behavior of the schema backend when attempting to add a new
@@ -3233,7 +3258,7 @@
  private void assertSchemaHasDITStructureRule(int ruleID, boolean expected)
  {
    boolean hasDITStructureRule = DirectoryServer.getSchema().getSchemaNG().hasDITStructureRule(ruleID);
    boolean hasDITStructureRule = DirectoryServer.getSchema().hasDITStructureRule(ruleID);
    assertEquals(hasDITStructureRule, expected, "Expected to find a DITStructureRule with ruleID " + ruleID);
  }
@@ -3677,19 +3702,6 @@
    assertSchemaHasDITStructureRule(ruleID, false);
  }
  private MatchingRule getMatchingRule(String name, String oid, boolean isObsolete)
  {
    Schema schema =
        new SchemaBuilder(Schema.getCoreSchema())
          .buildMatchingRule(oid)
            .syntaxOID(SchemaConstants.SYNTAX_DIRECTORY_STRING_OID)
            .names(name)
            .implementation(new SchemaTestMatchingRuleImpl())
            .obsolete(isObsolete)
            .addToSchema().toSchema();
    return schema.getMatchingRule(oid);
  }
  /**
   * Tests the behavior of the schema backend when attempting to add a new
   * matching rule use that doesn't already exist.
@@ -4074,11 +4086,27 @@
    }
  }
  private MatchingRule registerNewMatchingRule(String name, String oid, boolean obsolete) throws DirectoryException
  private MatchingRule registerNewMatchingRule(final String name, final String oid, final boolean obsolete)
      throws DirectoryException
  {
    MatchingRule matchingRule = getMatchingRule(name, oid, obsolete);
    DirectoryServer.getSchema().registerMatchingRules(Arrays.asList(matchingRule), false);
    return matchingRule;
    updateSchema(new SchemaUpdater()
    {
      @Override
      public void update(SchemaBuilder builder) throws DirectoryException
      {
        builder
          .buildMatchingRule(oid)
          .syntaxOID(SchemaConstants.SYNTAX_DIRECTORY_STRING_OID)
          .names(name)
          .implementation(new SchemaTestMatchingRuleImpl())
          .obsolete(obsolete)
          .addToSchema();
      }
    });
    SchemaHandler schemaHandler = DirectoryServer.getInstance().getServerContext().getSchemaHandler();
    return schemaHandler.getSchema().getMatchingRule(oid);
  }
  private void runModify(String[] args, String ldifContent, ResultCode expectedRC)
opendj-server-legacy/src/test/java/org/opends/server/core/SchemaHandlerTestCase.java
@@ -31,8 +31,8 @@
  @Test
  public void testSchemaInitialization() throws Exception
  {
    org.opends.server.types.Schema schema = new org.opends.server.types.Schema(Schema.getCoreSchema());
    initializeSchemaHandler(schema);
    SchemaHandler handler = initializeSchemaHandler();
    Schema schema = handler.getSchema();
    assertThat(schema.getMatchingRules()).isNotEmpty(); // some matching rules defined
    schema.getSyntax(SchemaConstants.SYNTAX_DIRECTORY_STRING_OID);
@@ -41,17 +41,18 @@
    schema.getObjectClass("changeLogEntry"); // from file 03-changelog.ldif
  }
  private void initializeSchemaHandler(org.opends.server.types.Schema schema) throws Exception
  private SchemaHandler initializeSchemaHandler() throws Exception
  {
    SchemaHandler schemaHandler = new SchemaHandler();
    final ServerContext serverContext = aServerContext()
        .schemaDirectory(new File(TestCaseUtils.getBuildRoot(), "resource/schema"))
        .configFile(TestCaseUtils.getTestResource("configForTests/config-small.ldif"))
        .withConfigurationBootstrapped()
        .schema(schema)
        .schemaHandler(schemaHandler)
        .build();
    SchemaHandler schemaHandler = new SchemaHandler();
    schemaHandler.initialize(serverContext);
    return schemaHandler;
  }
}
opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java
@@ -112,7 +112,7 @@
  @Test
  public void testXAPPROXExtension() throws Exception
  {
    org.opends.server.types.Schema schema = DirectoryServer.getSchema();
    Schema schema = DirectoryServer.getInstance().getServerContext().getSchema();
    Syntax attrTypeSyntax = schema.getSyntax("1.3.6.1.4.1.1466.115.121.1.3");
    assertNotNull(attrTypeSyntax);
@@ -126,7 +126,7 @@
    // Verify that we can decode the attribute type and that it has the
    // correct approximate matching rule.
    Schema newSchema = new SchemaBuilder(schema.getSchemaNG())
    Schema newSchema = new SchemaBuilder(schema)
      .addAttributeType(definition.toString(), false)
      .toSchema();
opendj-server-legacy/src/test/java/org/opends/server/schema/CertificateSyntaxTest.java
@@ -17,12 +17,12 @@
package org.opends.server.schema;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.ServerContextBuilder;
import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
import org.forgerock.opendj.server.config.server.CertificateAttributeSyntaxCfg;
import org.opends.server.api.AttributeSyntax;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.ServerContext;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.util.Base64;
@@ -119,7 +119,7 @@
    };
    ServerContext serverContext = ServerContextBuilder.aServerContext()
        .schema(new org.opends.server.types.Schema(Schema.getCoreSchema()))
        .schemaHandler(new SchemaHandler()) // provides core schema
        .build();
    syntax.initializeSyntax(cfg, serverContext);
    return syntax;
opendj-server-legacy/src/test/java/org/opends/server/schema/CoreSchemaProviderTestCase.java
@@ -21,6 +21,7 @@
import org.forgerock.opendj.config.ConfigurationMock;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.CoreTestCase;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.ServerContext;
import org.testng.annotations.Test;
@@ -44,20 +45,18 @@
    CoreSchemaCfg coreSchemaCfg = ConfigurationMock.mockCfg(CoreSchemaCfg.class);
    CoreSchemaProvider provider = new CoreSchemaProvider();
    org.opends.server.types.Schema schema = new org.opends.server.types.Schema( Schema.getCoreSchema());
    provider.initialize(getServerContext(schema), coreSchemaCfg, new SchemaBuilder());
    provider.initialize(getServerContext(), coreSchemaCfg, new SchemaBuilder());
    verify(coreSchemaCfg).addCoreSchemaChangeListener(provider);
  }
  private ServerContext getServerContext(org.opends.server.types.Schema schema) throws Exception
  private ServerContext getServerContext() throws Exception
  {
    return aServerContext()
        .schemaDirectory(new File(TestCaseUtils.getBuildRoot(), "resource/schema"))
        .configFile(TestCaseUtils.getTestResource("configForTests/config-small.ldif"))
        .withConfigurationBootstrapped()
        .schema(schema)
        .schemaHandler(new SchemaHandler())
        .build();
  }
@@ -69,8 +68,7 @@
    SchemaBuilder schemaBuilder = new SchemaBuilder();
    CoreSchemaProvider provider = new CoreSchemaProvider();
    org.opends.server.types.Schema schema = new org.opends.server.types.Schema( Schema.getCoreSchema());
    provider.initialize(getServerContext(schema), coreSchemaCfg, schemaBuilder);
    provider.initialize(getServerContext(), coreSchemaCfg, schemaBuilder);
    assertThat(schemaBuilder.toSchema().getOption(ALLOW_ZERO_LENGTH_DIRECTORY_STRINGS)).isTrue();
  }
@@ -83,8 +81,7 @@
    SchemaBuilder schemaBuilder = new SchemaBuilder(Schema.getCoreSchema());
    CoreSchemaProvider provider = new CoreSchemaProvider();
    org.opends.server.types.Schema schema = new org.opends.server.types.Schema( Schema.getCoreSchema());
    provider.initialize(getServerContext(schema), coreSchemaCfg, schemaBuilder);
    provider.initialize(getServerContext(), coreSchemaCfg, schemaBuilder);
    assertThat(schemaBuilder.toSchema().hasSyntax(DIRECTORY_STRING_SYNTAX_OID)).isFalse();
  }
@@ -97,8 +94,7 @@
    SchemaBuilder schemaBuilder = new SchemaBuilder(Schema.getCoreSchema());
    CoreSchemaProvider provider = new CoreSchemaProvider();
    org.opends.server.types.Schema schema = new org.opends.server.types.Schema( Schema.getCoreSchema());
    provider.initialize(getServerContext(schema), coreSchemaCfg, schemaBuilder);
    provider.initialize(getServerContext(), coreSchemaCfg, schemaBuilder);
    assertThat(schemaBuilder.toSchema().hasMatchingRule(DIRECTORY_STRING_SYNTAX_OID)).isFalse();
  }
opendj-server-legacy/src/test/java/org/opends/server/schema/CountryStringSyntaxTest.java
@@ -18,12 +18,12 @@
package org.opends.server.schema;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.ServerContextBuilder;
import org.opends.server.api.AttributeSyntax;
import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.server.config.server.AttributeSyntaxCfg;
import org.forgerock.opendj.server.config.server.CountryStringAttributeSyntaxCfg;
import org.opends.server.core.SchemaHandler;
import org.opends.server.core.ServerContext;
import org.opends.server.util.RemoveOnceSDKSchemaIsUsed;
import org.testng.annotations.DataProvider;
@@ -119,7 +119,7 @@
    };
    ServerContext serverContext = ServerContextBuilder.aServerContext()
        .schema(new org.opends.server.types.Schema(Schema.getCoreSchema()))
        .schemaHandler(new SchemaHandler()) // provides core schema
        .build();
    syntax.initializeSyntax(cfg, serverContext);
    return syntax;
opendj-server-legacy/src/test/java/org/opends/server/tasks/AddSchemaFileTaskTestCase.java
@@ -32,6 +32,8 @@
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;
@@ -46,7 +48,7 @@
@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.
@@ -59,29 +61,49 @@
    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();
  }
  /**
@@ -98,14 +120,11 @@
    // 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 =
@@ -147,8 +166,7 @@
    assertEquals(resultCode, 0);
    waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr));
    assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() ==
                     beforeModifyTimestamp);
    assertFalse(getSchemaHandler().getYoungestModificationTime() == beforeModifyTimestamp);
  }
  /**
@@ -165,8 +183,7 @@
    // 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");
@@ -246,8 +263,7 @@
    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
@@ -326,8 +342,7 @@
    // 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);
@@ -349,8 +364,7 @@
    assertEquals(resultCode, 0);
    waitTaskCompletedSuccessfully(DN.valueOf(taskDNStr));
    assertFalse(DirectoryServer.getSchema().getYoungestModificationTime() ==
                     beforeModifyTimestamp);
    assertFalse(getSchemaHandler().getYoungestModificationTime() == beforeModifyTimestamp);
  }
  /**
@@ -385,9 +399,4 @@
    assertFalse(resultCode == 0);
    invalidFile.delete();
  }
  private String getSchemaDirectory()
  {
    return DirectoryServer.getEnvironmentConfig().getSchemaDirectory().getPath();
  }
}