From 163bc9c2ce2db40f360e777b4d430438728e408d Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 09 May 2012 10:10:46 +0000
Subject: [PATCH] Fix OPENDJ-488: Cancel request succeeds with result code 118 (CANCELED) when it should receive result code 0 (SUCCESS)

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java |   86 +++++++++++++++++++++----------------------
 1 files changed, 42 insertions(+), 44 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java
index 4a95bfe..e432bff 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/extensions/CancelExtendedOperationTestCase.java
@@ -23,26 +23,26 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS.
  */
 package org.opends.server.extensions;
 
 
 
+import static org.opends.server.protocols.ldap.LDAPConstants.*;
+import static org.opends.server.util.ServerConstants.OID_CANCEL_REQUEST;
+import static org.opends.server.util.ServerConstants.OID_WHO_AM_I_REQUEST;
+import static org.testng.Assert.assertEquals;
+
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
 
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
 import org.opends.server.TestCaseUtils;
 import org.opends.server.core.AddOperation;
-import org.opends.server.core.AbandonOperationBasis;
 import org.opends.server.plugins.DelayPreOpPlugin;
-import org.opends.server.protocols.asn1.ASN1Reader;
-import org.opends.server.protocols.asn1.ASN1Writer;
 import org.opends.server.protocols.asn1.ASN1;
+import org.opends.server.protocols.asn1.ASN1Writer;
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.ldap.AddRequestProtocolOp;
 import org.opends.server.protocols.ldap.AddResponseProtocolOp;
@@ -59,20 +59,23 @@
 import org.opends.server.protocols.ldap.LDAPMessage;
 import org.opends.server.protocols.ldap.LDAPModification;
 import org.opends.server.protocols.ldap.LDAPResultCode;
-import org.opends.server.protocols.ldap.ModifyRequestProtocolOp;
-import org.opends.server.protocols.ldap.ModifyResponseProtocolOp;
 import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp;
 import org.opends.server.protocols.ldap.ModifyDNResponseProtocolOp;
+import org.opends.server.protocols.ldap.ModifyRequestProtocolOp;
+import org.opends.server.protocols.ldap.ModifyResponseProtocolOp;
 import org.opends.server.protocols.ldap.SearchRequestProtocolOp;
 import org.opends.server.protocols.ldap.SearchResultDoneProtocolOp;
-import org.opends.server.types.*;
-
-import static org.testng.Assert.*;
-import static org.testng.Assert.assertEquals;
-
-import static org.opends.server.protocols.ldap.LDAPConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-import org.opends.messages.Message;
+import org.opends.server.types.ByteString;
+import org.opends.server.types.ByteStringBuilder;
+import org.opends.server.types.DereferencePolicy;
+import org.opends.server.types.Entry;
+import org.opends.server.types.ModificationType;
+import org.opends.server.types.RawAttribute;
+import org.opends.server.types.RawModification;
+import org.opends.server.types.ResultCode;
+import org.opends.server.types.SearchScope;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 
 /**
@@ -163,8 +166,7 @@
 
 
     // Read two response messages from the server.  One should be an add
-    // response and the other should be an extended response.  They should both
-    // have a result code of "cancelled".
+    // response and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -179,7 +181,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }
@@ -246,8 +248,7 @@
 
 
     // Read two response messages from the server.  One should be a compare
-    // response and the other should be an extended response.  They should both
-    // have a result code of "cancelled".
+    // response and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -263,7 +264,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }
@@ -343,8 +344,7 @@
 
 
     // Read two response messages from the server.  One should be a delete
-    // response and the other should be an extended response.  They should both
-    // have a result code of "cancelled".
+    // response and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -360,7 +360,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }
@@ -424,16 +424,17 @@
     message = new LDAPMessage(3, extendedRequest);
     w.writeMessage(message);
 
-                                                          
+
     // Read two response messages from the server.  They should both be extended
-    // responses and they should both have result codes of "cancelled".
-    for (int i=0; i < 2; i++)
-    {
-      message = r.readMessage();
-      ExtendedResponseProtocolOp extendedResponse =
-           message.getExtendedResponseProtocolOp();
-      assertEquals(extendedResponse.getResultCode(), LDAPResultCode.CANCELED);
-    }
+    // responses, one with the result code CANCELED and one with SUCCESS.
+    message = r.readMessage();
+    ExtendedResponseProtocolOp extendedResponse =
+            message.getExtendedResponseProtocolOp();
+    assertEquals(extendedResponse.getResultCode(), LDAPResultCode.CANCELED);
+
+    message = r.readMessage();
+    extendedResponse = message.getExtendedResponseProtocolOp();
+    assertEquals(extendedResponse.getResultCode(), LDAPResultCode.SUCCESS);
 
     socket.close();
   }
@@ -502,8 +503,7 @@
 
 
     // Read two response messages from the server.  One should be a modify
-    // response and the other should be an extended response.  They should both
-    // have a result code of "cancelled".
+    // response and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -519,7 +519,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }
@@ -600,8 +600,7 @@
 
 
     // Read two response messages from the server.  One should be a modify DN
-    // response and the other should be an extended response.  They should both
-    // have a result code of "cancelled".
+    // response and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -617,7 +616,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }
@@ -688,8 +687,7 @@
 
 
     // Read two response messages from the server.  One should be a search
-    // result done and the other should be an extended response.  They should
-    // both have a result code of "cancelled".
+    // result done and the other should be an extended response.
     for (int i=0; i < 2; i++)
     {
       message = r.readMessage();
@@ -705,7 +703,7 @@
           ExtendedResponseProtocolOp extendedResponse =
                message.getExtendedResponseProtocolOp();
           assertEquals(extendedResponse.getResultCode(),
-                       LDAPResultCode.CANCELED);
+                       LDAPResultCode.SUCCESS);
           break;
         default:
       }

--
Gitblit v1.10.0