use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddValidSyntax.
// =========================================================================
// Syntax addition tests
// -------------------------------------------------------------------------
/**
* Try to inject a new valid Syntax, with no SC : the associated SC
* will be the default OctetString SC
*/
@Test
public void testAddValidSyntax() throws Exception {
SchemaManager schemaManager = loadSystem();
int sSize = schemaManager.getLdapSyntaxRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
LdapSyntax syntax = new LdapSyntax("1.1.0");
// It should not fail
assertTrue(schemaManager.add(syntax));
LdapSyntax added = schemaManager.lookupLdapSyntaxRegistry("1.1.0");
assertNotNull(added);
assertEquals(OctetStringSyntaxChecker.class.getName(), added.getSyntaxChecker().getClass().getName());
List<Throwable> errors = schemaManager.getErrors();
assertEquals(0, errors.size());
assertTrue(isSyntaxPresent(schemaManager, "1.1.0"));
assertEquals(sSize + 1, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddSyntaxExistingOid.
/**
* Try to inject a Syntax with an existing OID
*/
@Test
public void testAddSyntaxExistingOid() throws Exception {
SchemaManager schemaManager = loadSystem();
int sSize = schemaManager.getLdapSyntaxRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
LdapSyntax syntax = new LdapSyntax("2.5.4.3");
// It should fail
assertFalse(schemaManager.add(syntax));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteExistingSyntaxCheckerUsedByRemovedSyntax.
/**
* Check that a SyntaxChecker which has been used by a deleted Syntax
* can be removed
*/
@Test
public void testDeleteExistingSyntaxCheckerUsedByRemovedSyntax() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
int srSize = schemaManager.getLdapSyntaxRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
String OID = "1.3.6.1.4.1.1466.115.121.1.33";
// Check that the S and SC are present
assertTrue(isSyntaxCheckerPresent(schemaManager, OID));
assertTrue(isSyntaxPresent(schemaManager, OID));
// Now try to remove the SC
SyntaxChecker sc = schemaManager.lookupSyntaxCheckerRegistry(OID);
// shouldn't be deleted cause there is a S associated with it
assertFalse(schemaManager.delete(sc));
List<Throwable> errors = schemaManager.getErrors();
assertFalse(errors.isEmpty());
assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
// Now delete the using S : it should be OK
LdapSyntax syntax = new LdapSyntax(OID);
assertTrue(schemaManager.delete(syntax));
assertEquals(srSize - 1, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
assertFalse(isSyntaxPresent(schemaManager, OID));
// and try to delete the SC again
assertTrue(schemaManager.delete(sc));
assertFalse(isSyntaxCheckerPresent(schemaManager, OID));
assertEquals(scrSize - 1, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteExistingSyntax.
// =========================================================================
// Syntax deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingSyntax() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int sSize = schemaManager.getLdapSyntaxRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
// delete a existing syntax not used by AT and MR
LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry("1.3.6.1.4.1.1466.115.121.1.10");
assertTrue(schemaManager.delete(syntax));
assertEquals(sSize - 1, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
// add a syntax and then delete (should behave same as above )
syntax = new LdapSyntax("0.1.1");
assertTrue(schemaManager.add(syntax));
assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
syntax = schemaManager.lookupLdapSyntaxRegistry("0.1.1");
assertTrue(schemaManager.delete(syntax));
try {
schemaManager.lookupLdapSyntaxRegistry("0.1.1");
fail("shouldn't find the syntax");
} catch (Exception e) {
// expected behaviour
}
assertEquals(sSize - 1, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.
the class SchemaManagerDelTest method testDeleteNonExistingSyntax.
@Test
public void testDeleteNonExistingSyntax() throws Exception {
SchemaManager schemaManager = loadSchema("system");
int sSize = schemaManager.getLdapSyntaxRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
LdapSyntax syntax = new LdapSyntax("0.1.1");
assertFalse(schemaManager.delete(syntax));
assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Aggregations