use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddOneValue.
@Test
public void testAddOneValue() throws Exception {
AttributeType at = TestEntryUtils.getIA5StringAttributeType();
DefaultAttribute attr = new DefaultAttribute(at);
// Add a String value
attr.add("test");
assertEquals(1, attr.size());
assertTrue(attr.getAttributeType().getSyntax().isHumanReadable());
Value value = attr.get();
assertTrue(value instanceof Value);
assertEquals("test", ((Value) value).getValue());
// Add a binary value
assertEquals(0, attr.add(new byte[] { 0x01 }));
// Add a Value
Value ssv = new Value(at, "test2");
attr.add(ssv);
assertEquals(2, attr.size());
Set<String> expected = new HashSet<String>();
expected.add("test");
expected.add("test2");
for (Value val : attr) {
if (expected.contains(val.getValue())) {
expected.remove(val.getValue());
} else {
fail();
}
}
assertEquals(0, expected.size());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class SchemaAwareModificationSerializationTest method deserializeValue.
/**
* Deserialize a DefaultModification
*/
private Modification deserializeValue(ByteArrayOutputStream out) throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
ObjectInputStream oIn = null;
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
try {
oIn = new ObjectInputStream(in);
Modification modification = new DefaultModification();
modification.readExternal(oIn);
Attribute attribute = modification.getAttribute();
if ((attribute != null) && (schemaManager != null)) {
AttributeType attributeType = schemaManager.getAttributeType(attribute.getId());
modification.apply(attributeType);
}
return modification;
} catch (IOException ioe) {
throw ioe;
} finally {
try {
if (oIn != null) {
oIn.close();
}
} catch (IOException ioe) {
throw ioe;
}
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class DefaultSchemaLoader method loadAttributeTypes.
/**
* {@inheritDoc}
*/
@Override
public List<Entry> loadAttributeTypes(Schema... schemas) throws LdapException, IOException {
List<Entry> attributeTypeEntries = new ArrayList<>();
if (schemas == null) {
return attributeTypeEntries;
}
AttributesFactory factory = new AttributesFactory();
for (Schema schema : schemas) {
Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
SchemaObject schemaObject = schemaObjectWrapper.get();
if (schemaObject instanceof AttributeType) {
AttributeType attributeType = (AttributeType) schemaObject;
Entry attributeTypeEntry = factory.convert(attributeType, schema, null);
attributeTypeEntries.add(attributeTypeEntry);
}
}
}
return attributeTypeEntries;
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class BinaryValueAttributeTypeTest method testgetAttributeType.
/**
* Test the getAttributeType method
* @throws LdapInvalidAttributeValueException
*/
@Test
public void testgetAttributeType() throws LdapInvalidAttributeValueException {
AttributeType attribute = EntryUtils.getBytesAttributeType();
Value sbv = Value.createValue(attribute);
assertEquals(attribute, sbv.getAttributeType());
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class BinaryValueAttributeTypeTest method testInstanceOf.
/**
* Test the instanceOf method
*/
@Test
public void testInstanceOf() throws LdapException {
AttributeType attribute = EntryUtils.getBytesAttributeType();
Value sbv = Value.createValue(attribute);
assertTrue(sbv.isInstanceOf(attribute));
attribute = EntryUtils.getIA5StringAttributeType();
assertFalse(sbv.isInstanceOf(attribute));
}
Aggregations