use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class AttributeTypeDescriptionSchemaParserTest method testSuperType.
/**
* Test SUP and its value.
*
* @throws ParseException
*/
@Test
public void testSuperType() throws ParseException {
String value = null;
AttributeType attributeType = null;
// no SUP
value = "( 1.1 SYNTAX 1.1 )";
attributeType = parser.parseAttributeTypeDescription(value);
assertNull(attributeType.getSuperiorOid());
// SUP numericoid
value = "( 1.1 SYNTAX 1.1 SUP 1.2.3.4.5.6.7.8.9.0 )";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("1.2.3.4.5.6.7.8.9.0", attributeType.getSuperiorOid());
// SUP descr, no space
value = "(1.1 SYNTAX1.1 SUPabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSuperiorOid());
// SUP descr, newline
value = "\t(\t1.1\tSYNTAX\t1.1\tSUP\tabcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789\t)\t";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", attributeType.getSuperiorOid());
// quoted SUP value
value = "( 1.1 SYNTAX 1.1 SUP 'name' )";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("name", attributeType.getSuperiorOid());
// quoted SUP value
value = "( 1.1 SYNTAX 1.1 SUP '1.2.3.4' )";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("1.2.3.4", attributeType.getSuperiorOid());
// quoted SUP value
value = "( 1.1 SYNTAX 1.1 SUP ('1.2.3.4') )";
attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("1.2.3.4", attributeType.getSuperiorOid());
// invalid character
value = "( 1.1 SYNTAX 1.1 SUP 1.2.3.4.A )";
try {
attributeType = parser.parseAttributeTypeDescription(value);
fail("Exception expected, invalid SUP '1.2.3.4.A' (invalid character)");
} catch (ParseException pe) {
// expected
}
// only single SUP allowed
value = "( 1.1 SYNTAX 1.1 SUP ( name1 $ name2 ) )";
try {
attributeType = parser.parseAttributeTypeDescription(value);
fail("Exception expected, only single SUP allowed");
} catch (ParseException pe) {
// expected
}
// empty sup
value = "( 1.1 SYNTAX 1.1 SUP )";
try {
attributeType = parser.parseAttributeTypeDescription(value);
fail("Exception expected, no SUP value");
} catch (ParseException pe) {
// expected
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class AttributeTypeDescriptionSchemaParserTest method testRfcUid.
// //////////////////////////////////////////////////////////////
// Some real-world attribute type definitions //
// //////////////////////////////////////////////////////////////
@Test
public void testRfcUid() throws ParseException {
String value = "( 0.9.2342.19200300.100.1.1 NAME ( 'uid' 'userid' ) DESC 'RFC1274: user identifier' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} USAGE userApplications )";
AttributeType attributeType = parser.parseAttributeTypeDescription(value);
assertEquals("0.9.2342.19200300.100.1.1", attributeType.getOid());
assertEquals(2, attributeType.getNames().size());
assertEquals("uid", attributeType.getNames().get(0));
assertEquals("userid", attributeType.getNames().get(1));
assertEquals("RFC1274: user identifier", attributeType.getDescription());
assertNull(attributeType.getSuperiorOid());
assertEquals("caseIgnoreMatch", attributeType.getEqualityOid());
assertEquals("caseIgnoreSubstringsMatch", attributeType.getSubstringOid());
assertNull(attributeType.getOrderingOid());
assertEquals("1.3.6.1.4.1.1466.115.121.1.15", attributeType.getSyntaxOid());
assertEquals(256, attributeType.getSyntaxLength());
assertEquals(UsageEnum.USER_APPLICATIONS, attributeType.getUsage());
assertFalse(attributeType.isObsolete());
assertFalse(attributeType.isCollective());
assertFalse(attributeType.isSingleValued());
assertTrue(attributeType.isUserModifiable());
assertEquals(0, attributeType.getExtensions().size());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class AttributeTypeDescriptionSchemaParserTest method testAttributeTypeWithSchemaExtension.
/**
* Tests the parse of a simple AttributeType with the schema extension.
*/
@Test
public void testAttributeTypeWithSchemaExtension() throws ParseException {
String substrate = "( 1.3.6.1.4.1.18060.0.4.0.2.10000 NAME ( 'bogus' 'bogusName' ) " + "DESC 'bogus description' SUP name SINGLE-VALUE X-SCHEMA 'blah' )";
AttributeType desc = parser.parseAttributeTypeDescription(substrate);
assertEquals("1.3.6.1.4.1.18060.0.4.0.2.10000", desc.getOid());
assertEquals("bogus", desc.getNames().get(0));
assertEquals("bogusName", desc.getNames().get(1));
assertEquals("bogus description", desc.getDescription());
assertEquals("name", desc.getSuperiorOid());
assertEquals(true, desc.isSingleValued());
assertEquals("blah", desc.getExtension("X-SCHEMA").get(0));
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testParseOpenLdapCollectiveSchema.
@Test
public void testParseOpenLdapCollectiveSchema() throws Exception {
InputStream input = getClass().getResourceAsStream("collective.schema");
parser.parse(input);
List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
assertEquals(13, attributeTypes.size());
assertEquals(0, objectClassTypes.size());
assertEquals(0, objectIdentifierMacros.size());
for (AttributeType attributeTypeLiteral : attributeTypes) {
assertTrue(attributeTypeLiteral.isCollective());
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class OpenLdapSchemaParserTest method testSimpleAttributeTypeNoLength.
@Test
public void testSimpleAttributeTypeNoLength() throws Exception {
String attributeTypeData = "attributetype ( 2.5.4.14 NAME 'searchGuide'\n" + " DESC 'RFC2256: search guide, obsoleted by enhancedSearchGuide'\n" + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.25 )";
parser.parse(attributeTypeData);
List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
Map<String, AttributeType> mapAttributeTypes = mapAttributeTypes(attributeTypes);
AttributeType attributeType = mapAttributeTypes.get("2.5.4.14");
assertNotNull(attributeType);
assertEquals("2.5.4.14", attributeType.getOid());
assertEquals("searchGuide", attributeType.getName());
assertEquals("RFC2256: search guide, obsoleted by enhancedSearchGuide", attributeType.getDescription());
assertEquals("1.3.6.1.4.1.1466.115.121.1.25", attributeType.getSyntaxOid());
}
Aggregations