use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testIsValidSyntaxChecker.
/**
* Test method isValid( SyntaxChecker )
*/
@Test
public void testIsValidSyntaxChecker() throws LdapException {
Attribute attr = new DefaultAttribute("test");
attr.add("test", "another test");
assertTrue(attr.isValid(atCN));
attr.add("test an invalid '\uFFFD' char");
assertFalse(attr.isValid(atCN));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testDefaultServerAttributeStringAttributeType.
/**
* Test constructor DefaultEntryAttribute( String, AttributeType )
*/
@Test
public void testDefaultServerAttributeStringAttributeType() {
Attribute attr1 = new DefaultAttribute("cn", atCN);
assertTrue(attr1.isHumanReadable());
assertEquals(0, attr1.size());
assertEquals("2.5.4.3", attr1.getId());
assertEquals("cn", attr1.getUpId());
assertEquals(atCN, attr1.getAttributeType());
Attribute attr2 = new DefaultAttribute(" CommonName ", atCN);
assertTrue(attr2.isHumanReadable());
assertEquals(0, attr2.size());
assertEquals("2.5.4.3", attr2.getId());
assertEquals(" CommonName ", attr2.getUpId());
assertEquals(atCN, attr2.getAttributeType());
Attribute attr3 = new DefaultAttribute(" ", atCN);
assertTrue(attr3.isHumanReadable());
assertEquals(0, attr3.size());
assertEquals("2.5.4.3", attr3.getId());
assertEquals("cn", attr3.getUpId());
assertEquals(atCN, attr3.getAttributeType());
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testToClientAttribute.
/**
* Test the conversion method
*/
@Test
public void testToClientAttribute() throws LdapException {
Attribute attribute = new DefaultAttribute(atCN, "test", "test2");
Attribute clientAttribute = attribute.clone();
assertTrue(clientAttribute instanceof Attribute);
assertTrue(clientAttribute.contains("test", "test2"));
assertEquals("2.5.4.3", clientAttribute.getId());
attribute.remove("test", "test2");
assertTrue(clientAttribute.contains("test", "test2"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testRemoveStringArray.
/**
* Test method remove( String... )
*/
@Test
public void testRemoveStringArray() throws Exception {
Attribute attr1 = new DefaultAttribute(atEMail);
assertFalse(attr1.remove("a"));
attr1.add("a", "b", "c");
assertTrue(attr1.remove("a"));
assertEquals(2, attr1.size());
assertTrue(attr1.remove("b", "c"));
assertEquals(0, attr1.size());
assertFalse(attr1.remove("d"));
attr1.clear();
attr1.add("a", "b", "c");
assertFalse(attr1.remove("b", "e"));
assertEquals(2, attr1.size());
attr1.clear();
attr1.add("a", (String) null, "b");
assertTrue(attr1.remove((String) null, "a"));
assertEquals(1, attr1.size());
Attribute attr2 = new DefaultAttribute("test");
attr2.add(BYTES1, BYTES2, BYTES3);
assertFalse(attr2.remove((String) null));
assertTrue(attr2.remove("ab", "c"));
assertFalse(attr2.remove("d"));
}
use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.
the class SchemaAwareAttributeTest method testContainsStringArray.
/**
* Test method contains( String... )
*/
@Test
public void testContainsStringArray() throws LdapException {
Attribute attr1 = new DefaultAttribute(atEMail);
assertEquals(0, attr1.size());
assertFalse(attr1.contains("a"));
assertFalse(attr1.contains((String) null));
attr1.add((String) null);
assertEquals(1, attr1.size());
assertTrue(attr1.contains((String) null));
attr1.remove((String) null);
assertFalse(attr1.contains((String) null));
assertEquals(0, attr1.size());
attr1.add("a", "b", "c");
assertEquals(3, attr1.size());
assertTrue(attr1.contains("a"));
assertTrue(attr1.contains("b"));
assertTrue(attr1.contains("c"));
assertFalse(attr1.contains("e"));
assertFalse(attr1.contains((String) null));
}
Aggregations