use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithSubstrings1Initial1Any.
/**
* Test parsing of a request with a Substrings Filter with 1 Initial and 1 Any elements
*/
@Test
public void testRequestWithSubstrings1Initial1Any() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_initial_1_any.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof SubstringNode);
SubstringNode substringFilter = (SubstringNode) filter;
assertEquals("jack", substringFilter.getInitial());
List<String> initials = substringFilter.getAny();
assertEquals(1, initials.size());
assertEquals("kate", initials.get(0).toString());
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithAttributesButNoAttribute.
/**
* Test parsing of a request with Attibutes Element but not any Attribute element
*/
@Test
public void testRequestWithAttributesButNoAttribute() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("request_with_attributes_but_no_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
assertTrue(true);
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWith1Control.
/**
* Test parsing of a request with a (optional) Control element
*/
@Test
public void testRequestWith1Control() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("request_with_1_control.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = searchRequest.getControls();
assertEquals(1, searchRequest.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()));
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithApproxMatchFilterBase64Value.
/**
* Test parsing of a request with an approxMatch Filter with base64 value
*/
@Test
public void testRequestWithApproxMatchFilterBase64Value() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_approxMatch_base64_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof ApproximateNode);
ApproximateNode<?> approxMatchFilter = (ApproximateNode<?>) filter;
assertEquals("sn", approxMatchFilter.getAttribute());
assertEquals("DSMLv2.0 rocks!!", approxMatchFilter.getValue().getValue());
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class SearchRequestTest method testRequestWithGreaterOrEqualFilterEmptyValue.
/**
* Test parsing of a request with an greaterOrEqual Filter with an empty value
*/
@Test
public void testRequestWithGreaterOrEqualFilterEmptyValue() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(SearchRequestTest.class.getResource("filters/request_with_greaterOrEqual_with_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
ExprNode filter = searchRequest.getFilter();
assertTrue(filter instanceof GreaterEqNode);
GreaterEqNode<?> greaterEqFilter = (GreaterEqNode<?>) filter;
assertEquals("sn", greaterEqFilter.getAttribute());
assertEquals("", greaterEqFilter.getValue().getValue());
}
Aggregations