Search in sources :

Example 46 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.

the class CompareResponseProtocolOpTestCase method testCompareResponseProtocolOpFailure.

/**
 * Provides test coverage for the compare response protocol op for a failure
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareResponseProtocolOpFailure() 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");
    CompareResponseProtocolOp op = new CompareResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new CompareResponseProtocolOp(reader);
    op = CompareResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new CompareResponseProtocolOp(op.toLDAPResult());
    assertEquals(op.getResultCode(), 32);
    assertNotNull(op.getMatchedDN());
    assertEquals(new DN(op.getMatchedDN()), new DN("dc=example,dc=com"));
    assertNotNull(op.getDiagnosticMessage());
    assertEquals(op.getDiagnosticMessage(), "The parent entry did not exist");
    assertNotNull(op.getReferralURLs());
    assertFalse(op.getReferralURLs().isEmpty());
    assertEquals(op.getReferralURLs().size(), 2);
    assertEquals(op.getProtocolOpType(), (byte) 0x6F);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 47 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.

the class CompareResponseProtocolOpTestCase method testCompareResponseProtocolOpSuccess.

/**
 * Provides test coverage for the compare response protocol op for a success
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testCompareResponseProtocolOpSuccess() throws Exception {
    CompareResponseProtocolOp op = new CompareResponseProtocolOp(6, null, null, null);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new CompareResponseProtocolOp(reader);
    op = CompareResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new CompareResponseProtocolOp(op.toLDAPResult());
    assertEquals(op.getResultCode(), 6);
    assertNull(op.getMatchedDN());
    assertNull(op.getDiagnosticMessage());
    assertNotNull(op.getReferralURLs());
    assertTrue(op.getReferralURLs().isEmpty());
    assertEquals(op.getProtocolOpType(), (byte) 0x6F);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 48 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.

the class DeleteRequestProtocolOpTestCase method testDeleteRequestProtocolOp.

/**
 * Provides test coverage for the delete request protocol op.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDeleteRequestProtocolOp() throws Exception {
    DeleteRequestProtocolOp op = new DeleteRequestProtocolOp("dc=example,dc=com");
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new DeleteRequestProtocolOp(reader);
    op = DeleteRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new DeleteRequestProtocolOp(op.toDeleteRequest());
    assertEquals(new DN(op.getDN()), new DN("dc=example,dc=com"));
    assertEquals(op.getProtocolOpType(), (byte) 0x4A);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 49 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.

the class DeleteResponseProtocolOpTestCase method testDeleteResponseProtocolOpFailure.

/**
 * Provides test coverage for the delete response protocol op for a failure
 * response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDeleteResponseProtocolOpFailure() 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");
    DeleteResponseProtocolOp op = new DeleteResponseProtocolOp(32, "dc=example,dc=com", "The parent entry did not exist", refs);
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new DeleteResponseProtocolOp(reader);
    op = DeleteResponseProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new DeleteResponseProtocolOp(op.toLDAPResult());
    assertEquals(op.getResultCode(), 32);
    assertNotNull(op.getMatchedDN());
    assertEquals(new DN(op.getMatchedDN()), new DN("dc=example,dc=com"));
    assertNotNull(op.getDiagnosticMessage());
    assertEquals(op.getDiagnosticMessage(), "The parent entry did not exist");
    assertNotNull(op.getReferralURLs());
    assertFalse(op.getReferralURLs().isEmpty());
    assertEquals(op.getReferralURLs().size(), 2);
    assertEquals(op.getProtocolOpType(), (byte) 0x6B);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) DN(com.unboundid.ldap.sdk.DN) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 50 with ASN1StreamReader

use of com.unboundid.asn1.ASN1StreamReader in project ldapsdk by pingidentity.

the class ExtendedRequestProtocolOpTestCase method testExtendedRequestProtocolOpWithOIDWithoutValue.

/**
 * Provides test coverage for the extended request protocol op with an OID but
 * no value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedRequestProtocolOpWithOIDWithoutValue() throws Exception {
    ExtendedRequestProtocolOp op = new ExtendedRequestProtocolOp("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 ExtendedRequestProtocolOp(reader);
    op = ExtendedRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new ExtendedRequestProtocolOp(op.toExtendedRequest());
    assertNotNull(op.getOID());
    assertEquals(op.getOID(), "1.2.3.4");
    assertNull(op.getValue());
    assertEquals(op.getProtocolOpType(), (byte) 0x77);
    assertNotNull(op.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Aggregations

ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)121 ByteArrayInputStream (java.io.ByteArrayInputStream)114 Test (org.testng.annotations.Test)114 ASN1Buffer (com.unboundid.asn1.ASN1Buffer)91 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)31 LinkedList (java.util.LinkedList)28 ASN1BufferSequence (com.unboundid.asn1.ASN1BufferSequence)22 DN (com.unboundid.ldap.sdk.DN)21 Control (com.unboundid.ldap.sdk.Control)18 NotNull (com.unboundid.util.NotNull)13 ASN1StreamReaderSequence (com.unboundid.asn1.ASN1StreamReaderSequence)11 ArrayList (java.util.ArrayList)10 ASN1Exception (com.unboundid.asn1.ASN1Exception)8 IOException (java.io.IOException)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 InterruptedIOException (java.io.InterruptedIOException)5 SocketTimeoutException (java.net.SocketTimeoutException)5 Attribute (com.unboundid.ldap.sdk.Attribute)4 SSLSocket (javax.net.ssl.SSLSocket)4 ASN1Element (com.unboundid.asn1.ASN1Element)3