use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class SearchResultReferenceTest method testResponseWith1EmptyRef.
/**
* Test parsing of a Response with 1 Ref
*/
@Test
public void testResponseWith1EmptyRef() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultReferenceTest.class.getResource("response_with_1_empty_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(0, references.size());
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class SearchResultReferenceTest method testResponseWith3ControlsWithoutValue.
/**
* 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(SearchResultReferenceTest.class.getResource("response_with_3_controls_without_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(3, searchResultReference.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());
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse in project directory-ldap-api by apache.
the class SearchResultReferenceTest method testResponseWith1Ref.
/**
* Test parsing of a Response with 1 Ref
*/
@Test
public void testResponseWith1Ref() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultReferenceTest.class.getResource("response_with_1_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(1, references.size());
try {
assertTrue(references.contains(new LdapUrl("ldap://localhost").toString()));
} catch (LdapURLEncodingException e) {
fail();
}
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse 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();
}
}
use of org.apache.directory.api.dsmlv2.response.SearchResponse 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());
}
Aggregations