Search in sources :

Example 26 with ModifyResponse

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

the class ModifyResponseTest method testResponseWithMatchedDNAttribute.

/**
 * Test parsing of a response with MatchedDN attribute
 */
@Test
public void testResponseWithMatchedDNAttribute() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_matchedDN_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = modifyResponse.getLdapResult();
    assertTrue(ldapResult.getMatchedDn().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 27 with ModifyResponse

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

the class ModifyResponseTest method testResponseWith1Referral.

/**
 * Test parsing of a response with a Referral
 */
@Test
public void testResponseWith1Referral() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_1_referral.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = modifyResponse.getLdapResult();
    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
    assertEquals(1, referrals.size());
    try {
        assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 28 with ModifyResponse

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

the class ModifyResponseTest method testResponseWith1Control.

/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_1_control.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = modifyResponse.getControls();
    assertEquals(1, modifyResponse.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());
    assertEquals("Some text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 29 with ModifyResponse

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

the class ModifyResponseTest method testDecodeModifyResponseSuccessWithControls.

/**
 * Test the decoding of a ModifyResponse with controls
 */
@Test
public void testDecodeModifyResponseSuccessWithControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2B);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x29, 0x02, 0x01, // messageID MessageID
    0x01, 0x67, // CHOICE { ..., modifyResponse ModifyResponse, ...
    0x07, // ModifyResponse ::= [APPLICATION 7] LDAPResult
    0x0A, 0x01, // LDAPResult ::= SEQUENCE {
    0x00, // },
    0x04, // matchedDN LDAPDN,
    0x00, 0x04, // errorMessage LDAPString,
    0x00, // }
    (byte) 0xA0, // A control
    0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyResponseDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyResponseDecorator>(codec);
    // Decode a ModifyResponse PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check the decoded ModifyResponse PDU
    ModifyResponse modifyResponse = ldapMessageContainer.getMessage();
    assertEquals(1, modifyResponse.getMessageId());
    assertEquals(ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode());
    assertEquals("", modifyResponse.getLdapResult().getMatchedDn().getName());
    assertEquals("", modifyResponse.getLdapResult().getDiagnosticMessage());
    // Check the Control
    Map<String, Control> controls = modifyResponse.getControls();
    assertEquals(1, controls.size());
    @SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
    assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
    assertEquals("", Strings.dumpBytes((byte[]) control.getValue()));
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(modifyResponse);
        // Check the length
        assertEquals(0x2B, 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) ByteBuffer(java.nio.ByteBuffer) DecoderException(org.apache.directory.api.asn1.DecoderException) EncoderException(org.apache.directory.api.asn1.EncoderException) Control(org.apache.directory.api.ldap.model.message.Control) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) ModifyResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CodecControl(org.apache.directory.api.ldap.codec.api.CodecControl) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 30 with ModifyResponse

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

the class ModifyResponseTest method testDecodeModifyResponseSuccess.

/**
 * Test the decoding of a ModifyResponse
 */
@Test
public void testDecodeModifyResponseSuccess() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0E);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x0C, 0x02, 0x01, // messageID MessageID
    0x01, 0x67, // CHOICE { ..., modifyResponse ModifyResponse, ...
    0x07, // ModifyResponse ::= [APPLICATION 7] LDAPResult
    0x0A, 0x01, // LDAPResult ::= SEQUENCE {
    0x00, // },
    0x04, // matchedDN LDAPDN,
    0x00, 0x04, // errorMessage LDAPString,
    0x00 // referral [3] Referral OPTIONAL }
    // }
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<ModifyResponseDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyResponseDecorator>(codec);
    // Decode a ModifyResponse PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    // Check the decoded ModifyResponse PDU
    ModifyResponse modifyResponse = ldapMessageContainer.getMessage();
    assertEquals(1, modifyResponse.getMessageId());
    assertEquals(ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode());
    assertEquals("", modifyResponse.getLdapResult().getMatchedDn().getName());
    assertEquals("", modifyResponse.getLdapResult().getDiagnosticMessage());
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(modifyResponse);
        // Check the length
        assertEquals(0x0E, 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) ModifyResponseDecorator(org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)30 Test (org.junit.Test)17 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)15 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)15 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)13 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)8 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)7 Modification (org.apache.directory.api.ldap.model.entry.Modification)7 Dn (org.apache.directory.api.ldap.model.name.Dn)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)6 Control (org.apache.directory.api.ldap.model.message.Control)5 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 ModifyResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2