use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.
the class CompareRequestTest method testRequestWith1ControlBase64Value.
/**
* Test parsing of a request with a (optional) Control element with Base64 value
*/
@Test
public void testRequestWith1ControlBase64Value() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(CompareRequestTest.class.getResource("request_with_1_control.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = compareRequest.getControls();
assertEquals(1, compareRequest.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.ldap.model.message.CompareRequest in project directory-ldap-api by apache.
the class CompareRequestTest method testRequestWith1CompleteAssertionBase64Value.
/**
* Test parsing of a request with a complete assertion with base64 value
*/
@Test
public void testRequestWith1CompleteAssertionBase64Value() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(CompareRequestTest.class.getResource("request_with_1_complete_assertion_base64_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
assertTrue(compareRequest.getName().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
assertEquals("sn", compareRequest.getAttributeId());
assertEquals("DSMLv2.0 rocks!!", compareRequest.getAssertionValue().getValue());
}
use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.
the class CompareRequestTest method testRequestWith1ControlEmptyValue.
/**
* Test parsing of a request with a (optional) Control element with empty value
*/
@Test
public void testRequestWith1ControlEmptyValue() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(CompareRequestTest.class.getResource("request_with_1_control_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = compareRequest.getControls();
assertEquals(1, compareRequest.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());
}
use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.
the class CompareRequestTest method testRequestWithRequestId.
/**
* Test parsing of a request with the (optional) requestID attribute
*/
@Test
public void testRequestWithRequestId() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(CompareRequestTest.class.getResource("request_with_requestID_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareRequest compareRequest = (CompareRequest) parser.getBatchRequest().getCurrentRequest();
assertEquals(456, compareRequest.getMessageId());
}
use of org.apache.directory.api.ldap.model.message.CompareRequest in project directory-ldap-api by apache.
the class CompareRequestDsml method toDsml.
/**
* {@inheritDoc}
*/
@Override
public Element toDsml(Element root) {
Element element = super.toDsml(root);
CompareRequest request = getDecorated();
// Dn
if (request.getName() != null) {
element.addAttribute("dn", request.getName().getName());
}
// Assertion
Element assertionElement = element.addElement("assertion");
if (request.getAttributeId() != null) {
assertionElement.addAttribute("name", request.getAttributeId());
}
if (request.getAssertionValue() != null) {
assertionElement.addElement("value").setText(request.getAssertionValue().getValue());
}
return element;
}
Aggregations