use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest method testDecodeDelRequestSuccess.
/**
* Test the decoding of a full DelRequest
*/
@Test
public void testDecodeDelRequestSuccess() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x27);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x25, 0x02, 0x01, // messageID MessageID
0x01, // DelRequest ::= [APPLICATION 10] LDAPDN;
0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<DeleteRequestDecorator> container = new LdapMessageContainer<DeleteRequestDecorator>(codec);
// Decode a DelRequest PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded DelRequest PDU
DeleteRequest delRequest = container.getMessage();
assertEquals(1, delRequest.getMessageId());
assertEquals("cn=testModify,ou=users,ou=system", delRequest.getName().toString());
// Check the length
DeleteRequest internalDeleteRequest = new DeleteRequestImpl();
internalDeleteRequest.setMessageId(delRequest.getMessageId());
internalDeleteRequest.setName(delRequest.getName());
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(internalDeleteRequest);
// Check the length
assertEquals(0x27, bb.limit());
String encodedPdu = Strings.dumpBytes(bb.array());
assertEquals(encodedPdu, decodedPdu);
} catch (EncoderException ee) {
ee.printStackTrace();
fail(ee.getMessage());
}
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith2DelRequest.
/**
* Test parsing of a Request with 2 DelRequest
*/
@Test
public void testResponseWith2DelRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_2_DelRequest.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchRequestDsml batchRequest = parser.getBatchRequest();
assertEquals(2, batchRequest.getRequests().size());
if (batchRequest.getCurrentRequest() instanceof DeleteRequest) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class BatchRequestTest method testResponseWith1DelRequest.
/**
* Test parsing of a Request with 1 DelRequest
*/
@Test
public void testResponseWith1DelRequest() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(BatchRequestTest.class.getResource("request_with_1_DelRequest.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 DeleteRequest) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest 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(DelRequestTest.class.getResource("request_with_1_control_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = delRequest.getControls();
assertEquals(1, delRequest.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.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest method testRequestWithRequestId.
/**
* Test parsing of a request with the (optional) requestID attribute
*/
@Test
public void testRequestWithRequestId() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(DelRequestTest.class.getResource("request_with_requestID_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
assertEquals(456, delRequest.getMessageId());
}
Aggregations