Search in sources :

Example 86 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SearchResultEntryTest method testResponseWith1Attr2Value.

/**
 * Test parsing of a response with 1 Attr 2 Value
 */
@Test
public void testResponseWith1Attr2Value() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultEntryTest.class.getResource("response_with_1_attr_2_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultEntry searchResultEntry = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultEntry();
    Entry entry = searchResultEntry.getEntry();
    assertEquals(1, entry.size());
    Iterator<Attribute> attributeIterator = entry.iterator();
    Attribute attribute = attributeIterator.next();
    assertEquals("objectclass", attribute.getUpId());
    assertEquals(2, attribute.size());
    Iterator<Value> valueIterator = attribute.iterator();
    assertTrue(valueIterator.hasNext());
    Value value = valueIterator.next();
    assertEquals("top", value.getValue());
    assertTrue(valueIterator.hasNext());
    value = valueIterator.next();
    assertEquals("domain", value.getValue());
    assertFalse(valueIterator.hasNext());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Value(org.apache.directory.api.ldap.model.entry.Value) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 87 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testRemoveStringByteArrayArray.

/**
 * Test method for remove(String, byte[]... )
 */
@Test
public void testRemoveStringByteArrayArray() throws LdapException {
    Entry entry = new DefaultEntry(exampleDn);
    Attribute attrPWD = new DefaultAttribute("userPassword", BYTES1, (byte[]) null, BYTES2);
    entry.put(attrPWD);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertTrue(entry.remove("userPassword", BYTES1, BYTES2));
    assertFalse(entry.containsAttribute("userPassword"));
    entry.add("userPassword", BYTES1, (byte[]) null, BYTES2);
    assertTrue(entry.remove("userPassword", (byte[]) null));
    assertEquals(2, entry.get("userPassword").size());
    assertTrue(entry.remove("userPassword", BYTES1, BYTES3));
    assertEquals(1, entry.get("userPassword").size());
    assertTrue(Arrays.equals(BYTES2, entry.get("userPassword").getBytes()));
    assertFalse(entry.remove("userPassword", BYTES3));
    assertFalse(entry.remove("void", "whatever"));
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Example 88 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaAwareEntryTest method testPutStringStringArray.

/**
 * Test method for put( String, String... )
 */
@Test
public void testPutStringStringArray() {
    Entry entry = new DefaultEntry(exampleDn);
    try {
        entry.put((String) null, "a");
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    try {
        entry.put("   ", "a");
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(true);
    }
    entry.put("sn", (String) null);
    assertEquals(1, entry.size());
    assertNotNull("sn", entry.get("sn"));
    assertEquals(1, entry.get("sn").size());
    assertNull(entry.get("sn").get().getValue());
    entry.put("ObjectClass", "top", "person", "top");
    assertEquals(2, entry.size());
    assertNotNull("objectclass", entry.get("sn"));
    assertEquals(2, entry.get("OBJECTCLASS").size());
    Attribute attribute = entry.get("objectClass");
    assertTrue(attribute.contains("top"));
    assertTrue(attribute.contains("person"));
    assertEquals("objectclass", attribute.getId());
    assertEquals("ObjectClass", attribute.getUpId());
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Test(org.junit.Test)

Example 89 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaAwareModificationSerializationTest method deserializeValue.

/**
 * Deserialize a DefaultModification
 */
private Modification deserializeValue(ByteArrayOutputStream out) throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    ObjectInputStream oIn = null;
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    try {
        oIn = new ObjectInputStream(in);
        Modification modification = new DefaultModification();
        modification.readExternal(oIn);
        Attribute attribute = modification.getAttribute();
        if ((attribute != null) && (schemaManager != null)) {
            AttributeType attributeType = schemaManager.getAttributeType(attribute.getId());
            modification.apply(attributeType);
        }
        return modification;
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        try {
            if (oIn != null) {
                oIn.close();
            }
        } catch (IOException ioe) {
            throw ioe;
        }
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 90 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class SchemaAwareModificationSerializationTest method testCreateServerModification.

@Test
public void testCreateServerModification() throws LdapException {
    Attribute attribute = new DefaultAttribute("cn", cnAT);
    attribute.add("test1", "test2");
    Modification mod = new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attribute);
    Modification clone = mod.clone();
    attribute.remove("test2");
    Attribute clonedAttribute = clone.getAttribute();
    assertEquals(1, mod.getAttribute().size());
    assertTrue(mod.getAttribute().contains("TEST1"));
    assertEquals(2, clonedAttribute.size());
    assertTrue(clone.getAttribute().contains("test1"));
    assertTrue(clone.getAttribute().contains("test2"));
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13