Search in sources :

Example 1 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorValid.

// =========================================================================
// ObjectClass addition tests
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// First, not defined superior
// -------------------------------------------------------------------------
/**
 * Addition of a valid OC
 */
@Test
public void testAddObjectClassNoSuperiorValid() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass objectClass = new ObjectClass("1.1.1");
    assertTrue(schemaManager.add(objectClass));
    assertEquals(0, schemaManager.getErrors().size());
    ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
    assertNotNull(added);
    assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay.

/**
 * Addition of an OC with some AT present in MUST and in MAY in one of its
 * superior
 */
@Test
public void testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.setNames("Test");
    objectClass.setType(ObjectClassTypeEnum.STRUCTURAL);
    objectClass.addSuperiorOids("alias", "OpenLDAProotDSE");
    objectClass.addMustAttributeTypeOids("aliasedObjectName", "cn");
    assertTrue(schemaManager.add(objectClass));
    assertEquals(0, schemaManager.getErrors().size());
    ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
    assertNotNull(added);
    assertTrue(added.getNames().contains("Test"));
    assertNotNull(added.getSuperiors());
    assertEquals(2, added.getSuperiors().size());
    Set<String> expectedSups = new HashSet<String>();
    expectedSups.add("alias");
    expectedSups.add("OpenLDAProotDSE");
    for (ObjectClass addedOC : added.getSuperiors()) {
        assertTrue(expectedSups.contains(addedOC.getName()));
        expectedSups.remove(addedOC.getName());
    }
    assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteNonExistingObjectClass.

@Test
public void testDeleteNonExistingObjectClass() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int ocSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass oc = new ObjectClass("0.1.1");
    assertFalse(schemaManager.delete(oc));
    assertEquals(ocSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 4 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingObjectClassUsedByAnotherObjectClass.

@Test
public void testDeleteExistingObjectClassUsedByAnotherObjectClass() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int ocSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass oc = new ObjectClass("2.5.6.0");
    // shouldn't delete the 'top' OC
    assertFalse(schemaManager.delete(oc));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    assertEquals(ocSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 5 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingObjectClass.

// =========================================================================
// ObjectClass deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingObjectClass() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int ocSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass oc = new ObjectClass("2.5.17.2");
    assertTrue(schemaManager.delete(oc));
    assertEquals(ocSize - 1, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    try {
        schemaManager.lookupObjectClassRegistry("2.5.17.2");
        fail();
    } catch (Exception e) {
    // expected
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Aggregations

ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)53 Test (org.junit.Test)34 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)9 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)6 ParseException (java.text.ParseException)5 HashSet (java.util.HashSet)5 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)3 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2