Search in sources :

Example 16 with SearchResultReference

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

the class SearchResultReferenceTest method testResponseWith2Ref.

/**
 * Test parsing of a Response with 2 Ref
 */
@Test
public void testResponseWith2Ref() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultReferenceTest.class.getResource("response_with_2_ref.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultReference searchResultReference = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultReference();
    Collection<String> references = searchResultReference.getReferral().getLdapUrls();
    assertEquals(2, references.size());
    try {
        assertTrue(references.contains(new LdapUrl("ldap://localhost").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
    try {
        assertTrue(references.contains(new LdapUrl("ldap://www.apache.org").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) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 17 with SearchResultReference

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

the class SearchResultReferenceTest method testResponseWith1ControlEmptyValue.

/**
 * Test parsing of a response with a (optional) Control element with empty value
 */
@Test
public void testResponseWith1ControlEmptyValue() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultReferenceTest.class.getResource("response_with_1_control_empty_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultReference searchResultReference = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultReference();
    Map<String, Control> controls = searchResultReference.getControls();
    assertEquals(1, searchResultReference.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());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)17 Test (org.junit.Test)11 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)9 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)8 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)8 SearchResponse (org.apache.directory.api.dsmlv2.response.SearchResponse)8 Control (org.apache.directory.api.ldap.model.message.Control)6 DecoderException (org.apache.directory.api.asn1.DecoderException)4 EncoderException (org.apache.directory.api.asn1.EncoderException)4 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 SearchResultReferenceDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator)4 Referral (org.apache.directory.api.ldap.model.message.Referral)4 SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)4 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)4 ByteBuffer (java.nio.ByteBuffer)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)3 HashSet (java.util.HashSet)2