CancelExtendedOperationTestCase.java revision 5cd7bdbbda0fa9f1aa6e12d9171c3811b73feb07
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2015 ForgeRock AS.
*/
/**
* A set of test cases for the cancel extended operation handler.
*/
public class CancelExtendedOperationTestCase
extends ExtensionsTestCase
{
/**
* Ensures that the Directory Server is running, and enables the delay plugin
* so that new requests will be artificially delayed.
*
* @throws Exception If an unexpected problem occurs.
*/
public void startServer()
throws Exception
{
}
/**
* Tests the ability to cancel an add operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelAddOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create an add request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be an add
// response and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
case OP_TYPE_ADD_RESPONSE:
break;
break;
default:
}
}
}
/**
* Tests the ability to cancel a compare operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelCompareOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a compare request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be a compare
// response and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
case OP_TYPE_COMPARE_RESPONSE:
break;
break;
default:
}
}
}
/**
* Tests the ability to cancel a delete operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelDeleteOperation()
throws Exception
{
// Add an entry to the server that we can delete.
"dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a delete request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be a delete
// response and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
case OP_TYPE_DELETE_RESPONSE:
break;
break;
default:
}
}
}
/**
* Tests the ability to cancel an extended operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelExtendedOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a "Who Am I?" extended operation and send it to the server. Make
// sure to include the delay request control so it won't complete before we
// can send the cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. They should both be extended
// responses, one with the result code CANCELED and one with SUCCESS.
message = r.readMessage();
message = r.readMessage();
}
/**
* Tests the ability to cancel a modify operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelModifyOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a modify request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be a modify
// response and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
case OP_TYPE_MODIFY_RESPONSE:
break;
break;
default:
}
}
}
/**
* Tests the ability to cancel a modify DN operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelModifyDNOperation()
throws Exception
{
// Add an entry to the server that we can rename.
"dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a modify DN request and send it to the server. Make sure to
// include the delay request control so it won't complete before we can send
// the cancel request.
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be a modify DN
// response and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
break;
break;
default:
}
}
}
/**
* Tests the ability to cancel a search operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelSearchOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a search request and send it to the server. Make sure to include
// the delay request control so it won't complete before we can send the
// cancel request.
0, false,
new LinkedHashSet<String>());
w.writeMessage(message);
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read two response messages from the server. One should be a search
// result done and the other should be an extended response.
for (int i=0; i < 2; i++)
{
message = r.readMessage();
switch (message.getProtocolOpType())
{
break;
break;
default:
}
}
}
/**
* Tests the attempt to cancel an operation that doesn't exist.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelNoSuchOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a cancel request and send it to the server.
builder.toByteString());
w.writeMessage(message);
// Read the response message from the server. It should be an extended
// response with a result code of "no such operation".
message = r.readMessage();
}
/**
* Tests sending a cancel request with no request value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelNoValue()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a cancel request and send it to the server.
w.writeMessage(message);
// Read the response message from the server. It should be an extended
// response with a result code of "no such operation".
message = r.readMessage();
}
/**
* Tests sending a cancel request with a malformed request value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelMalformedValue()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a cancel request and send it to the server.
w.writeMessage(message);
// Read the response message from the server. It should be an extended
// response with a result code of "no such operation".
message = r.readMessage();
}
/**
* Tests the ability to cancel an extended operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCancelCancelExtendedOperation()
throws Exception
{
// Create a new connection to the Directory Server and authenticate as
// the Directory Manager.
w.writeMessage(message);
message = r.readMessage();
// Create a self cancelling request and send it to the server. Make sure
// to include the delay request control so it won't complete before we
// can send the cancel request.
builder.toByteString());
w.writeMessage(message);
message = r.readMessage();
}
}