use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class IntermediateResponseProtocolOpTestCase method testIntermediateResponseProtocolOpWithOIDWithoutValue.
/**
* Provides test coverage for the intermediate response protocol op with an
* OID but no value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIntermediateResponseProtocolOpWithOIDWithoutValue() throws Exception {
IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp("1.2.3.4", null);
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new IntermediateResponseProtocolOp(reader);
op = IntermediateResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new IntermediateResponseProtocolOp(op.toIntermediateResponse());
assertNotNull(op.getOID());
assertEquals(op.getOID(), "1.2.3.4");
assertNull(op.getValue());
assertEquals(op.getProtocolOpType(), (byte) 0x79);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class IntermediateResponseProtocolOpTestCase method testIntermediateResponseProtocolOpWithoutOIDWithValue.
/**
* Provides test coverage for the intermediate response protocol op with a
* value but no OID.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testIntermediateResponseProtocolOpWithoutOIDWithValue() throws Exception {
IntermediateResponseProtocolOp op = new IntermediateResponseProtocolOp(null, new ASN1OctetString());
ASN1Buffer buffer = new ASN1Buffer();
op.writeTo(buffer);
byte[] opBytes = buffer.toByteArray();
ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
op = new IntermediateResponseProtocolOp(reader);
op = IntermediateResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
op = new IntermediateResponseProtocolOp(op.toIntermediateResponse());
assertNull(op.getOID());
assertNotNull(op.getValue());
assertEquals(op.getValue().getValue().length, 0);
assertEquals(op.getProtocolOpType(), (byte) 0x79);
assertNotNull(op.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testReadFromInvalidProtocolOpType.
/**
* Tests the {@code LDAPMessage.readFrom} method with invalid protocol op
* type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testReadFromInvalidProtocolOpType() throws Exception {
ASN1Buffer b = new ASN1Buffer();
ASN1BufferSequence s = b.beginSequence();
b.addInteger(1);
b.addOctetString();
s.end();
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
LDAPMessage.readFrom(reader, true);
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testDeleteRequestMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a delete request
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDeleteRequestMessage() throws Exception {
DeleteRequestProtocolOp op = new DeleteRequestProtocolOp("dc=example,dc=com");
LDAPMessage m = new LDAPMessage(1, op);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof DeleteRequestProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getDeleteRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testModifyResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a modify response
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyResponseMessage() throws Exception {
LinkedList<String> refs = new LinkedList<String>();
refs.add("ldap://server1.example.com:389/dc=example,dc=com");
refs.add("ldap://server2.example.com:389/dc=example,dc=com");
LinkedList<Control> controls = new LinkedList<Control>();
controls.add(new Control("1.2.3.4"));
controls.add(new Control("1.2.3.5", true, new ASN1OctetString()));
ModifyResponseProtocolOp op = new ModifyResponseProtocolOp(0, null, null, refs);
LDAPMessage m = new LDAPMessage(1, op, controls);
ASN1Buffer b = new ASN1Buffer();
m.writeTo(b);
ByteArrayInputStream inputStream = new ByteArrayInputStream(b.toByteArray());
ASN1StreamReader reader = new ASN1StreamReader(inputStream);
m = LDAPMessage.readFrom(reader, true);
m = LDAPMessage.decode(m.encode());
assertEquals(m.getMessageID(), 1);
assertNotNull(m.getProtocolOp());
assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getModifyResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
Aggregations