Search in sources :

Example 1 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsOcMoreThanOnceInSup.

/**
 * Addition of an OC with the same OC more than once in SUP
 */
@Test
public void testAddObjectClassSuperiorsOcMoreThanOnceInSup() 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", "2.5.6.1");
    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 2 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsWithCycle.

/**
 * Addition of an OC with itself in the SUP list
 */
@Test
public void testAddObjectClassSuperiorsWithCycle() 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", "Test", "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 3 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorATMoreThanOnceInMay.

/**
 * Addition of an OC with an AT present more than once in MAY
 */
@Test
public void testAddObjectClassNoSuperiorATMoreThanOnceInMay() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.addMayAttributeTypeOids("cn", "ref", "commonName");
    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)

Example 4 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorCollectiveATInMustOrMay.

/**
 * Addition of an OC with a collective AT present in MUST or MAY.
 */
@Test
public void testAddObjectClassNoSuperiorCollectiveATInMustOrMay() throws Exception {
    SchemaManager schemaManager = loadSystem();
    schemaManager.loadWithDeps("collective");
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // Check a addition in MUST
    MutableObjectClass objectClassMust = new MutableObjectClass("1.1.1");
    objectClassMust.addMustAttributeTypeOids("c-o", "ref");
    // collective attribute in MUST : failure expected
    assertFalse(schemaManager.add(objectClassMust));
    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());
    // Check an addition in MAY
    MutableObjectClass objectClassMay = new MutableObjectClass("1.1.1");
    objectClassMay.addMayAttributeTypeOids("c-o", "ref");
    // collective attribute in MAY : failure expected
    assertFalse(schemaManager.add(objectClassMay));
    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)

Example 5 with MutableObjectClass

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorNonExistingAtInMay.

/**
 * Addition of an OC with not existing AT in MAY
 */
@Test
public void testAddObjectClassNoSuperiorNonExistingAtInMay() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.addMayAttributeTypeOids("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)

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