use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testDecodeExtendedRequestNoNameWithControls.
/**
* Test the decoding of a ExtendedRequest with no name and a control
*/
@Test
public void testDecodeExtendedRequestNoNameWithControls() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2B);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x29, 0x02, 0x01, // messageID MessageID
0x01, // CHOICE { ..., extendedResp Response, ...
0x78, // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
0x07, // COMPONENTS OF LDAPResult,
0x0A, 0x01, // LDAPResult ::= SEQUENCE {
0x00, // },
0x04, // matchedDN LDAPDN,
0x00, 0x04, // errorMessage LDAPString,
0x00, // responseName [0] LDAPOID,
(byte) 0xA0, // A control
0x1B, 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 });
String decodedPdu = Strings.dumpBytes(stream.array());
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<ExtendedResponseDecorator<?>> container = new LdapMessageContainer<ExtendedResponseDecorator<?>>(codec);
// Decode the ExtendedResponse PDU
try {
ldapDecoder.decode(stream, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
// Check the decoded ExtendedResponse PDU
ExtendedResponse extendedResponse = container.getMessage();
assertEquals(1, extendedResponse.getMessageId());
assertEquals(ResultCodeEnum.SUCCESS, extendedResponse.getLdapResult().getResultCode());
assertEquals("", extendedResponse.getLdapResult().getMatchedDn().getName());
assertEquals("", extendedResponse.getLdapResult().getDiagnosticMessage());
// Check the Control
Map<String, Control> controls = extendedResponse.getControls();
assertEquals(1, controls.size());
@SuppressWarnings("unchecked") CodecControl<Control> control = (org.apache.directory.api.ldap.codec.api.CodecControl<Control>) controls.get("2.16.840.1.113730.3.4.2");
assertEquals("2.16.840.1.113730.3.4.2", control.getOid());
assertEquals("", Strings.dumpBytes(control.getValue()));
// Check the encoding
try {
ByteBuffer bb = encoder.encodeMessage(extendedResponse);
// Check the length
assertEquals(0x2B, 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.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest 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(ExtendedResponseTest.class.getResource("response_with_1_control_empty_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
Map<String, Control> controls = extendedResponse.getControls();
assertEquals(1, extendedResponse.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.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testResponseWith2Controls.
/**
* Test parsing of a response with 2 (optional) Control elements
*/
@Test
public void testResponseWith2Controls() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ExtendedResponseTest.class.getResource("response_with_2_controls.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
Map<String, Control> controls = extendedResponse.getControls();
assertEquals(2, extendedResponse.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.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testResponseWithResponseName.
/**
* Test parsing of a response with Response Name
*/
@Test
public void testResponseWithResponseName() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ExtendedResponseTest.class.getResource("response_with_responseName.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
try {
assertEquals(Oid.fromString("1.2.3.4.5.6.7.8.9.0").toString(), extendedResponse.getResponseName().toString());
} catch (DecoderException e) {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testResponseWithErrorMessage.
/**
* Test parsing of a response with Error Message
*/
@Test
public void testResponseWithErrorMessage() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ExtendedResponseTest.class.getResource("response_with_error_message.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = extendedResponse.getLdapResult();
assertEquals("Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getDiagnosticMessage());
}
Aggregations