use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddEntryAttributeArray.
/**
* Test method for add( EntryAttribute... )
*/
@Test
public void testAddEntryAttributeArray() throws LdapException {
Entry entry = createEntry();
assertEquals(4, entry.size());
assertTrue(entry.containsAttribute("ObjectClass"));
assertTrue(entry.containsAttribute("CN"));
assertTrue(entry.containsAttribute(" sn "));
assertTrue(entry.containsAttribute("userPassword"));
Attribute attr = entry.get("objectclass");
assertEquals(2, attr.size());
Attribute attrCN2 = new DefaultAttribute("cn", "test1", "test3");
entry.add(attrCN2);
assertEquals(4, entry.size());
attr = entry.get("cn");
assertEquals(3, attr.size());
assertTrue(attr.contains("test1", "test2", "test3"));
// Check adding some byte[] values (they will not be transformed to Strings)
attrCN2.clear();
attrCN2.add(BYTES1, BYTES2);
entry.add(attrCN2);
assertEquals(4, entry.size());
attr = entry.get("cn");
assertEquals(3, attr.size());
assertTrue(attr.contains("test1", "test2", "test3"));
assertFalse(attr.contains("ab", "b"));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddStringValueArray.
/**
* Test method for add( String, Value... )
*/
@Test
public void testAddStringValueArray() throws LdapException {
Entry entry = new DefaultEntry();
Value value = new Value((String) null);
entry.add("cn", value);
assertEquals(1, entry.size());
Attribute attributeCN = entry.get("cn");
assertEquals(1, attributeCN.size());
assertNotNull(attributeCN.get());
assertNull(attributeCN.get().getValue());
Value value1 = new Value("test1");
Value value2 = new Value("test2");
Value value3 = new Value("test1");
entry.add("sn", value1, value2, value3);
assertEquals(2, entry.size());
Attribute attributeSN = entry.get("sn");
assertEquals(2, attributeSN.size());
assertNotNull(attributeSN.get());
assertTrue(attributeSN.contains(value1));
assertTrue(attributeSN.contains(value2));
Value value4 = new Value(BYTES1);
entry.add("l", value1, value4);
assertEquals(3, entry.size());
Attribute attributeL = entry.get("l");
assertEquals(2, attributeL.size());
assertNotNull(attributeL.get());
assertTrue(attributeL.contains(value1));
// The byte[] value must have been transformed to a String
assertTrue(attributeL.contains("ab"));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testAddStringByteArrayArray.
/**
* Test method for add( String, byte[]... )
*/
@Test
public void testAddStringByteArrayArray() throws LdapException {
Entry entry = new DefaultEntry();
entry.add("userPassword", (byte[]) null);
assertEquals(1, entry.size());
Attribute attributePWD = entry.get("userPassword");
assertEquals(1, attributePWD.size());
assertNotNull(attributePWD.get());
assertNull(attributePWD.get().getBytes());
entry.add("jpegPhoto", BYTES1, BYTES1, BYTES2);
assertEquals(2, entry.size());
Attribute attributeJPG = entry.get("jpegPhoto");
assertEquals(2, attributeJPG.size());
assertNotNull(attributeJPG.get());
assertTrue(attributeJPG.contains(BYTES1));
assertTrue(attributeJPG.contains(BYTES2));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testRemoveStringValueArray.
/**
* Test method for remove(String, Value... )
*/
@Test
public void testRemoveStringValueArray() throws LdapException {
Entry entry = new DefaultEntry(exampleDn);
Attribute attrCN = new DefaultAttribute("cn", "test1", "test2", (String) null);
Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, BYTES2, (byte[]) null);
entry.add(attrCN, attrPWD);
Value strValue1 = new Value("test1");
Value strValue2 = new Value("test2");
Value strValue3 = new Value("test3");
Value strNullValue = new Value((String) null);
Value binValue1 = new Value(BYTES1);
Value binValue2 = new Value(BYTES2);
Value binValue3 = new Value(BYTES3);
Value binNullValue = new Value((byte[]) null);
assertTrue(entry.remove("cn", strValue1, strNullValue));
assertTrue(entry.contains("cn", strValue2));
assertFalse(entry.remove("cn", strValue3));
assertTrue(entry.remove("cn", strValue2));
assertFalse(entry.containsAttribute("cn"));
entry.add(attrCN, attrPWD);
assertTrue(entry.remove("userpassword", binValue1, binNullValue));
assertTrue(entry.contains("userpassword", binValue2));
assertFalse(entry.remove("userpassword", binValue3));
assertTrue(entry.remove("userpassword", binValue2));
assertFalse(entry.containsAttribute("userpassword"));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testPutStringByteArrayArray.
/**
* Test method for put( String, byte[]... )
*/
@Test
public void testPutStringByteArrayArray() {
Entry entry = new DefaultEntry(exampleDn);
try {
entry.put((String) null, BYTES1);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
try {
entry.put(" ", BYTES1);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
entry.put("userPassword", (byte[]) null);
assertEquals(1, entry.size());
assertNotNull(entry.get("userPassword"));
assertEquals(1, entry.get("userPassword").size());
assertNull(entry.get("userPassword").get().getBytes());
entry.put("jpegPhoto", BYTES1, BYTES2, BYTES1);
assertEquals(2, entry.size());
assertNotNull(entry.get("jpegPhoto"));
assertEquals(2, entry.get("JPEGPhoto").size());
Attribute attribute = entry.get("jpegPhoto");
assertTrue(attribute.contains(BYTES1));
assertTrue(attribute.contains(BYTES2));
assertEquals("jpegphoto", attribute.getId());
assertEquals("jpegPhoto", attribute.getUpId());
}
Aggregations