use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SearchResultEntryTest method testResponseWith1Attr2Value.
/**
* Test parsing of a response with 1 Attr 2 Value
*/
@Test
public void testResponseWith1Attr2Value() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultEntryTest.class.getResource("response_with_1_attr_2_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResultEntry searchResultEntry = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultEntry();
Entry entry = searchResultEntry.getEntry();
assertEquals(1, entry.size());
Iterator<Attribute> attributeIterator = entry.iterator();
Attribute attribute = attributeIterator.next();
assertEquals("objectclass", attribute.getUpId());
assertEquals(2, attribute.size());
Iterator<Value> valueIterator = attribute.iterator();
assertTrue(valueIterator.hasNext());
Value value = valueIterator.next();
assertEquals("top", value.getValue());
assertTrue(valueIterator.hasNext());
value = valueIterator.next();
assertEquals("domain", value.getValue());
assertFalse(valueIterator.hasNext());
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testRemoveStringByteArrayArray.
/**
* Test method for remove(String, byte[]... )
*/
@Test
public void testRemoveStringByteArrayArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
entry.put(attrPWD);
assertTrue(entry.remove("userPassword", (byte[]) null));
assertTrue(entry.remove("userPassword", BYTES1, BYTES2));
assertFalse(entry.containsAttribute("userPassword"));
entry.add("userPassword", BYTES1, (byte[]) null, BYTES2);
assertTrue(entry.remove("userPassword", (byte[]) null));
assertEquals(2, entry.get("userPassword").size());
assertTrue(entry.remove("userPassword", BYTES1, BYTES3));
assertEquals(1, entry.get("userPassword").size());
assertTrue(Arrays.equals(BYTES2, entry.get("userPassword").getBytes()));
assertFalse(entry.remove("userPassword", BYTES3));
assertFalse(entry.remove("void", "whatever"));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testPutStringStringArray.
/**
* Test method for put( String, String... )
*/
@Test
public void testPutStringStringArray() {
Entry entry = new DefaultEntry(exampleDn);
try {
entry.put((String) null, "a");
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
try {
entry.put(" ", "a");
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
entry.put("sn", (String) null);
assertEquals(1, entry.size());
assertNotNull("sn", entry.get("sn"));
assertEquals(1, entry.get("sn").size());
assertNull(entry.get("sn").get().getValue());
entry.put("ObjectClass", "top", "person", "top");
assertEquals(2, entry.size());
assertNotNull("objectclass", entry.get("sn"));
assertEquals(2, entry.get("OBJECTCLASS").size());
Attribute attribute = entry.get("objectClass");
assertTrue(attribute.contains("top"));
assertTrue(attribute.contains("person"));
assertEquals("objectclass", attribute.getId());
assertEquals("ObjectClass", attribute.getUpId());
}
use of org.apache.directory.api.ldap.model.entry.Attribute 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.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareModificationSerializationTest method testCreateServerModification.
@Test
public void testCreateServerModification() throws LdapException {
Attribute attribute = new DefaultAttribute("cn", cnAT);
attribute.add("test1", "test2");
Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attribute);
Modification clone = mod.clone();
attribute.remove("test2");
Attribute clonedAttribute = clone.getAttribute();
assertEquals(1, mod.getAttribute().size());
assertTrue(mod.getAttribute().contains("TEST1"));
assertEquals(2, clonedAttribute.size());
assertTrue(clone.getAttribute().contains("test1"));
assertTrue(clone.getAttribute().contains("test2"));
}
Aggregations