use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeNoSupNoUserModificationUserAplication.
/**
* Try to inject an AttributeType which is a NO-USER-MODIFICATION and userApplication
*/
@Test
public void testAddAttributeTypeNoSupNoUserModificationUserAplication() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid("2.5.13.1");
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
attributeType.setUserModifiable(false);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeNoSupNoSyntaxNoSuperior.
// =========================================================================
// For each test, we will check many different things.
// If the test is successful, we want to know if the SchemaObject
// Registry has grown : its size must be one bigger. If the SchemaObject
// is not loadable, then the GlobalOidRegistry must also have grown.
// =========================================================================
// AttributeType addition tests
// -------------------------------------------------------------------------
// First, not defined superior
// -------------------------------------------------------------------------
/**
* Try to inject an AttributeType without any superior nor Syntax : it's invalid
*/
@Test
public void testAddAttributeTypeNoSupNoSyntaxNoSuperior() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid("2.5.13.1");
attributeType.setOrderingOid(null);
attributeType.setSubstringOid(null);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException 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());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddMatchingRuleExistingOID.
/**
* Try to inject a new MatchingRule with an existing OID
*/
@Test
public void testAddMatchingRuleExistingOID() throws Exception {
SchemaManager schemaManager = loadSystem();
int mrrSize = schemaManager.getMatchingRuleRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableMatchingRule matchingRule = new MutableMatchingRule("2.5.13.0");
matchingRule.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
// It should fail (oid already registered)
assertFalse(schemaManager.add(matchingRule));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
// Check that the existing MR has not been replaced
assertTrue(isMRPresent(schemaManager, "2.5.13.0"));
MatchingRule existing = schemaManager.lookupMatchingRuleRegistry("2.5.13.0");
assertEquals("objectIdentifierMatch", existing.getName());
assertEquals(mrrSize, schemaManager.getMatchingRuleRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsAuxiliaryWithStructuralInSup.
/**
* Addition of an AUXILIARY OC with some STRUCTURAL superior
*/
@Test
public void testAddObjectClassSuperiorsAuxiliaryWithStructuralInSup() 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.AUXILIARY);
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());
}
Aggregations