From a64a7b0ec18dcd771507d4acd85625274aa59b21 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 18 Feb 2009 19:57:56 +0000
Subject: [PATCH] Fix for issue 3803

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java |   40 +++++++++++++++++++++++++++++++++++++++-
 opendj-sdk/opends/src/server/org/opends/server/controls/VLVResponseControl.java                         |    4 ++--
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/controls/VLVResponseControl.java b/opendj-sdk/opends/src/server/org/opends/server/controls/VLVResponseControl.java
index 8256b92..523708c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/controls/VLVResponseControl.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/controls/VLVResponseControl.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.controls;
 import org.opends.messages.Message;
@@ -248,7 +248,7 @@
     writer.writeStartSequence();
     writer.writeInteger(targetPosition);
     writer.writeInteger(contentCount);
-    writer.writeInteger(vlvResultCode);
+    writer.writeEnumerated(vlvResultCode);
     if (contextID != null)
     {
       writer.writeOctetString(contextID);
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
index e48897d..011483a 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.controls;
 
@@ -44,6 +44,10 @@
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.ldap.LDAPResultCode;
 import org.opends.server.protocols.ldap.LDAPControl;
+import org.opends.server.protocols.asn1.ASN1Writer;
+import org.opends.server.protocols.asn1.ASN1;
+import org.opends.server.protocols.asn1.ASN1Reader;
+import org.opends.server.protocols.asn1.ASN1Constants;
 import org.opends.server.types.*;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -383,7 +387,41 @@
     assertNotNull(vlvRequest.toString());
   }
 
+  /**
+   * Tests the ASN.1 encoding for the response control.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testASN1ValueEncoding()
+         throws Exception
+  {
+    ByteStringBuilder builder = new ByteStringBuilder();
+    ASN1Writer writer = ASN1.getWriter(builder);
+    VLVResponseControl vlvResponse = new VLVResponseControl(true, 0, 15, 0,
+        ByteString.valueOf("foo"));
+    vlvResponse.writeValue(writer);
 
+    ASN1Reader reader = ASN1.getReader(builder.toByteString());
+    // Should start as an octet string with a nested sequence
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
+    reader.readStartSequence();
+    // Should be an sequence start
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_SEQUENCE_TYPE);
+    reader.readStartSequence();
+    // Should be an integer with targetPosition
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
+    assertEquals(reader.readInteger(), 0);
+    // Should be an integer with contentCount
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_INTEGER_TYPE);
+    assertEquals(reader.readInteger(), 15);
+    // Should be an enumerated with virtualListViewResult
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_ENUMERATED_TYPE);
+    assertEquals(reader.readEnumerated(), 0);
+    // Should be an octet string with contextID
+    assertEquals(reader.peekType(), ASN1Constants.UNIVERSAL_OCTET_STRING_TYPE);
+    assertEquals(reader.readOctetStringAsString(), "foo");
+  }
 
   /**
    * Tests the first constructor for the response control.

--
Gitblit v1.10.0