Search in sources :

Example 16 with SchemaObject

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

the class SchemaParserTestUtils method testExtensions.

/**
 * Test extensions.
 *
 * @throws ParseException
 */
public static void testExtensions(AbstractSchemaParser parser, String oid, String required) throws ParseException {
    String value = null;
    SchemaObject asd = null;
    // no extension
    value = "( " + oid + " " + required + " )";
    asd = parser.parse(value);
    assertEquals(0, asd.getExtensions().size());
    // single extension with one value
    value = "( " + oid + " " + required + " X-TEST 'test' )";
    asd = parser.parse(value);
    assertEquals(1, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-TEST"));
    assertEquals(1, asd.getExtension("X-TEST").size());
    assertEquals("test", asd.getExtension("X-TEST").get(0));
    // single extension with multiple values
    value = "( " + oid + " " + required + " X-TEST-ABC ('test1' 'test \u00E4\u00F6\u00FC\u00DF'       'test \u90E8\u9577' ) )";
    asd = parser.parse(value);
    assertEquals(1, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-TEST-ABC"));
    assertEquals(3, asd.getExtension("X-TEST-ABC").size());
    assertEquals("test1", asd.getExtension("X-TEST-ABC").get(0));
    assertEquals("test \u00E4\u00F6\u00FC\u00DF", asd.getExtension("X-TEST-ABC").get(1));
    assertEquals("test \u90E8\u9577", asd.getExtension("X-TEST-ABC").get(2));
    // multiple extensions
    value = "(" + oid + " " + required + " X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2'))";
    asd = parser.parse(value);
    assertEquals(2, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-TEST-a"));
    assertEquals(2, asd.getExtension("X-TEST-a").size());
    assertEquals("test1-1", asd.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", asd.getExtension("X-TEST-a").get(1));
    assertNotNull(asd.getExtension("X-TEST-b"));
    assertEquals(2, asd.getExtension("X-TEST-b").size());
    assertEquals("test2-1", asd.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", asd.getExtension("X-TEST-b").get(1));
    // multiple extensions, no spaces
    value = "(" + oid + " " + required + " X-TEST-a('test1-1''test1-2')X-TEST-b('test2-1''test2-2'))";
    asd = parser.parse(value);
    assertEquals(2, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-TEST-a"));
    assertEquals(2, asd.getExtension("X-TEST-a").size());
    assertEquals("test1-1", asd.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", asd.getExtension("X-TEST-a").get(1));
    assertNotNull(asd.getExtension("X-TEST-b"));
    assertEquals(2, asd.getExtension("X-TEST-b").size());
    assertEquals("test2-1", asd.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", asd.getExtension("X-TEST-b").get(1));
    // multiple extensions, tabs, newline, comments
    value = "(" + oid + "\n#comment\n" + required + "\nX-TEST-a\n(\t'test1-1'\t\n'test1-2'\n\r)\tX-TEST-b\n(\n'test2-1'\t'test2-2'\t)\r)";
    asd = parser.parse(value);
    assertEquals(2, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-TEST-a"));
    assertEquals(2, asd.getExtension("X-TEST-a").size());
    assertEquals("test1-1", asd.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", asd.getExtension("X-TEST-a").get(1));
    assertNotNull(asd.getExtension("X-TEST-b"));
    assertEquals(2, asd.getExtension("X-TEST-b").size());
    assertEquals("test2-1", asd.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", asd.getExtension("X-TEST-b").get(1));
    // some more complicated
    value = "(" + oid + " " + required + " X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ('\\5C\\27\\5c'))";
    asd = parser.parse(value);
    assertEquals(1, asd.getExtensions().size());
    assertNotNull(asd.getExtension("X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
    assertEquals(1, asd.getExtension("X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").size());
    assertEquals("\\'\\", asd.getExtension("X-_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").get(0));
    // invalid extension, no number allowed
    value = "( " + oid + " " + required + " X-TEST1 'test' )";
    try {
        asd = parser.parse(value);
        fail("Exception expected, invalid extension X-TEST1 (no number allowed)");
    } catch (ParseException pe) {
        assertTrue(true);
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ParseException(java.text.ParseException)

Example 17 with SchemaObject

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

the class SchemaParserTestUtils method testDescription.

/**
 * Tests DESC
 *
 * @throws ParseException
 */
public static void testDescription(AbstractSchemaParser parser, String oid, String required) throws ParseException {
    String value = null;
    SchemaObject asd = null;
    // simple
    value = "(" + oid + " " + required + " DESC 'Descripton')";
    asd = parser.parse(value);
    assertEquals("Descripton", asd.getDescription());
    // simple with tabs, newline, comment, etc.
    value = "(" + oid + "\n" + required + "\tDESC#comment\n\n\r\n\r\t'Descripton')";
    asd = parser.parse(value);
    assertEquals("Descripton", asd.getDescription());
    // simple w/o space
    value = "(" + oid + " " + required + " DESC'Descripton')";
    asd = parser.parse(value);
    assertEquals("Descripton", asd.getDescription());
    // simple parentheses and quotes
    value = "(" + oid + " " + required + " DESC ('Descripton') )";
    asd = parser.parse(value);
    assertEquals("Descripton", asd.getDescription());
    // unicode
    value = "( " + oid + " " + required + " DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' )";
    asd = parser.parse(value);
    assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", asd.getDescription());
    // escaped characters
    value = "( " + oid + " " + required + " DESC 'test\\5Ctest' )";
    asd = parser.parse(value);
    assertEquals("test\\test", asd.getDescription());
    value = "( " + oid + " " + required + " DESC 'test\\5ctest' )";
    asd = parser.parse(value);
    assertEquals("test\\test", asd.getDescription());
    value = "( " + oid + " " + required + " DESC 'test\\27test' )";
    asd = parser.parse(value);
    assertEquals("test'test", asd.getDescription());
    value = "( " + oid + " " + required + " DESC '\\5C\\27\\5c' )";
    asd = parser.parse(value);
    assertEquals("\\'\\", asd.getDescription());
    // lowercase DESC
    value = "( " + oid + " " + required + " desc 'Descripton' )";
    asd = parser.parse(value);
    assertEquals("Descripton", asd.getDescription());
    // empty DESC
    value = "( " + oid + " " + required + " DESC '' )";
    asd = parser.parse(value);
    assertEquals("", asd.getDescription());
    // multiple not allowed
    value = "(" + oid + " " + required + " DESC ( 'Descripton1' 'Description 2' )  )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid multiple DESC not allowed.)");
    } catch (ParseException pe) {
    // expected
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ParseException(java.text.ParseException)

Example 18 with SchemaObject

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

the class SchemaParserTestUtils method testObsolete.

/**
 * Tests OBSOLETE
 *
 * @throws ParseException
 */
public static void testObsolete(AbstractSchemaParser parser, String oid, String required) throws ParseException {
    String value = null;
    SchemaObject asd = null;
    // not obsolete
    value = "( " + oid + " " + required + " )";
    asd = parser.parse(value);
    assertFalse(asd.isObsolete());
    // not obsolete
    value = "( " + oid + " " + required + " NAME 'test' DESC 'Descripton' )";
    asd = parser.parse(value);
    assertFalse(asd.isObsolete());
    // obsolete
    value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLETE)";
    asd = parser.parse(value);
    assertTrue(asd.isObsolete());
    // obsolete
    value = "(" + oid + " " + required + " OBSOLETE)";
    asd = parser.parse(value);
    assertTrue(asd.isObsolete());
    // lowercased obsolete
    value = "(" + oid + " " + required + " obsolete)";
    asd = parser.parse(value);
    assertTrue(asd.isObsolete());
    // invalid
    value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLET )";
    try {
        asd = parser.parse(value);
        fail("Exception expected, invalid OBSOLETE value");
    } catch (ParseException pe) {
    // expected
    }
    // trailing value not allowed
    value = "(" + oid + " " + required + " NAME 'test' DESC 'Descripton' OBSOLETE 'true' )";
    try {
        asd = parser.parse(value);
        fail("Exception expected, trailing value ('true') now allowed");
    } catch (ParseException pe) {
        assertTrue(true);
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ParseException(java.text.ParseException)

Example 19 with SchemaObject

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

the class OidRegistry method toString.

/**
 * @see Object#toString()
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    if (byOid != null) {
        boolean isFirst = true;
        for (Map.Entry<String, T> entry : byOid.entrySet()) {
            if (isFirst) {
                isFirst = false;
            } else {
                sb.append(", ");
            }
            sb.append("<");
            SchemaObject schemaObject = entry.getValue();
            if (schemaObject != null) {
                sb.append(schemaObject.getObjectType());
                sb.append(", ");
                sb.append(schemaObject.getOid());
                sb.append(", ");
                sb.append(schemaObject.getName());
            }
            sb.append(">");
        }
    }
    return sb.toString();
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with SchemaObject

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

the class Registries method clone.

/**
 * Clone the Registries. This is done in two steps :
 * - first clone the SchemaObjetc registries
 * - second restore the relation between them
 */
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
    // First clone the structure
    Registries clone = (Registries) super.clone();
    // Now, clone the oidRegistry
    clone.globalOidRegistry = globalOidRegistry.copy();
    // We have to clone every SchemaObject registries now
    clone.attributeTypeRegistry = attributeTypeRegistry.copy();
    clone.comparatorRegistry = comparatorRegistry.copy();
    clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
    clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
    clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
    clone.matchingRuleRegistry = matchingRuleRegistry.copy();
    clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
    clone.nameFormRegistry = nameFormRegistry.copy();
    clone.normalizerRegistry = normalizerRegistry.copy();
    clone.objectClassRegistry = objectClassRegistry.copy();
    clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
    // Store all the SchemaObjects into the globalOid registry
    for (AttributeType attributeType : clone.attributeTypeRegistry) {
        clone.globalOidRegistry.put(attributeType);
    }
    for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
        clone.globalOidRegistry.put(ditContentRule);
    }
    for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
        clone.globalOidRegistry.put(ditStructureRule);
    }
    for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
        clone.globalOidRegistry.put(matchingRule);
    }
    for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
        clone.globalOidRegistry.put(matchingRuleUse);
    }
    for (NameForm nameForm : clone.nameFormRegistry) {
        clone.globalOidRegistry.put(nameForm);
    }
    for (ObjectClass objectClass : clone.objectClassRegistry) {
        clone.globalOidRegistry.put(objectClass);
    }
    for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
        clone.globalOidRegistry.put(syntax);
    }
    // Clone the schema list
    clone.loadedSchemas = new HashMap<>();
    for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
        // We don't clone the schemas
        clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
    }
    // Clone the Using and usedBy structures
    // They will be empty
    clone.using = new HashMap<>();
    clone.usedBy = new HashMap<>();
    // Last, rebuild the using and usedBy references
    clone.buildReferences();
    // Now, check the registries. We don't care about errors
    clone.checkRefInteg();
    clone.schemaObjects = new HashMap<>();
    // SchemaObjects
    for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
        Set<SchemaObjectWrapper> objects = new HashSet<>();
        for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
            SchemaObject original = schemaObjectWrapper.get();
            try {
                if (!(original instanceof LoadableSchemaObject)) {
                    SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
                    SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
                    objects.add(newWrapper);
                } else {
                    SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
                    objects.add(newWrapper);
                }
            } catch (LdapException ne) {
            // Nothing to do
            }
        }
        clone.schemaObjects.put(entry.getKey(), objects);
    }
    return clone;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) HashSet(java.util.HashSet) Set(java.util.Set) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) HashMap(java.util.HashMap) Map(java.util.Map) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet)

Aggregations

SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)37 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)14 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)13 ArrayList (java.util.ArrayList)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)12 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)11 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)10 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 ParseException (java.text.ParseException)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)3 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)3