use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testCompareRequestMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a compare request
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompareRequestMessage() throws Exception {
CompareRequestProtocolOp op = new CompareRequestProtocolOp("dc=example,dc=com", "dc", new ASN1OctetString("example"));
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 CompareRequestProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getCompareRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testModifyDNRequestMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a modify DN
* request protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyDNRequestMessage() throws Exception {
ModifyDNRequestProtocolOp op = new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null);
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 ModifyDNRequestProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getModifyDNRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testConstructorNullControlArray.
/**
* Tests the constructor which takes an array of controls with a {@code null}
* array.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorNullControlArray() throws Exception {
LDAPMessage m = new LDAPMessage(1, new UnbindRequestProtocolOp(), (Control[]) null);
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 UnbindRequestProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getUnbindRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testConstructorEmptyControlList.
/**
* Tests the constructor which takes a list of controls with an empty list.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorEmptyControlList() throws Exception {
LinkedList<Control> controlList = new LinkedList<Control>();
LDAPMessage m = new LDAPMessage(1, new UnbindRequestProtocolOp(), controlList);
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 UnbindRequestProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
assertNotNull(m.getUnbindRequestProtocolOp());
assertNotNull(m.toString());
}
use of com.unboundid.asn1.ASN1Buffer in project ldapsdk by pingidentity.
the class LDAPMessageTestCase method testBindResponseMessage.
/**
* Tests the behavior of the {@code LDAPMessage} class with a bind response
* protocol op.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBindResponseMessage() 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()));
BindResponseProtocolOp op = new BindResponseProtocolOp(0, null, null, refs, new ASN1OctetString());
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 BindResponseProtocolOp);
assertEquals(m.getProtocolOpType(), LDAPMessage.PROTOCOL_OP_TYPE_BIND_RESPONSE);
assertNotNull(m.getControls());
assertFalse(m.getControls().isEmpty());
assertNotNull(m.getBindResponseProtocolOp());
inputStream = new ByteArrayInputStream(b.toByteArray());
reader = new ASN1StreamReader(inputStream);
LDAPResponse r = LDAPMessage.readLDAPResponseFrom(reader, true);
assertNotNull(m.toString());
}
Aggregations