Search in sources :

Example 11 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsAbstractWithStructuralInSup.

/**
 * Addition of an ABSTRACT OC with some STRUCTURAL superior
 */
@Test
public void testAddObjectClassSuperiorsAbstractWithStructuralInSup() 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.ABSTRACT);
    objectClass.addSuperiorOids("referral");
    assertFalse(schemaManager.add(objectClass));
    assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.1"));
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) 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) Test(org.junit.Test)

Example 12 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorNonExistingAtInMust.

/**
 * Addition of an OC with not existing AT in MUST
 */
@Test
public void testAddObjectClassNoSuperiorNonExistingAtInMust() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.addMustAttributeTypeOids("cn", "none", "userPassword");
    assertFalse(schemaManager.add(objectClass));
    assertEquals(1, schemaManager.getErrors().size());
    Throwable error = schemaManager.getErrors().get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.1"));
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) 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) Test(org.junit.Test)

Example 13 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsNonExistingOCInSup.

/**
 * Addition of an OC with a non existing OC in SUP
 */
@Test
public void testAddObjectClassSuperiorsNonExistingOCInSup() 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", "refessal");
    assertFalse(schemaManager.add(objectClass));
    assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.1"));
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) 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) Test(org.junit.Test)

Example 14 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsValid.

// -------------------------------------------------------------------------
// Then, with superiors
// -------------------------------------------------------------------------
/**
 * Addition of a valid OC with some superiors
 */
@Test
public void testAddObjectClassSuperiorsValid() 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", "referral", "top");
    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(3, added.getSuperiors().size());
    Set<String> expectedSups = new HashSet<String>();
    expectedSups.add("alias");
    expectedSups.add("referral");
    expectedSups.add("top");
    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 15 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorATMoreThanOnceInMust.

/**
 * Addition of an OC with an AT present more than once in MUST
 */
@Test
public void testAddObjectClassNoSuperiorATMoreThanOnceInMust() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.addMustAttributeTypeOids("cn", "ref", "2.5.4.3");
    assertFalse(schemaManager.add(objectClass));
    assertEquals(1, schemaManager.getErrors().size());
    assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.1"));
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) 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) Test(org.junit.Test)

Aggregations

MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)17 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)16 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)16 Test (org.junit.Test)16 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)14 HashSet (java.util.HashSet)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)1 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)1 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)1 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)1 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)1