| | |
| | | |
| | | |
| | | |
| | | import java.util.ResourceBundle; |
| | | |
| | | import org.opends.server.admin.std.meta.RootCfgDefn; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.schema.ObjectClassSyntax; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.ByteStringFactory; |
| | | import org.opends.server.types.ObjectClass; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | // Create a one-to-many relation for test-parent components. |
| | | static { |
| | | InstantiableRelationDefinition.Builder<TestParentCfgClient, TestParentCfg> builder = |
| | | new InstantiableRelationDefinition.Builder<TestParentCfgClient, TestParentCfg>( |
| | | InstantiableRelationDefinition.Builder<TestParentCfgClient, TestParentCfg> builder = new InstantiableRelationDefinition.Builder<TestParentCfgClient, TestParentCfg>( |
| | | RootCfgDefn.getInstance(), "test-one-to-many-parent", |
| | | "test-one-to-many-parents", TestParentCfgDefn.getInstance()); |
| | | RD_TEST_ONE_TO_MANY_PARENT = builder.getInstance(); |
| | |
| | | |
| | | // Create a one-to-many relation for test-parent components. |
| | | static { |
| | | OptionalRelationDefinition.Builder<TestParentCfgClient, TestParentCfg> builder = |
| | | new OptionalRelationDefinition.Builder<TestParentCfgClient, TestParentCfg>( |
| | | OptionalRelationDefinition.Builder<TestParentCfgClient, TestParentCfg> builder = new OptionalRelationDefinition.Builder<TestParentCfgClient, TestParentCfg>( |
| | | RootCfgDefn.getInstance(), "test-one-to-zero-or-one-parent", |
| | | TestParentCfgDefn.getInstance()); |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT = builder.getInstance(); |
| | | } |
| | | |
| | | // Test parent object class definition. |
| | | private static ObjectClass TEST_PARENT_OCD = null; |
| | | |
| | | // Test child object class definition. |
| | | private static ObjectClass TEST_CHILD_OCD = null; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Registers test parent and child object class definitions and any |
| | | * required resource bundles. |
| | | * <p> |
| | | * Unit tests which call this method <b>must</b> call |
| | | * {@link #cleanup()} on completion. |
| | | * |
| | | * @throws Exception |
| | | * If an unexpected error occurred. |
| | | */ |
| | | public synchronized static void setUp() throws Exception { |
| | | if (TEST_PARENT_OCD == null) { |
| | | String ocd = "( 1.3.6.1.4.1.26027.1.2.4455114401 " |
| | | + "NAME 'ds-cfg-test-parent-dummy' " |
| | | + "SUP top STRUCTURAL " |
| | | + "MUST ( cn $ ds-cfg-virtual-attribute-class $ " |
| | | + "ds-cfg-virtual-attribute-enabled $ ds-cfg-virtual-attribute-type ) " |
| | | + "MAY ( ds-cfg-virtual-attribute-base-dn $ ds-cfg-virtual-attribute-group-dn $ " |
| | | + "ds-cfg-virtual-attribute-filter $ ds-cfg-virtual-attribute-conflict-behavior ) " |
| | | + "X-ORIGIN 'OpenDS Directory Server' )"; |
| | | ByteString b = ByteStringFactory.create(ocd); |
| | | |
| | | TEST_PARENT_OCD = ObjectClassSyntax.decodeObjectClass(b, DirectoryServer |
| | | .getSchema(), false); |
| | | } |
| | | |
| | | if (TEST_CHILD_OCD == null) { |
| | | String ocd = "( 1.3.6.1.4.1.26027.1.2.4455114402 " |
| | | + "NAME 'ds-cfg-test-child-dummy' " |
| | | + "SUP top STRUCTURAL " |
| | | + "MUST ( cn $ ds-cfg-virtual-attribute-class $ " |
| | | + "ds-cfg-virtual-attribute-enabled $ ds-cfg-virtual-attribute-type ) " |
| | | + "MAY ( ds-cfg-virtual-attribute-base-dn $ ds-cfg-virtual-attribute-group-dn $ " |
| | | + "ds-cfg-virtual-attribute-filter $ ds-cfg-virtual-attribute-conflict-behavior $" |
| | | + "ds-cfg-backend-base-dn) " + "X-ORIGIN 'OpenDS Directory Server' )"; |
| | | ByteString b = ByteStringFactory.create(ocd); |
| | | |
| | | TEST_CHILD_OCD = ObjectClassSyntax.decodeObjectClass(b, DirectoryServer |
| | | .getSchema(), false); |
| | | } |
| | | |
| | | { |
| | | // Register the test parent object class. |
| | | DirectoryServer.registerObjectClass(TEST_PARENT_OCD, true); |
| | | |
| | | // Register the test parent resource bundle. |
| | | TestParentCfgDefn d = TestParentCfgDefn.getInstance(); |
| | | String baseName = d.getClass().getName(); |
| | | ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName); |
| | | ManagedObjectDefinitionI18NResource.getInstance().setResourceBundle(d, |
| | | resourceBundle); |
| | | } |
| | | |
| | | { |
| | | // Register the test child object class. |
| | | DirectoryServer.registerObjectClass(TEST_CHILD_OCD, true); |
| | | |
| | | // Register the test child resource bundle. |
| | | TestChildCfgDefn d = TestChildCfgDefn.getInstance(); |
| | | String baseName = d.getClass().getName(); |
| | | ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName); |
| | | ManagedObjectDefinitionI18NResource.getInstance().setResourceBundle(d, |
| | | resourceBundle); |
| | | } |
| | | |
| | | // Ensure that the relations are registered (do this after things |
| | | // that can fail and leave tests in a bad state). |
| | | RootCfgDefn.getInstance().registerRelationDefinition( |
| | | RD_TEST_ONE_TO_MANY_PARENT); |
| | | RootCfgDefn.getInstance().registerRelationDefinition( |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT); |
| | | LDAPProfile.getInstance().pushWrapper(new MockLDAPProfile()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | * framework. |
| | | */ |
| | | public static void cleanup() { |
| | | RootCfgDefn.getInstance().deregisterRelationDefinition( |
| | | RD_TEST_ONE_TO_MANY_PARENT); |
| | | RootCfgDefn.getInstance().deregisterRelationDefinition( |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT); |
| | | LDAPProfile.getInstance().popWrapper(); |
| | | |
| | | { |
| | | RootCfgDefn.getInstance().deregisterRelationDefinition( |
| | | RD_TEST_ONE_TO_MANY_PARENT); |
| | | RootCfgDefn.getInstance().deregisterRelationDefinition( |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT); |
| | | DirectoryServer.deregisterObjectClass(TEST_PARENT_OCD); |
| | | TestParentCfgDefn d = TestParentCfgDefn.getInstance(); |
| | | ManagedObjectDefinitionI18NResource.getInstance().removeResourceBundle(d); |
| | | } |
| | | |
| | | { |
| | | DirectoryServer.deregisterObjectClass(TEST_CHILD_OCD); |
| | | TestChildCfgDefn d = TestChildCfgDefn.getInstance(); |
| | | ManagedObjectDefinitionI18NResource.getInstance().removeResourceBundle(d); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | * Gets the one-to-many relation between the root and test-parent |
| | | * components. |
| | | * <p> |
| | | * Unit tests which call this method <b>must</b> call |
| | | * {@link #cleanup()} on completion. |
| | | * Unit tests which call this method <b>must</b> have already |
| | | * called {@link #setUp()}. |
| | | * |
| | | * @return Returns the one-to-many relation between the root and |
| | | * test-parent components. |
| | | */ |
| | | public static InstantiableRelationDefinition<TestParentCfgClient, TestParentCfg> getTestOneToManyParentRelationDefinition() { |
| | | // Ensure that the relation is registered. |
| | | RootCfgDefn.getInstance().registerRelationDefinition( |
| | | RD_TEST_ONE_TO_MANY_PARENT); |
| | | return RD_TEST_ONE_TO_MANY_PARENT; |
| | | } |
| | | |
| | |
| | | * Gets the one-to-zero-or-one relation between the root and a |
| | | * test-parent component. |
| | | * <p> |
| | | * Unit tests which call this method <b>must</b> call |
| | | * {@link #cleanup()} on completion. |
| | | * Unit tests which call this method <b>must</b> have already |
| | | * called {@link #setUp()}. |
| | | * |
| | | * @return Returns the one-to-zero-or-one relation between the root |
| | | * and a test-parent component. |
| | | */ |
| | | public static OptionalRelationDefinition<TestParentCfgClient, TestParentCfg> getTestOneToZeroOrOneParentRelationDefinition() { |
| | | // Ensure that the relation is registered. |
| | | RootCfgDefn.getInstance().registerRelationDefinition( |
| | | RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT); |
| | | return RD_TEST_ONE_TO_ZERO_OR_ONE_PARENT; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adds a constraint temporarily with test child definition. |
| | | * |
| | | * @param constraint |
| | | * The constraint. |
| | | */ |
| | | public static void addConstraint(Constraint constraint) { |
| | | TestChildCfgDefn.getInstance().registerConstraint(constraint); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Removes a constraint from the test child definition. |
| | | * |
| | | * @param constraint |
| | | * The constraint. |
| | | */ |
| | | public static void removeConstraint(Constraint constraint) { |
| | | TestChildCfgDefn.getInstance().deregisterConstraint(constraint); |
| | | } |
| | | |
| | | |
| | | |
| | | // Prevent instantiation. |
| | | private TestCfg() { |
| | | // No implementation required. |