Search in sources :

Example 6 with SearchResponse

use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.

the class SearchResponseTest method testResponseWith1SRE1SRR1SRD.

/**
 * Test parsing of a Response with 1 Search Result Entry, 1 Search Result Reference and a Search Result Done
 */
@Test
public void testResponseWith1SRE1SRR1SRD() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResponseTest.class.getResource("response_with_1_SRE_1_SRR_1_SRD.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResponse searchResponse = (SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated();
    assertEquals(1, searchResponse.getSearchResultEntryList().size());
    assertEquals(1, searchResponse.getSearchResultReferenceList().size());
    assertNotNull(searchResponse.getSearchResultDone());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 7 with SearchResponse

use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.

the class SearchResponseTest 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(SearchResponseTest.class.getResource("response_with_requestID_attribute.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResponse searchResponse = (SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated();
    assertEquals(456, searchResponse.getMessageId());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 8 with SearchResponse

use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.

the class SearchResponseTest method testResponseWith1SRE1SRD.

/**
 * Test parsing of a Response with 1 Search Result Entry and a Search Result Done
 */
@Test
public void testResponseWith1SRE1SRD() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResponseTest.class.getResource("response_with_1_SRE_1_SRD.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResponse searchResponse = (SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated();
    assertEquals(1, searchResponse.getSearchResultEntryList().size());
    assertNotNull(searchResponse.getSearchResultDone());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 9 with SearchResponse

use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.

the class SearchResultDoneTest method testResponseWith1Referral.

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

use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.

the class SearchResultDoneTest method testResponseWith1Control.

/**
 * Test parsing of a response with a (optional) Control element
 */
@Test
public void testResponseWith1Control() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultDoneTest.class.getResource("response_with_1_control.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
    Map<String, Control> controls = searchResultDone.getControls();
    assertEquals(1, searchResultDone.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()));
}
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) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) 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

AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)44 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)44 SearchResponse (org.apache.directory.api.dsmlv2.response.SearchResponse)44 Test (org.junit.Test)44 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)21 SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)14 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)13 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)12 Control (org.apache.directory.api.ldap.model.message.Control)12 SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)9 LdapResult (org.apache.directory.api.ldap.model.message.LdapResult)8 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)6 Entry (org.apache.directory.api.ldap.model.entry.Entry)6 Value (org.apache.directory.api.ldap.model.entry.Value)5 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)5 BatchResponseDsml (org.apache.directory.api.dsmlv2.response.BatchResponseDsml)2 SearchResponseDsml (org.apache.directory.api.dsmlv2.response.SearchResponseDsml)2 AddResponseDsml (org.apache.directory.api.dsmlv2.response.AddResponseDsml)1 BindResponseDsml (org.apache.directory.api.dsmlv2.response.BindResponseDsml)1 CompareResponseDsml (org.apache.directory.api.dsmlv2.response.CompareResponseDsml)1