Search in sources :

Example 16 with CompareResponse

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

the class BatchResponseTest method testResponseWith1CompareResponse.

/**
 * Test parsing of a Response with the 1 CompareResponse
 */
@Test
public void testResponseWith1CompareResponse() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(BatchResponseTest.class.getResource("response_with_1_CompareResponse.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 CompareResponse) {
        assertTrue(true);
    } else {
        fail();
    }
}
Also used : BatchResponseDsml(org.apache.directory.api.dsmlv2.response.BatchResponseDsml) CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 17 with CompareResponse

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

the class CompareResponseTest method testResponseWith1Referral.

/**
 * Test parsing of a response with a Referral
 */
@Test
public void testResponseWith1Referral() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(CompareResponseTest.class.getResource("response_with_1_referral.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = compareResponse.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 : CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) 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) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 18 with CompareResponse

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

the class CompareResponseTest method testResponseWith1ReferralAndAnErrorMessage.

/**
 * Test parsing of a response with a Referral and an Error Message
 */
@Test
public void testResponseWith1ReferralAndAnErrorMessage() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(CompareResponseTest.class.getResource("response_with_1_referral_and_error_message.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = compareResponse.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 : CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) 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) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 19 with CompareResponse

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

the class CompareResponseTest method testResponseWithMatchedDNAttribute.

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

Example 20 with CompareResponse

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

the class CompareResponseTest method testResponseWithResultCode.

/**
 * Test parsing of a response with Result Code
 */
@Test
public void testResponseWithResultCode() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(CompareResponseTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = compareResponse.getLdapResult();
    assertEquals(ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode());
}
Also used : CompareResponse(org.apache.directory.api.ldap.model.message.CompareResponse) 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) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

CompareResponse (org.apache.directory.api.ldap.model.message.CompareResponse)25 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 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 Control (org.apache.directory.api.ldap.model.message.Control)6 CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)5 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 CompareRequestImpl (org.apache.directory.api.ldap.model.message.CompareRequestImpl)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 CompareResponseDecorator (org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 BatchResponseDsml (org.apache.directory.api.dsmlv2.response.BatchResponseDsml)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 AddResponse (org.apache.directory.api.ldap.model.message.AddResponse)2 BindResponse (org.apache.directory.api.ldap.model.message.BindResponse)2