Search in sources :

Example 31 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWith1ControlEmptyValue.

/**
 * Test parsing of a request with a (optional) Control element with empty value
 */
@Test
public void testRequestWith1ControlEmptyValue() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_1_control_empty_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = modifyRequest.getControls();
    assertEquals(1, modifyRequest.getControls().size());
    Control control = controls.get("1.2.840.113556.1.4.643");
    assertNotNull(control);
    assertTrue(control.isCritical());
    assertEquals("1.2.840.113556.1.4.643", control.getOid());
    assertFalse(((DsmlControl<?>) control).hasValue());
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 32 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWith2Modifications.

/**
 * Test parsing of a request with 2 Modification elements
 * @throws NamingException
 */
@Test
public void testRequestWith2Modifications() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_2_modifications.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(2, modifications.size());
    Iterator<Modification> iter = modifications.iterator();
    Modification modification = iter.next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
    Attribute attribute = modification.getAttribute();
    assertEquals("directreport", attribute.getId());
    assertEquals("CN=John Smith, DC=microsoft, DC=com", attribute.get().getValue());
    modification = iter.next();
    attribute = modification.getAttribute();
    assertEquals("sn", attribute.getId());
    assertEquals(ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation());
    assertEquals("CN=Steve Jobs, DC=apple, DC=com", attribute.get().getValue());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 33 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWithOperationDelete.

/**
 * Test parsing of a request with operation attribute to Delete value
 * @throws NamingException
 */
@Test
public void testRequestWithOperationDelete() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_delete.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.REMOVE_ATTRIBUTE, modification.getOperation());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 34 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWithOperationReplace.

/**
 * Test parsing of a request with operation attribute to Replace value
 * @throws NamingException
 */
@Test
public void testRequestWithOperationReplace() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_operation_replace.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.REPLACE_ATTRIBUTE, modification.getOperation());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 35 with ModifyRequest

use of org.apache.directory.api.ldap.model.message.ModifyRequest in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWithModificationWith2Values.

/**
 * Test parsing of a request with a Modification element
 * @throws NamingException
 */
@Test
public void testRequestWithModificationWith2Values() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_with_2_values.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
    Attribute attribute = modification.getAttribute();
    assertEquals("directreport", attribute.getId());
    assertEquals(2, attribute.size());
    assertTrue(attribute.contains("CN=John Smith, DC=microsoft, DC=com"));
    assertTrue(attribute.contains("CN=Steve Jobs, DC=apple, DC=com"));
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Aggregations

ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)40 Modification (org.apache.directory.api.ldap.model.entry.Modification)25 Test (org.junit.Test)24 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)22 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)17 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)17 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)14 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)11 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)11 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)10 Dn (org.apache.directory.api.ldap.model.name.Dn)10 ByteBuffer (java.nio.ByteBuffer)7 DecoderException (org.apache.directory.api.asn1.DecoderException)7 EncoderException (org.apache.directory.api.asn1.EncoderException)7 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)7 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)7 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)7 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)7 Control (org.apache.directory.api.ldap.model.message.Control)7