use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testRemoveByteArray.
/**
* Test method remove( byte... )
*/
@Test
public void testRemoveByteArray() throws Exception {
Attribute attr1 = new DefaultAttribute(atPwd);
assertFalse(attr1.remove(BYTES1));
attr1.add(BYTES1, BYTES2, BYTES3);
assertTrue(attr1.remove(BYTES1));
assertEquals(2, attr1.size());
assertTrue(attr1.remove(BYTES2, BYTES3));
assertEquals(0, attr1.size());
assertFalse(attr1.remove(BYTES4));
attr1.clear();
attr1.add(BYTES1, BYTES2, BYTES3);
assertFalse(attr1.remove(BYTES3, BYTES4));
assertEquals(2, attr1.size());
attr1.clear();
attr1.add(BYTES1, (byte[]) null, BYTES2);
assertTrue(attr1.remove((byte[]) null, BYTES1));
assertEquals(1, attr1.size());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testContains.
/**
* Test the contains() method
*/
@Test
public void testContains() throws Exception {
AttributeType at = TestEntryUtils.getIA5StringAttributeType();
DefaultAttribute attr = new DefaultAttribute(at);
attr.add("Test 1");
attr.add("Test 2");
attr.add("Test 3");
assertTrue(attr.contains("test 1"));
assertTrue(attr.contains("Test 2"));
assertTrue(attr.contains("TEST 3"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testGetString.
/**
* Test method getString()
*/
@Test
public void testGetString() throws LdapInvalidAttributeValueException {
Attribute attr1 = new DefaultAttribute(atDC);
assertEquals(1, attr1.add((String) null));
Attribute attr2 = new DefaultAttribute(atDC);
attr2.add("a");
assertEquals("a", attr2.getString());
Attribute attr3 = new DefaultAttribute(atPwd);
attr3.add(BYTES1, BYTES2);
try {
attr3.getString();
fail();
} catch (LdapInvalidAttributeValueException ivae) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testSetUpIdStringAttributeType.
/**
* Test method setUpId( String, AttributeType )
*/
@Test
public void testSetUpIdStringAttributeType() throws Exception {
Attribute attr = new DefaultAttribute(atSN);
attr.setUpId(null, atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals("cn", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals("cn", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" CN ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" CN ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" CommonName ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" CommonName ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
attr.setUpId(" 2.5.4.3 ", atCN);
assertEquals("2.5.4.3", attr.getId());
assertEquals(" 2.5.4.3 ", attr.getUpId());
assertEquals(atCN, attr.getAttributeType());
// Check with wrong IDs
try {
attr.setUpId("sn", atCN);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
try {
attr.setUpId(" 2.5.4.4 ", atCN);
fail();
} catch (IllegalArgumentException iae) {
assertTrue(true);
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testAddTwoValue.
@Test
public void testAddTwoValue() throws Exception {
AttributeType at = TestEntryUtils.getIA5StringAttributeType();
DefaultAttribute attr = new DefaultAttribute(at);
// Add String values
attr.add("test");
attr.add("test2");
assertEquals(2, attr.size());
assertTrue(attr.getAttributeType().getSyntax().isHumanReadable());
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());
}
Aggregations