org.apache.directory.api.ldap.model.message.AddResponse Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.message.AddResponse. 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 6 votes vote down vote up
/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
}
 
Example #2
Source File: InitAddResponse.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void action( LdapMessageContainer<AddResponse> container ) throws DecoderException
{
    // Now, we can allocate the AddResponse Object
    AddResponse addResponse = new AddResponseImpl( container.getMessageId() );
    container.setMessage( addResponse );

    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();

    int expectedLength = tlv.getLength();

    if ( expectedLength == 0 )
    {
        String msg = I18n.err( I18n.ERR_05146_NULL_ADD_RESPONSE );
        LOG.error( msg );
        throw new DecoderException( msg );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05167_ADD_RESPONSE ) );
    }
}
 
Example #3
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a AddResponse with no LdapResult
 */
@Test
public void testDecodeAddResponseEmptyResult() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0E );

    stream.put( new byte[]
        {
            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x00,               // CHOICE { ..., addResponse AddResponse, ...
        } );

    stream.flip();

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

    // Decode a AddResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #4
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with MatchedDN attribute
 */
@Test
public void testResponseWithMatchedDNAttribute()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    assertTrue( ldapResult.getMatchedDn().equals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM" ) );
}
 
Example #5
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a AddResponse with no LdapResult
 */
@Test
public void testDecodeAddResponseEmptyResultCode() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x10 );

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

    stream.flip();

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

    // Decode a AddResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #6
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a AddResponse with no LdapResult
 */
@Test
public void testDecodeAddResponseEmptyResultCodeAbove90() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0A );

    stream.put( new byte[]
        {
            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x03,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x7F        // resultCode too high
        } );

    stream.flip();

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

    // Decode a AddResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } ); 
}
 
Example #7
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void add( Entry entry ) throws LdapException
{
    if ( entry == null )
    {
        String msg = I18n.err( I18n.ERR_04123_CANNOT_ADD_EMPTY_ENTRY );
        
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( msg );
        }
        
        throw new IllegalArgumentException( msg );
    }

    AddRequest addRequest = new AddRequestImpl();
    addRequest.setEntry( entry );

    AddResponse addResponse = add( addRequest );

    processResponse( addResponse );
}
 
Example #8
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with empty Error Message
 */
@Test
public void testResponseWithEmptyErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    assertNull( ldapResult.getDiagnosticMessage() );
}
 
Example #9
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a response with Error Message
 */
@Test
public void testResponseWithErrorMessage()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
        .getDiagnosticMessage() );
}
 
Example #10
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a AddResponse with no matched Dn
 */
@Test
public void testDecodeAddResponseEmptyResultCodeNoMatchedDN() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0A );

    stream.put( new byte[]
        {
            0x30, 0x08,             // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,     // messageID MessageID
              0x69, 0x03,           // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x00,   // resultCode success
        } );

    stream.flip();

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

    // Decode a AddResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #11
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test the decoding of a AddResponse with no error message
 */
@Test
public void testDecodeAddResponseEmptyResultCodeNoErrorMsg() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0C );

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

    stream.flip();

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

    // Decode a AddResponse message
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #12
Source File: LdapNetworkConnection.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Process the AddResponse received from the server
 * 
 * @param addResponse The AddResponse to process
 * @param addFuture The AddFuture to feed
 * @param responseId The associated request message ID
 * @throws InterruptedException If the Future is interrupted
 */
private void addReceived( AddResponse addResponse, AddFuture addFuture, int responseId ) throws InterruptedException
{
    // remove the listener from the listener map
    if ( LOG.isDebugEnabled() )
    {
        if ( addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
        {
            // Everything is fine, return the response
            LOG.debug( I18n.msg( I18n.MSG_04108_ADD_SUCCESSFUL, addResponse ) );
        }
        else
        {
            // We have had an error
            LOG.debug( I18n.msg( I18n.MSG_04107_ADD_FAILED, addResponse ) );
        }
    }

    // Store the response into the future
    addFuture.set( addResponse );

    // Remove the future from the map
    removeFromFutureMaps( responseId );
}
 
Example #13
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AddResponse add( AddRequest addRequest )
{
    LdapConnection connection = null;
    try
    {
        connection = connectionPool.getConnection();
        return connection.add( addRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    finally
    {
        returnLdapConnection( connection );
    }
}
 
Example #14
Source File: AddResponseTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test parsing of a Response with the (optional) requestID attribute
 */
@Test
public void testResponseWithRequestId()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    assertEquals( 456, addResponse.getMessageId() );
}
 
Example #15
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a AddResponse with all the different result codes
 */
@Test
public void testDecodeAddResponseEmptyResultCodesOK() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x0E );

    byte[] buffer = new byte[]
        {
            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
              0x02, 0x01, 0x01,         // messageID MessageID
              0x69, 0x07,               // CHOICE { ..., addResponse AddResponse, ...
                0x0A, 0x01, 0x00,       // resultCode success
                0x04, 0x00,             // matchedDN LDAPDN,
                0x04, 0x00              // errorMessage LDAPString,
        };

    for ( int i = 0; i < 91; i++ )
    {
        buffer[9] = ( byte ) i;
        stream.put( buffer );
        stream.flip();

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

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

        stream.clear();
    }

    assertTrue( true );
}
 
Example #16
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AddResponse add( Dn dn, RequestBuilder<AddRequest> requestBuilder )
{
    AddRequest addRequest = newAddRequest( newEntry( dn ) );
    try
    {
        requestBuilder.buildRequest( addRequest );
    }
    catch ( LdapException e )
    {
        throw new LdapRuntimeException( e );
    }
    return add( addRequest );
}
 
Example #17
Source File: LdapConnectionTemplate.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AddResponse add( Dn dn, final Attribute... attributes )
{
    return add( dn,
        new RequestBuilder<AddRequest>()
        {
            @Override
            public void buildRequest( AddRequest request ) throws LdapException
            {
                request.getEntry().add( attributes );
            }
        } );
}
 
Example #18
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 1 AddResponse
 */
@Test
public void testResponseWith1AddResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_1_AddResponse.xml" ).openStream(),
            "UTF-8" );

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

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 1, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof AddResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #19
Source File: LdapResultTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test the decoding of a AddResponse with a valid LdapResult and an invalid
 * transition after the referral sequence
 */
@Test
public void testDecodeAddResponseEmptyResultCodeEmptyReferrals() throws DecoderException
{
    ByteBuffer stream = ByteBuffer.allocate( 0x10 );

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

    stream.flip();

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

    // Decode the AddResponse PDU
    assertThrows( DecoderException.class, ( ) ->
    {
        Asn1Decoder.decode( stream, container );
    } );
}
 
Example #20
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param addRequestHandler The AddRequest message received handler
 * @param addResponseHandler The AddResponse message sent handler
 */
public void setAddHandlers( LdapRequestHandler<AddRequest> addRequestHandler,
    LdapResponseHandler<AddResponse> addResponseHandler )
{
    this.handler.removeReceivedMessageHandler( AddRequest.class );
    this.addRequestHandler = addRequestHandler;
    this.addRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( AddRequest.class, this.addRequestHandler );

    this.handler.removeSentMessageHandler( AddResponse.class );
    this.addResponseHandler = addResponseHandler;
    this.addResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( AddResponse.class, this.addResponseHandler );
}
 
Example #21
Source File: LdapServer.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Inject the MessageReceived and MessageSent handler into the IoHandler
 * 
 * @param addRequestHandler The AddRequest message received handler
 * @param addResponseHandler The AddResponse message sent handler
 */
public void setAddHandlers( LdapRequestHandler<AddRequest> addRequestHandler,
    LdapResponseHandler<AddResponse> addResponseHandler )
{
    this.handler.removeReceivedMessageHandler( AddRequest.class );
    this.addRequestHandler = addRequestHandler;
    this.addRequestHandler.setLdapServer( this );
    this.handler.addReceivedMessageHandler( AddRequest.class, this.addRequestHandler );

    this.handler.removeSentMessageHandler( AddResponse.class );
    this.addResponseHandler = addResponseHandler;
    this.addResponseHandler.setLdapServer( this );
    this.handler.addSentMessageHandler( AddResponse.class, this.addResponseHandler );
}
 
Example #22
Source File: ApacheLdapProviderImpl.java    From ldapchai with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void createEntry( final String entryDN, final Set<String> baseObjectClasses, final Map<String, String> stringAttributes )
        throws ChaiOperationException, ChaiUnavailableException, IllegalStateException
{
    activityPreCheck();
    getInputValidator().createEntry( entryDN, baseObjectClasses, stringAttributes );

    try
    {
        final AddRequest addRequest = new AddRequestImpl();
        final Entry entry = new DefaultEntry();
        entry.setDn( entryDN );
        for ( final String baseObjectClass : baseObjectClasses )
        {
            entry.add( ChaiConstant.ATTR_LDAP_OBJECTCLASS, baseObjectClass );
        }

        for ( final Map.Entry<String, String> entryIter : stringAttributes.entrySet() )
        {
            final String name = entryIter.getKey();
            final String value = entryIter.getValue();
            entry.add( name, value );
        }

        final AddResponse response = connection.add( addRequest );
        processResponse( response );
    }
    catch ( LdapException e )
    {
        throw ChaiOperationException.forErrorMessage( e.getMessage() );
    }
}
 
Example #23
Source File: BatchResponseTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test parsing of a Response with the 2 AddResponse
 */
@Test
public void testResponseWith2AddResponse()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

        parser.setInput( BatchResponseTest.class.getResource( "response_with_2_AddResponse.xml" ).openStream(),
            "UTF-8" );

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

    BatchResponseDsml batchResponse = parser.getBatchResponse();

    assertEquals( 2, batchResponse.getResponses().size() );

    DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();

    if ( response instanceof AddResponse )
    {
        assertTrue( true );
    }
    else
    {
        fail();
    }
}
 
Example #24
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 #25
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 #26
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 Referral elements
 */
@Test
public void testResponseWith2Referrals()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();

    assertEquals( 2, referrals.size() );

    assertTrue( referrals.contains( "ldap://www.apache.org/" ) );
    assertTrue( referrals.contains( "ldap://www.apple.com/" ) );
}
 
Example #27
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 an empty Referral
 */
@Test
public void testResponseWith1EmptyReferral()
{
    Dsmlv2ResponseParser parser = null;
    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();

    assertEquals( 0, referrals.size() );
}
 
Example #28
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 Referral
 */
@Test
public void testResponseWith1Referral()
{
    Dsmlv2ResponseParser parser = null;

    try
    {
        parser = new Dsmlv2ResponseParser( getCodec() );

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

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

    AddResponse addResponse = ( AddResponse ) parser.getBatchResponse().getCurrentResponse();

    LdapResult ldapResult = addResponse.getLdapResult();

    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();

    assertEquals( 1, referrals.size() );

    assertTrue( referrals.contains( "ldap://www.apache.org/" ) );
}
 
Example #29
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 #30
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() ) );
}