use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWith3ControlsWithoutValue.
/**
* Test parsing of a request with 3 (optional) Control elements without value
*/
@Test
public void testRequestWith3ControlsWithoutValue() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_3_controls_without_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = modifyRequest.getControls();
assertEquals(3, modifyRequest.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.Dsmlv2Parser in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithModificationWithEmptyValue.
/**
* Test parsing of a request with a Modification element with an empty value
* @throws NamingException
*/
@Test
public void testRequestWithModificationWithEmptyValue() throws LdapException {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_with_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Collection<Modification> modifications = modifyRequest.getModifications();
assertEquals(1, modifications.size());
Modification modification = modifications.iterator().next();
assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
Attribute attribute = modification.getAttribute();
assertEquals("directreport", attribute.getId());
assertEquals(1, attribute.size());
assertEquals("", attribute.get().getValue());
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWith2Controls.
/**
* Test parsing of a request with 2 (optional) Control elements
*/
@Test
public void testRequestWith2Controls() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_2_controls.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = modifyRequest.getControls();
assertEquals(2, modifyRequest.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.789");
assertNotNull(control);
assertFalse(control.isCritical());
assertEquals("1.2.840.113556.1.4.789", control.getOid());
assertEquals("Some other text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class ModifyRequestTest method testRequestWithRequestId.
/**
* Test parsing of a request with the (optional) requestID attribute
*/
@Test
public void testRequestWithRequestId() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(ModifyRequestTest.class.getResource("request_with_requestID_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
assertEquals(456, modifyRequest.getMessageId());
}
use of org.apache.directory.api.dsmlv2.Dsmlv2Parser in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith1AbandonRequest.
/**
* Test parsing of a Request with 1 AbandonRequest
*/
@Test
public void testResponseWith1AbandonRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_1_AbandonRequest.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchRequestDsml batchRequest = parser.getBatchRequest();
assertEquals(1, batchRequest.getRequests().size());
if (batchRequest.getCurrentRequest() instanceof AbandonRequest) {
assertTrue(true);
} else {
fail();
}
}
Aggregations