use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testRemoveValueArray.
/**
* Test method remove( Value... )
*/
@Test
public void testRemoveValueArray() throws Exception {
Attribute attr1 = new DefaultAttribute(atEMail);
assertFalse(attr1.remove(stringValue1));
attr1.add("a", "b", "c");
assertTrue(attr1.remove(stringValue1));
assertEquals(2, attr1.size());
assertTrue(attr1.remove(stringValue2, stringValue3));
assertEquals(0, attr1.size());
assertFalse(attr1.remove(stringValue4));
attr1.clear();
attr1.add("a", "b", "c");
assertFalse(attr1.remove(stringValue2, stringValue4));
assertEquals(2, attr1.size());
attr1.clear();
attr1.add("a", (String) null, "b");
assertTrue(attr1.remove(nullStringValue, stringValue1));
assertEquals(1, attr1.size());
attr1.clear();
attr1.add("a", (String) null, "b");
attr1.add(BYTES3);
assertFalse(attr1.remove(nullStringValue, stringValue1, binaryValue3));
assertEquals(1, attr1.size());
Attribute attr2 = new DefaultAttribute(atPwd);
assertFalse(attr2.remove(binaryValue1));
attr2.add(BYTES1, BYTES2, BYTES3);
assertTrue(attr2.remove(binaryValue1));
assertEquals(2, attr2.size());
assertTrue(attr2.remove(binaryValue2, binaryValue3));
assertEquals(0, attr2.size());
assertFalse(attr2.remove(binaryValue4));
attr2.clear();
attr2.add(BYTES1, BYTES2, BYTES3);
assertFalse(attr2.remove(binaryValue2, stringValue4));
assertEquals(2, attr2.size());
attr2.clear();
attr2.add(BYTES1, (byte[]) null, BYTES3);
assertFalse(attr2.remove(nullStringValue, binaryValue1));
assertEquals(2, attr2.size());
attr2.clear();
attr2.add(BYTES1, (byte[]) null, BYTES2);
attr2.add("c");
assertEquals(4, attr2.size());
assertFalse(attr2.remove(nullStringValue, binaryValue1, stringValue3));
assertEquals(3, attr2.size());
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddByteArray.
/**
* Test method add( byte[]... )
*/
@Test
public void testAddByteArray() throws LdapInvalidAttributeValueException {
Attribute attr1 = new DefaultAttribute(atPwd);
int nbAdded = attr1.add((byte[]) null);
assertEquals(1, nbAdded);
assertFalse(attr1.isHumanReadable());
assertTrue(Arrays.equals(nullBinaryValue.getBytes(), attr1.getBytes()));
Attribute attr2 = new DefaultAttribute(atPwd);
nbAdded = attr2.add(Strings.EMPTY_BYTES);
assertEquals(1, nbAdded);
assertFalse(attr2.isHumanReadable());
assertTrue(Arrays.equals(Strings.EMPTY_BYTES, attr2.getBytes()));
Attribute attr3 = new DefaultAttribute(atPwd);
nbAdded = attr3.add(BYTES1);
assertEquals(1, nbAdded);
assertFalse(attr3.isHumanReadable());
assertTrue(Arrays.equals(BYTES1, attr3.getBytes()));
Attribute attr4 = new DefaultAttribute(atPwd);
nbAdded = attr4.add(BYTES1, BYTES2, BYTES3, BYTES4);
assertEquals(4, nbAdded);
assertFalse(attr4.isHumanReadable());
assertTrue(attr4.contains(BYTES1));
assertTrue(attr4.contains(BYTES2));
assertTrue(attr4.contains(BYTES3));
assertTrue(attr4.contains(BYTES4));
Attribute attr5 = new DefaultAttribute(atPwd);
nbAdded = attr5.add(BYTES1, BYTES2, (byte[]) null, BYTES3);
assertEquals(4, nbAdded);
assertFalse(attr5.isHumanReadable());
assertTrue(attr5.contains(BYTES1));
assertTrue(attr5.contains(BYTES2));
assertTrue(attr5.contains((byte[]) null));
assertTrue(attr5.contains(BYTES3));
Attribute attr6 = new DefaultAttribute(atPwd);
nbAdded = attr6.add("ab", (String) null);
assertEquals(2, nbAdded);
assertFalse(attr6.isHumanReadable());
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeValueArray.
/**
* Test constructor DefaultEntryAttribute( String, AttributeType, Value... )
*/
@Test
public void testDefaultServerAttributeStringAttributeTypeValueArray() throws LdapException {
Attribute attr1 = new DefaultAttribute("dc", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr1.isHumanReadable());
assertEquals(3, attr1.size());
assertEquals("0.9.2342.19200300.100.1.25", attr1.getId());
assertEquals("dc", attr1.getUpId());
assertEquals(atDC, attr1.getAttributeType());
assertTrue(attr1.contains("a", "b"));
assertTrue(attr1.contains(nullStringValue));
Attribute attr2 = new DefaultAttribute(atDC, stringValue1, binaryValue2, nullStringValue);
assertTrue(attr2.isHumanReadable());
assertEquals(2, attr2.size());
assertEquals("0.9.2342.19200300.100.1.25", attr2.getId());
assertEquals("dc", attr2.getUpId());
assertEquals(atDC, attr2.getAttributeType());
assertTrue(attr2.contains("a"));
assertTrue(attr2.contains(nullStringValue));
Attribute attr3 = new DefaultAttribute("DomainComponent", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr3.isHumanReadable());
assertEquals(3, attr3.size());
assertEquals("0.9.2342.19200300.100.1.25", attr3.getId());
assertEquals("DomainComponent", attr3.getUpId());
assertEquals(atDC, attr3.getAttributeType());
assertTrue(attr3.contains("a", "b"));
assertTrue(attr3.contains(nullStringValue));
Attribute attr4 = new DefaultAttribute(" 0.9.2342.19200300.100.1.25 ", atDC, stringValue1, stringValue2, nullStringValue);
assertTrue(attr4.isHumanReadable());
assertEquals(3, attr4.size());
assertEquals("0.9.2342.19200300.100.1.25", attr4.getId());
assertEquals(" 0.9.2342.19200300.100.1.25 ", attr4.getUpId());
assertEquals(atDC, attr4.getAttributeType());
assertTrue(attr4.contains("a", "b"));
assertTrue(attr4.contains(nullStringValue));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeTypeByteArray.
/**
* Test method DefaultEntryAttribute( String, AttributeType, byte[]... )
*/
@Test
public void testDefaultServerAttributeStringAttributeTypeByteArray() throws LdapException {
Attribute attr1 = new DefaultAttribute("userPassword", atPwd, BYTES1, BYTES2, (byte[]) null);
assertFalse(attr1.isHumanReadable());
assertEquals(3, attr1.size());
assertEquals("2.5.4.35", attr1.getId());
assertEquals("userPassword", attr1.getUpId());
assertEquals(atPwd, attr1.getAttributeType());
assertTrue(attr1.contains(BYTES1, BYTES2));
assertTrue(attr1.contains(nullBinaryValue));
Attribute attr2 = new DefaultAttribute("2.5.4.35", atPwd, stringValue1, binaryValue2, nullBinaryValue);
assertFalse(attr2.isHumanReadable());
assertEquals(2, attr2.size());
assertEquals("2.5.4.35", attr2.getId());
assertEquals("2.5.4.35", attr2.getUpId());
assertEquals(atPwd, attr2.getAttributeType());
assertTrue(attr2.contains(BYTES2));
assertTrue(attr2.contains(nullBinaryValue));
}
use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddStringArray.
/**
* Test method add( String... )
*/
@Test
public void testAddStringArray() throws LdapInvalidAttributeValueException {
Attribute attr1 = new DefaultAttribute(atDC);
int nbAdded = attr1.add((String) null);
assertEquals(1, nbAdded);
assertTrue(attr1.isHumanReadable());
assertEquals(nullStringValue, attr1.get());
Attribute attr2 = new DefaultAttribute(atDC);
nbAdded = attr2.add("");
assertEquals(1, nbAdded);
assertTrue(attr2.isHumanReadable());
assertEquals("", attr2.getString());
Attribute attr3 = new DefaultAttribute(atCN);
nbAdded = attr3.add("t");
assertEquals(1, nbAdded);
assertTrue(attr3.isHumanReadable());
assertEquals("t", attr3.getString());
Attribute attr4 = new DefaultAttribute(atCN);
nbAdded = attr4.add("a", "b", "c", "d");
assertEquals(4, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
nbAdded = attr4.add("e");
assertEquals(1, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
assertTrue(attr4.contains("e"));
nbAdded = attr4.add(BYTES1);
assertEquals(0, nbAdded);
assertTrue(attr4.isHumanReadable());
assertEquals("a", attr4.getString());
assertTrue(attr4.contains("a"));
assertTrue(attr4.contains("b"));
assertTrue(attr4.contains("c"));
assertTrue(attr4.contains("d"));
assertTrue(attr4.contains("e"));
assertFalse(attr4.contains("ab"));
Attribute attr5 = new DefaultAttribute(atEMail);
nbAdded = attr5.add("a", "b", (String) null, "d");
assertEquals(4, nbAdded);
assertTrue(attr5.isHumanReadable());
assertTrue(attr5.contains("a"));
assertTrue(attr5.contains("b"));
assertTrue(attr5.contains(nullStringValue));
assertTrue(attr5.contains("d"));
Attribute attr6 = new DefaultAttribute(atPwd);
nbAdded = attr6.add("a", (String) null);
assertEquals(2, nbAdded);
assertFalse(attr6.isHumanReadable());
}
Aggregations