use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testUserCertificateBinary.
/**
* Test method for userCertificate;binary AT
*/
@Test
public void testUserCertificateBinary() throws LdapException {
Entry entry = new DefaultEntry(schemaManager);
entry.add("objectClass", "top", "person", "inetorgPerson");
entry.add("cn", "test1", "test2");
entry.add("sn", "Test1", "Test2");
entry.add("userPassword", BYTES1, BYTES2);
entry.add("userCertificate;binary", Strings.getBytesUtf8("secret"));
assertTrue(entry.containsAttribute("userCertificate;binary"));
assertTrue(entry.containsAttribute("userCertificate"));
entry.removeAttributes("userCertificate;binary");
assertFalse(entry.containsAttribute("userCertificate;binary"));
assertFalse(entry.containsAttribute("userCertificate"));
entry.add("userCertificate", Strings.getBytesUtf8("secret"));
assertTrue(entry.containsAttribute("userCertificate;binary"));
assertTrue(entry.containsAttribute("userCertificate"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project directory-ldap-api by apache.
the class SchemaAwareEntryTest method testSerializeCompleteEntry.
/**
* Test the serialization of a complete entry
*/
@Test
public void testSerializeCompleteEntry() throws LdapException, IOException, ClassNotFoundException {
Dn dn = new Dn(schemaManager, "ou=system");
byte[] password = Strings.getBytesUtf8("secret");
Entry entry = new DefaultEntry(dn);
entry.add("ObjectClass", "top", "person");
entry.add("cn", "test1");
entry.add("userPassword", password);
Entry entrySer = deserializeValue(serializeValue(entry));
assertEquals(entry, entrySer);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry 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.DefaultEntry 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