Search in sources :

Example 6 with AddResponseImpl

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

the class AddRequestTest method testDecodeAddRequestNullType.

/**
 * Test the decoding of a AddRequest with a empty attributeList
 */
@Test
public void testDecodeAddRequestNullType() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2F);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x2D, 0x02, 0x01, // messageID MessageID
    0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
    0x28, // entry LDAPDN,
    0x04, 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', // attributes AttributeList }
    0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
    0x04, 0x30, // attribute 1
    0x02, 0x04, // type AttributeDescription,
    0x00 });
    stream.flip();
    // Allocate a LdapMessage Container
    Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode a AddRequest message
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof AddResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((AddResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
    fail("We should not reach this point");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Message(org.apache.directory.api.ldap.model.message.Message) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

AddResponseImpl (org.apache.directory.api.ldap.model.message.AddResponseImpl)6 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ByteBuffer (java.nio.ByteBuffer)3 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 Message (org.apache.directory.api.ldap.model.message.Message)3 Test (org.junit.Test)3 AddRequestDecorator (org.apache.directory.api.ldap.codec.decorators.AddRequestDecorator)2 AddResponseDecorator (org.apache.directory.api.ldap.codec.decorators.AddResponseDecorator)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1