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

The following examples show how to use org.apache.directory.api.ldap.model.message.AddResponse#getControls() . 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: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AddResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 1, addResponse.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() ) );
}
 
Example 2
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with a (optional) Control element with emptyValue
 */
@Test
public void testResponseWith1ControlEmptyValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AddResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 1, addResponse.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() );
}
 
Example 3
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 2 (optional) Control elements
 */
@Test
public void testResponseWith2Controls()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AddResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 2, addResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.789" );

    assertNotNull( control );
    assertFalse( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.789", control.getOid() );
    assertEquals( "Some other text", Strings.utf8ToString( ( ( DsmlControl<?> ) control ).getValue() ) );
}
 
Example 4
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a response with 3 (optional) Control elements without value
 */
@Test
public void testResponseWith3ControlsWithoutValue()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( AddResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
            .openStream(), "UTF-8" );

        parser.parse();
    }
    catch ( Exception e )
    {
        fail( e.getMessage() );
    }

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 3, addResponse.getControls().size() );

    Control control = controls.get( "1.2.840.113556.1.4.456" );

    assertNotNull( control );
    assertTrue( control.isCritical() );
    assertEquals( "1.2.840.113556.1.4.456", control.getOid() );
    assertFalse( ( ( DsmlControl<?> ) control ).hasValue() );
}
 
Example 5
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a control
 */
@Test
public void testDecodeAddResponseSuccessWithControl() throws DecoderException, EncoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x32 );

    stream.put( new byte[]
        {
            0x30, 0x30,                     // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,             // messageID MessageID
              0x69, 0x07,                   // CHOICE { ..., addResponse AddResponse, ...
                                            // AddResponse ::= [APPLICATION 9] LDAPResult
                0x0A, 0x01, 0x00,           // LDAPResult ::= SEQUENCE {
                                            // resultCode ENUMERATED {
                                            // success (0), ...
                                            // },
                0x04, 0x00,                 // matchedDN LDAPDN,
                0x04, 0x00,                 // errorMessage LDAPString,
                                            // referral [3] Referral OPTIONAL }
                                            // }
              ( byte ) 0xA0, 0x22,          // A control
                0x30, 0x20,
                  0x04, 0x17,               // EntryChange response control
                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '7',
                  0x04, 0x05,               // Control value
                    0x30, 0x03,             // EntryChangeNotification ::= SEQUENCE {
                      0x0A, 0x01, 0x01      //     changeType ENUMERATED {
                                            //         add             (1),
        } );

    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 Control
    Map<String, Control> controls = addResponse.getControls();

    assertEquals( 1, controls.size() );

    Control control = controls.get( "2.16.840.1.113730.3.4.7" );
    assertEquals( "2.16.840.1.113730.3.4.7", control.getOid() );
    assertTrue( control instanceof EntryChange );

    // Check encode reverse
    Asn1Buffer buffer = new Asn1Buffer();

    LdapEncoder.encodeMessage( buffer, codec, addResponse );

    assertArrayEquals( stream.array(), buffer.getBytes().array() );
}