| | |
| | | |
| | | import org.opends.server.admin.AbstractManagedObjectDefinition; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.ConfigurationClient; |
| | | import org.opends.server.admin.DefinitionDecodingException; |
| | | import org.opends.server.admin.LDAPProfile; |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.RelationDefinition; |
| | | import org.opends.server.admin.SingletonRelationDefinition; |
| | | import org.opends.server.admin.std.meta.RootCfgDefn; |
| | | import org.opends.server.config.ConfigEntry; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.types.Entry; |
| | |
| | | */ |
| | | public final class AdminTestCaseUtils { |
| | | |
| | | // The relation name which will be used for dummy configurations. A |
| | | // deliberately obfuscated name is chosen to avoid clashes. |
| | | private static final String DUMMY_TEST_RELATION = "*dummy*test*relation*"; |
| | | |
| | | // Indicates if the dummy relation profile has been registered. |
| | | private static boolean isProfileRegistered = false; |
| | | |
| | | |
| | | |
| | | // Prevent instantiation. |
| | | private AdminTestCaseUtils() { |
| | | // No implementation required. |
| | |
| | | ConfigEntry configEntry = new ConfigEntry(entry, null); |
| | | |
| | | try { |
| | | ServerManagedObject<? extends S> mo = ServerManagedObject |
| | | .decode(ManagedObjectPath.emptyPath(), definition, |
| | | configEntry); |
| | | ServerManagementContext context = ServerManagementContext.getInstance(); |
| | | ServerManagedObject<? extends S> mo = context.decode(getPath(definition), |
| | | configEntry); |
| | | return mo.getConfiguration(); |
| | | } catch (DefinitionDecodingException e) { |
| | | throw ConfigExceptionFactory.getInstance() |
| | |
| | | .createDecodingExceptionAdaptor(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // Construct a dummy path. |
| | | private synchronized static <C extends ConfigurationClient, S extends Configuration> |
| | | ManagedObjectPath<C, S> getPath(AbstractManagedObjectDefinition<C, S> d) { |
| | | if (!isProfileRegistered) { |
| | | LDAPProfile.Wrapper profile = new LDAPProfile.Wrapper() { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getRelationRDNSequence(RelationDefinition<?, ?> r) { |
| | | if (r.getName().equals(DUMMY_TEST_RELATION)) { |
| | | return "cn=dummy configuration,cn=config"; |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | }; |
| | | |
| | | LDAPProfile.getInstance().pushWrapper(profile); |
| | | isProfileRegistered = true; |
| | | } |
| | | |
| | | SingletonRelationDefinition.Builder<C, S> builder = |
| | | new SingletonRelationDefinition.Builder<C, S>( |
| | | RootCfgDefn.getInstance(), DUMMY_TEST_RELATION, d); |
| | | ManagedObjectPath<?, ?> root = ManagedObjectPath.emptyPath(); |
| | | return root.child(builder.getInstance()); |
| | | |
| | | } |
| | | } |