Search in sources :

Example 1 with DeleteRequest

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

the class DelRequestTest method testDecodeDelRequestSuccess.

/**
 * Test the decoding of a full DelRequest
 */
@Test
public void testDecodeDelRequestSuccess() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x27);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x25, 0x02, 0x01, // messageID MessageID
    0x01, // DelRequest ::= [APPLICATION 10] LDAPDN;
    0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<DeleteRequestDecorator> container = new LdapMessageContainer<DeleteRequestDecorator>(codec);
    // Decode a DelRequest PDU
    try {
        ldapDecoder.decode(stream, container);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check the decoded DelRequest PDU
    DeleteRequest delRequest = container.getMessage();
    assertEquals(1, delRequest.getMessageId());
    assertEquals("cn=testModify,ou=users,ou=system", delRequest.getName().toString());
    // Check the length
    DeleteRequest internalDeleteRequest = new DeleteRequestImpl();
    internalDeleteRequest.setMessageId(delRequest.getMessageId());
    internalDeleteRequest.setName(delRequest.getName());
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(internalDeleteRequest);
        // Check the length
        assertEquals(0x27, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) DeleteRequestDecorator(org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) ByteBuffer(java.nio.ByteBuffer) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with DeleteRequest

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

the class BatchRequestTest method testResponseWith2DelRequest.

/**
 * Test parsing of a Request with 2 DelRequest
 */
@Test
public void testResponseWith2DelRequest() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(BatchRequestTest.class.getResource("request_with_2_DelRequest.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    BatchRequestDsml batchRequest = parser.getBatchRequest();
    assertEquals(2, batchRequest.getRequests().size());
    if (batchRequest.getCurrentRequest() instanceof DeleteRequest) {
        assertTrue(true);
    } else {
        fail();
    }
}
Also used : BatchRequestDsml(org.apache.directory.api.dsmlv2.request.BatchRequestDsml) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 3 with DeleteRequest

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

the class BatchRequestTest method testResponseWith1DelRequest.

/**
 * Test parsing of a Request with 1 DelRequest
 */
@Test
public void testResponseWith1DelRequest() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(BatchRequestTest.class.getResource("request_with_1_DelRequest.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    BatchRequestDsml batchRequest = parser.getBatchRequest();
    assertEquals(1, batchRequest.getRequests().size());
    if (batchRequest.getCurrentRequest() instanceof DeleteRequest) {
        assertTrue(true);
    } else {
        fail();
    }
}
Also used : BatchRequestDsml(org.apache.directory.api.dsmlv2.request.BatchRequestDsml) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 4 with DeleteRequest

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

the class DelRequestTest 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(DelRequestTest.class.getResource("request_with_1_control_empty_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
    Map<String, Control> controls = delRequest.getControls();
    assertEquals(1, delRequest.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) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 5 with DeleteRequest

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

the class DelRequestTest method testRequestWithRequestId.

/**
 * Test parsing of a request with the (optional) requestID attribute
 */
@Test
public void testRequestWithRequestId() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(DelRequestTest.class.getResource("request_with_requestID_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
    assertEquals(456, delRequest.getMessageId());
}
Also used : Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Aggregations

DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)18 Test (org.junit.Test)11 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)9 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)9 Control (org.apache.directory.api.ldap.model.message.Control)7 DeleteRequestImpl (org.apache.directory.api.ldap.model.message.DeleteRequestImpl)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)5 DeleteRequestDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator)4 Dn (org.apache.directory.api.ldap.model.name.Dn)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)2