use of org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse in project directory-ldap-api by apache.
the class EndTransactionResponseTest method testEndTransactionResponseMessageId.
/**
* Test the decoding of a EndTransactionResponse with a messageId and no updateControls
*/
@Test
public void testEndTransactionResponseMessageId() throws DecoderException, EncoderException {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0x05);
bb.put(new byte[] { // EndTransactionResponse ::= SEQUENCE {
0x30, // EndTransactionResponse ::= SEQUENCE {
0x03, // MessageId
0x02, // MessageId
0x01, // MessageId
0x04 });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
EndTransactionResponseContainer container = new EndTransactionResponseContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
EndTransactionResponse endTransactionResponse = container.getEndTransactionResponse();
assertEquals(4, endTransactionResponse.getFailedMessageId());
assertEquals(0, endTransactionResponse.getUpdateControls().size());
// Check the length
assertEquals(0x05, ((EndTransactionResponseDecorator) endTransactionResponse).computeLengthInternal());
// Check the encoding
ByteBuffer bb1 = ((EndTransactionResponseDecorator) endTransactionResponse).encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
}
use of org.apache.directory.api.ldap.extras.extended.endTransaction.EndTransactionResponse in project directory-ldap-api by apache.
the class EndTransactionResponseTest method testEndTransactionResponseUpdateControls.
/**
* Test the decoding of a EndTransactionResponse with updateControls
*/
@Test
public void testEndTransactionResponseUpdateControls() throws DecoderException, EncoderException {
Asn1Decoder decoder = new Asn1Decoder();
ByteBuffer bb = ByteBuffer.allocate(0xAC);
bb.put(new byte[] { // EndTransactionResponse ::= SEQUENCE {
0x30, // EndTransactionResponse ::= SEQUENCE {
(byte) 0x81, // EndTransactionResponse ::= SEQUENCE {
(byte) 0xA9, // UpdateControls
0x30, // UpdateControls
(byte) 0x81, // UpdateControls
(byte) 0xA6, // updateControl
0x30, // updateControl
0x5F, // messageID
0x02, // messageID
0x01, // messageID
0x01, // controls
0x30, // controls
0x5A, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x1A, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1', // criticality BOOLEAN DEFAULT FALSE,
0x01, // criticality BOOLEAN DEFAULT FALSE,
0x01, // criticality BOOLEAN DEFAULT FALSE,
(byte) 0xFF, // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'a', 'b', 'c', 'd', 'e', 'f', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x17, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'g', 'h', 'i', 'j', 'k', 'l', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x12, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3', // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
(byte) 0xFF, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x0F, // controlType LDAPOID}
0x04, // controlType LDAPOID}
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4', // updateControl
0x30, // updateControl
0x43, // messageID
0x02, // messageID
0x01, // messageID
0x02, // controls
0x30, // controls
0x3E, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x17, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', // controlValue OCTET STRING OPTIONAL }
0x04, // controlValue OCTET STRING OPTIONAL }
0x06, 'g', 'h', 'i', 'j', 'k', 'l', // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x12, // controlType LDAPOID,
0x04, // controlType LDAPOID,
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3', // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
0x01, // criticality BOOLEAN DEFAULT FALSE}
(byte) 0xFF, // Control ::= SEQUENCE {
0x30, // Control ::= SEQUENCE {
0x0F, // controlType LDAPOID}
0x04, // controlType LDAPOID}
0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' });
String decodedPdu = Strings.dumpBytes(bb.array());
bb.flip();
EndTransactionResponseContainer container = new EndTransactionResponseContainer();
try {
decoder.decode(bb, container);
} catch (DecoderException de) {
de.printStackTrace();
fail(de.getMessage());
}
EndTransactionResponse endTransactionResponse = container.getEndTransactionResponse();
assertEquals(-1, endTransactionResponse.getFailedMessageId());
assertEquals(2, endTransactionResponse.getUpdateControls().size());
UpdateControls updateControls1 = endTransactionResponse.getUpdateControls().get(0);
assertEquals(1, updateControls1.getMessageId());
assertNotNull(updateControls1.getControls());
assertEquals(4, updateControls1.getControls().size());
for (Control control : updateControls1.getControls()) {
switch(control.getOid()) {
case "1.3.6.1.5.5.1":
assertTrue(control.isCritical());
assertEquals("abcdef", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.2":
assertFalse(control.isCritical());
assertEquals("ghijkl", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.3":
assertTrue(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
case "1.3.6.1.5.5.4":
assertFalse(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
default:
fail();
break;
}
}
UpdateControls updateControls2 = endTransactionResponse.getUpdateControls().get(1);
assertEquals(2, updateControls2.getMessageId());
assertNotNull(updateControls2.getControls());
assertEquals(3, updateControls2.getControls().size());
for (Control control : updateControls2.getControls()) {
switch(control.getOid()) {
case "1.3.6.1.5.5.2":
assertFalse(control.isCritical());
assertEquals("ghijkl", Strings.utf8ToString(((CodecControl<?>) control).getValue()));
break;
case "1.3.6.1.5.5.3":
assertTrue(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
case "1.3.6.1.5.5.4":
assertFalse(control.isCritical());
assertNull(((CodecControl<?>) control).getValue());
break;
default:
fail();
break;
}
}
// Check the length
assertEquals(0xAC, ((EndTransactionResponseDecorator) endTransactionResponse).computeLengthInternal());
// Check the encoding
ByteBuffer bb1 = ((EndTransactionResponseDecorator) endTransactionResponse).encodeInternal();
String encodedPdu = Strings.dumpBytes(bb1.array());
assertEquals(encodedPdu, decodedPdu);
}
Aggregations