Java Code Examples for org.apache.directory.api.ldap.model.message.AddResponse#getMessageId()

The following examples show how to use org.apache.directory.api.ldap.model.message.AddResponse#getMessageId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a valid LdapResult
 */
@Test
public void testDecodeAddResponseEmptyResultCodeOK() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0E );

    stream.put( new byte[]
        {
            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x07,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x00,       // resultCode success
                0x04, 0x00,             // Empty matched Dn
                0x04, 0x00              // Empty errorMessage
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<AddResponse> container = new LdapMessageContainer<>( codec );

    // Decode the AddResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded AddResponse
    AddResponse addResponse = container.getMessage();

    assertEquals( 1, addResponse.getMessageId() );
    assertEquals( ResultCodeEnum.SUCCESS, addResponse.getLdapResult().getResultCode() );
    assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", addResponse.getLdapResult().getDiagnosticMessage() );

    // Check the reverse encoding
    Asn1Buffer buffer = new Asn1Buffer();

    AddResponse response = new AddResponseImpl( addResponse.getMessageId() );
    response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );

    ByteBuffer result = LdapEncoder.encodeMessage( buffer, codec, response );

    assertArrayEquals( stream.array(), result.array() );
}
 
Example 2
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a valid LdapResult with referral
 */
@Test
public void testDecodeAddResponseEmptyResultCodeOKReferral() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x1A );

    stream.put( new byte[]
        {
            0x30, 0x18,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x13,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x0A,       // resultCode success (Referral)
                0x04, 0x00,             // Empty matched Dn
                0x04, 0x00,             // Empty errorMessage
                ( byte ) 0xA3, 0x0A,
                  0x04, 0x08,
                    'l', 'd', 'a', 'p', ':', '/', '/', '/',
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<AddResponse> container = new LdapMessageContainer<>( codec );

    // Decode the AddResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded AddResponse
    AddResponse addResponse = container.getMessage();

    assertEquals( 1, addResponse.getMessageId() );
    assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
    assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", addResponse.getLdapResult().getDiagnosticMessage() );

    Referral referral = addResponse.getLdapResult().getReferral();

    assertNotNull( referral );
    assertEquals( 1, referral.getLdapUrls().size() );
    Collection<String> ldapUrls = referral.getLdapUrls();

    assertTrue( ldapUrls.contains( "ldap:///" ) );

    // Check the reverse encoding
    Asn1Buffer buffer = new Asn1Buffer();

    AddResponse response = new AddResponseImpl( addResponse.getMessageId() );
    Referral referralResult = new ReferralImpl();
    referralResult.addLdapUrl( "ldap:///" );

    response.getLdapResult().setReferral( referralResult );
    response.getLdapResult().setResultCode( ResultCodeEnum.REFERRAL );

    ByteBuffer result = LdapEncoder.encodeMessage( buffer, codec, response );

    assertArrayEquals( stream.array(), result.array() );
}
 
Example 3
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a valid LdapResult with referrals
 */
@Test
public void testDecodeAddResponseEmptyResultCodeOKReferrals() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x24 );

    stream.put( new byte[]
        {
            0x30, 0x22,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x1D,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x0A,       // resultCode success (Referral)
                0x04, 0x00,             // Empty matched Dn
                0x04, 0x00,             // Empty errorMessage
                ( byte ) 0xA3, 0x14,
                  0x04, 0x08,
                    'l', 'd', 'a', 'p', ':', '/', '/', '/',
                  0x04, 0x08,
                    'l', 'd', 'a', 'p', ':', '/', '/', '/',
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<AddResponse> container = new LdapMessageContainer<>( codec );

    // Decode the AddResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded AddResponse
    AddResponse addResponse = container.getMessage();

    assertEquals( 1, addResponse.getMessageId() );
    assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
    assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", addResponse.getLdapResult().getDiagnosticMessage() );

    Referral referral = addResponse.getLdapResult().getReferral();

    assertNotNull( referral );

    assertEquals( 2, referral.getLdapUrls().size() );

    Collection<String> ldapUrls = referral.getLdapUrls();

    for ( String ldapUrl : ldapUrls )
    {
        assertEquals( "ldap:///", ldapUrl );
    }

    // Check the reverse encoding
    Asn1Buffer buffer = new Asn1Buffer();

    AddResponse response = new AddResponseImpl( addResponse.getMessageId() );
    Referral referralResult = new ReferralImpl();
    referralResult.addLdapUrl( "ldap:///" );
    referralResult.addLdapUrl( "ldap:///" );

    response.getLdapResult().setReferral( referralResult );
    response.getLdapResult().setResultCode( ResultCodeEnum.REFERRAL );

    ByteBuffer result = LdapEncoder.encodeMessage( buffer, codec, response );

    assertArrayEquals( stream.array(), result.array() );
}
 
Example 4
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a valid LdapResult with referrals
 * and an empty referral
 */
@Test
public void testDecodeAddResponseEmptyResultCodeEmptyReferral() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x1C );

    stream.put( new byte[]
        {
            0x30, 0x1A,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x15,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x0A,       // resultCode success (Referral)
                0x04, 0x00,             // Empty matched Dn
                0x04, 0x00,             // Empty errorMessage
                ( byte ) 0xA3, 0x0C,
                  0x04, 0x08,
                    'l', 'd', 'a', 'p', ':', '/', '/', '/',
                  0x04, 0x00
        } );

    stream.flip();

    // Allocate a LdapMessage Container
    LdapMessageContainer<AddResponse> container = new LdapMessageContainer<>( codec );

    // Decode the AddResponse PDU
    Asn1Decoder.decode( stream, container );

    // Check the decoded AddResponse
    AddResponse addResponse = container.getMessage();

    assertEquals( 1, addResponse.getMessageId() );
    assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
    assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
    assertEquals( "", addResponse.getLdapResult().getDiagnosticMessage() );

    Referral referral = addResponse.getLdapResult().getReferral();

    assertNotNull( referral );

    assertEquals( 2, referral.getLdapUrls().size() );

    Collection<String> ldapUrls = referral.getLdapUrls();

    String[] expected = new String[]
        { "ldap:///", "" };
    int i = 0;

    for ( String ldapUrl : ldapUrls )
    {
        assertEquals( expected[i], ldapUrl );
        i++;
    }

    // Check the reverse encoding
    Asn1Buffer buffer = new Asn1Buffer();

    AddResponse response = new AddResponseImpl( addResponse.getMessageId() );
    Referral referralResult = new ReferralImpl();
    referralResult.addLdapUrl( "ldap:///" );
    referralResult.addLdapUrl( "" );

    response.getLdapResult().setReferral( referralResult );
    response.getLdapResult().setResultCode( ResultCodeEnum.REFERRAL );

    ByteBuffer result = LdapEncoder.encodeMessage( buffer, codec, response );

    assertArrayEquals( stream.array(), result.array() );
}