Search in sources :

Example 21 with ModifyResponse

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

the class ModifyResponseTest method testResponseWith2Referrals.

/**
 * Test parsing of a response with 2 Referral elements
 */
@Test
public void testResponseWith2Referrals() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_2_referrals.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = modifyResponse.getLdapResult();
    Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
    assertEquals(2, referrals.size());
    try {
        assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
    try {
        assertTrue(referrals.contains(new LdapUrl("ldap://www.apple.com/").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
}
Also used : 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) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 22 with ModifyResponse

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

the class ModifyResponseTest method testResponseWith2Controls.

/**
 * Test parsing of a response with 2 (optional) Control elements
 */
@Test
public void testResponseWith2Controls() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_2_controls.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    Map<String, Control> controls = modifyResponse.getControls();
    assertEquals(2, modifyResponse.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()));
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 23 with ModifyResponse

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

the class ModifyResponseTest method testResponseWithEmptyErrorMessage.

/**
 * Test parsing of a response with empty Error Message
 */
@Test
public void testResponseWithEmptyErrorMessage() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_empty_error_message.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = modifyResponse.getLdapResult();
    assertNull(ldapResult.getDiagnosticMessage());
}
Also used : 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) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 24 with ModifyResponse

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

the class ModifyResponseTest method testResponseWithErrorMessage.

/**
 * Test parsing of a response with Error Message
 */
@Test
public void testResponseWithErrorMessage() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_error_message.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    LdapResult ldapResult = modifyResponse.getLdapResult();
    assertEquals("Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getDiagnosticMessage());
}
Also used : 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) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 25 with ModifyResponse

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

the class ModifyResponseTest method testResponseWithRequestId.

/**
 * Test parsing of a Response with the (optional) requestID attribute
 */
@Test
public void testResponseWithRequestId() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(ModifyResponseTest.class.getResource("response_with_requestID_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyResponse modifyResponse = (ModifyResponse) parser.getBatchResponse().getCurrentResponse();
    assertEquals(456, modifyResponse.getMessageId());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)30 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 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)8 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)7 Modification (org.apache.directory.api.ldap.model.entry.Modification)7 Dn (org.apache.directory.api.ldap.model.name.Dn)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)6 Control (org.apache.directory.api.ldap.model.message.Control)5 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 ModifyResponseDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyResponseDecorator)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2