/*
* 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
* or http://forgerock.org/license/CDDLv1.0.html.
* 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-2009 Sun Microsystems, Inc.
* Portions Copyright 2014 ForgeRock AS
*/
package org.opends.server.protocols.internal;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
import org.opends.server.core.BindOperation;
import org.opends.server.core.CompareOperation;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ExtendedOperation;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.protocols.ldap.LDAPModification;
import org.opends.server.types.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
/**
* This class defines a set of tests for the
* org.opends.server.protocols.internal.InternalClientConnection class.
*/
public class InternalClientConnectionTestCase
extends InternalTestCase
{
/**
* Ensures that the Directory Server is running.
*
* @throws Exception If an unexpected problem occurs.
*/
@BeforeClass()
public void startServer()
throws Exception
{
TestCaseUtils.startServer();
}
/**
* Retrieves a set of internal client connections that may be used for
* testing purposes.
*
* @return A set of internal client connections that may be used for
* testing purposes.
*
* @throws Exception If an unexpected problem occurs.
*/
@DataProvider(name = "internalConns")
public Object[][] getInternalConnections()
throws Exception
{
DN dmDN = DN.valueOf("cn=Directory Manager,cn=Root DNs,cn=config");
Entry dmEntry = DirectoryServer.getEntry(dmDN);
TestCaseUtils.initializeTestBackend(true);
Entry userEntry = TestCaseUtils.makeEntry(
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
TestCaseUtils.addEntry(userEntry);
return new Object[][]
{
new Object[] { InternalClientConnection.getRootConnection() },
new Object[] { new InternalClientConnection(new AuthenticationInfo()) },
new Object[] { new InternalClientConnection(
new AuthenticationInfo(dmEntry, true)) },
new Object[] { new InternalClientConnection(
new AuthenticationInfo(userEntry, false)) },
new Object[] { new InternalClientConnection(dmDN) },
new Object[] { new InternalClientConnection(DN.rootDN()) },
new Object[] { new InternalClientConnection((DN) null) }
};
}
/**
* Tests the nextOperationID method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testNextOperationID(InternalClientConnection conn)
{
long opID1 = InternalClientConnection.nextOperationID();
long opID2 = InternalClientConnection.nextOperationID();
assertEquals(opID2, (opID1 + 1));
}
/**
* Tests the nextMessageID method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testNextMessageID(InternalClientConnection conn)
{
int msgID1 = InternalClientConnection.nextMessageID();
int msgID2 = InternalClientConnection.nextMessageID();
assertEquals(msgID2, (msgID1 + 1));
}
/**
* Tests the getConnectionID method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetConnectionID(InternalClientConnection conn)
{
assertTrue(conn.getConnectionID() < 0);
}
/**
* Tests the getConnectionHandler method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetConnectionHandler(InternalClientConnection conn)
{
assertEquals(conn.getConnectionHandler(),
InternalConnectionHandler.getInstance());
}
/**
* Tests the getProtocol method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetProtocol(InternalClientConnection conn)
{
assertEquals(conn.getProtocol(), "internal");
}
/**
* Tests the getClientAddress method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetClientAddress(InternalClientConnection conn)
{
assertEquals(conn.getClientAddress(), "internal");
}
/**
* Tests the getServerAddress method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetServerAddress(InternalClientConnection conn)
{
assertEquals(conn.getServerAddress(), "internal");
}
/**
* Tests the getRemoteAddress method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetRemoteAddress(InternalClientConnection conn)
{
assertNull(conn.getRemoteAddress());
}
/**
* Tests the getLocalAddress method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testGetLocalAddress(InternalClientConnection conn)
{
assertNull(conn.getLocalAddress());
}
/**
* Tests the isSecure method.
*
* @param conn The internal client connection to use for the test.
*/
@Test(dataProvider = "internalConns")
public void testIsSecure(InternalClientConnection conn)
{
assertTrue(conn.isSecure());
}
/**
* Tests the getConnectionSecurityProvider method.
*
* @param conn The internal client connection to use for the test.
*/
/*MPD
* @Test(dataProvider = "internalConns")
public void testGetConnectionSecurityProvider(InternalClientConnection conn)
{
assertNotNull(conn.getConnectionSecurityProvider());
}
*/
/**
* Tests the setConnectionSecurityProvider method.
*
* @param conn The internal client connection to use for the test.
*/
/* MPD
@Test(dataProvider = "internalConns")
public void testSetConnectionSecurityProvider(InternalClientConnection conn)
{
ConnectionSecurityProvider securityProvider =
conn.getConnectionSecurityProvider();
assertNotNull(securityProvider);
conn.setConnectionSecurityProvider(securityProvider);
}
*/
/**
* Tests the first processAdd method, which takes raw arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessAdd1()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
ByteString dn = ByteString.valueOf("cn=test,o=test");
ArrayList attrs = new ArrayList();
ArrayList values = new ArrayList();
values.add(ByteString.valueOf("top"));
values.add(ByteString.valueOf("device"));
attrs.add(new LDAPAttribute("objectClass", values));
values = new ArrayList();
values.add(ByteString.valueOf("test"));
attrs.add(new LDAPAttribute("cn", values));
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(dn, attrs);
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processAdd method, which takes processed
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessAdd2()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the first processSimpleBind method, which takes raw
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSimpleBind1()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
BindOperation bindOperation =
conn.processSimpleBind(ByteString.valueOf("cn=Directory Manager"),
ByteString.valueOf("password"));
assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processSimpleBind method, which takes
* processed arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSimpleBind2()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
BindOperation bindOperation =
conn.processSimpleBind(DN.valueOf("cn=Directory Manager"),
ByteString.valueOf("password"));
assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the first processSASLBind method, which takes raw
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSASLBind1()
throws Exception
{
ByteString creds =
ByteString.valueOf("\u0000dn:cn=Directory Manager\u0000password");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
BindOperation bindOperation =
conn.processSASLBind(ByteString.empty(), "PLAIN", creds);
assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processSASLBind method, which takes processed
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSASLBind2()
throws Exception
{
ByteString creds =
ByteString.valueOf("\u0000dn:cn=Directory Manager\u0000password");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
BindOperation bindOperation =
conn.processSASLBind(DN.rootDN(), "PLAIN", creds);
assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the first processCompare method, which takes raw
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessCompare1()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
CompareOperation compareOperation =
conn.processCompare(ByteString.valueOf("cn=test,o=test"), "cn",
ByteString.valueOf("test"));
assertEquals(compareOperation.getResultCode(), ResultCode.COMPARE_TRUE);
}
/**
* Tests the second processCompare method, which takes processed
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessCompare2()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
CompareOperation compareOperation =
conn.processCompare(DN.valueOf("cn=test,o=test"),
DirectoryServer.getAttributeType("cn", true),
ByteString.valueOf("test"));
assertEquals(compareOperation.getResultCode(), ResultCode.COMPARE_TRUE);
}
/**
* Tests the first processDelete method, which takes raw
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessDelete1()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
DeleteOperation deleteOperation =
conn.processDelete(ByteString.valueOf("cn=test,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processDelete method, which takes processed
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessDelete2()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
DeleteOperation deleteOperation =
conn.processDelete(DN.valueOf("cn=test,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the processExtendedOperation method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessExtendedOperation()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
ExtendedOperation extendedOperation =
conn.processExtendedOperation(OID_WHO_AM_I_REQUEST, null);
assertEquals(extendedOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the first processModify method, which takes raw
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModify1()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ArrayList values = new ArrayList();
values.add(ByteString.valueOf("This is a test"));
ArrayList mods = new ArrayList();
mods.add(new LDAPModification(ModificationType.REPLACE,
new LDAPAttribute("description", values)));
ModifyOperation modifyOperation =
conn.processModify(ByteString.valueOf("cn=test,o=test"), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processModify method, which takes processed
* arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModify2()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ArrayList mods = new ArrayList();
mods.add(new Modification(ModificationType.REPLACE,
Attributes.create("description", "This is a test")));
ModifyOperation modifyOperation =
conn.processModify(DN.valueOf("cn=test,o=test"), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the first processModifyDN method, which takes raw
* arguments and no newSuperior option.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModifyDN1()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(ByteString.valueOf("cn=test,o=test"),
ByteString.valueOf("cn=test2"), true);
assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the second processModifyDN method, which takes raw
* arguments and allows newSuperior option.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModifyDN2()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(ByteString.valueOf("cn=test,o=test"),
ByteString.valueOf("cn=test2"), true,
ByteString.valueOf("dc=example,dc=com"));
assertEquals(modifyDNOperation.getResultCode(),
ResultCode.UNWILLING_TO_PERFORM);
}
/**
* Tests the third processModifyDN method, which takes processed
* arguments and no newSuperior option.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModifyDN3()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(DN.valueOf("cn=test,o=test"),
RDN.decode("cn=test2"), true);
assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
* Tests the fourth processModifyDN method, which takes processed
* arguments and allows newSuperior option.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessModifyDN4()
throws Exception
{
TestCaseUtils.initializeTestBackend(true);
Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
"objectClass: top",
"objectClass: device",
"cn: test");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation = conn.processAdd(e.getName(), e.getObjectClasses(),
e.getUserAttributes(),
e.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(DN.valueOf("cn=test,o=test"),
RDN.decode("cn=test2"), true,
DN.valueOf("dc=example,dc=com"));
assertEquals(modifyDNOperation.getResultCode(),
ResultCode.UNWILLING_TO_PERFORM);
}
/**
* Tests the first processSearch method, which takes a minimal
* set of raw arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch1()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(ByteString.valueOf(""), SearchScope.BASE_OBJECT,
LDAPFilter.decode("(objectClass=*)"));
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchOperation.getSearchEntries().isEmpty());
assertTrue(searchOperation.getSearchReferences().isEmpty());
}
/**
* Tests the second processSearch method, which takes a full set
* of raw arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch2()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(ByteString.valueOf(""), SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
LDAPFilter.decode("(objectClass=*)"),
new LinkedHashSet());
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchOperation.getSearchEntries().isEmpty());
assertTrue(searchOperation.getSearchReferences().isEmpty());
}
/**
* Tests the third processSearch method, which takes a full set
* of raw arguments and uses an internal search listener to handle the
* results.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch3()
throws Exception
{
TestInternalSearchListener searchListener =
new TestInternalSearchListener();
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(ByteString.valueOf(""), SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
LDAPFilter.decode("(objectClass=*)"),
new LinkedHashSet(), searchListener);
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchListener.getSearchEntries().isEmpty());
assertTrue(searchListener.getSearchReferences().isEmpty());
}
/**
* Tests the fourth processSearch method, which takes a minimal
* set of processed arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch4()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(DN.rootDN(), SearchScope.BASE_OBJECT,
SearchFilter.createFilterFromString("(objectClass=*)"));
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchOperation.getSearchEntries().isEmpty());
assertTrue(searchOperation.getSearchReferences().isEmpty());
}
/**
* Tests the fifth processSearch method, which takes a full set
* of processed arguments.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch5()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(DN.rootDN(), SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
SearchFilter.createFilterFromString("(objectClass=*)"),
new LinkedHashSet());
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchOperation.getSearchEntries().isEmpty());
assertTrue(searchOperation.getSearchReferences().isEmpty());
}
/**
* Tests the sixth processSearch method, which takes a full set
* of processed arguments and uses an internal search listener to handle the
* results.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessSearch6()
throws Exception
{
TestInternalSearchListener searchListener =
new TestInternalSearchListener();
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(DN.rootDN(), SearchScope.BASE_OBJECT,
DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
SearchFilter.createFilterFromString("(objectClass=*)"),
new LinkedHashSet(), searchListener);
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchListener.getSearchEntries().isEmpty());
assertTrue(searchListener.getSearchReferences().isEmpty());
}
/**
* Tests the sendSearchReference method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSendSearchReference()
throws Exception
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
InternalSearchOperation searchOperation =
conn.processSearch(ByteString.valueOf(""), SearchScope.BASE_OBJECT,
LDAPFilter.decode("(objectClass=*)"));
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(searchOperation.getSearchEntries().isEmpty());
assertTrue(searchOperation.getSearchReferences().isEmpty());
SearchResultReference reference =
new SearchResultReference("ldap://server.example.com:389/");
conn.sendSearchReference(searchOperation, reference);
assertFalse(searchOperation.getSearchReferences().isEmpty());
}
/**
* Tests the sendIntermediateResponseMessage method.
*/
@Test()
public void testSendIntermediateResponseMessage()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
assertFalse(conn.sendIntermediateResponseMessage(null));
}
/**
* Tests the disconnect method.
*/
@Test()
public void testDisconnect()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
conn.disconnect(DisconnectReason.OTHER, false,
LocalizableMessage.raw("testDisconnect"));
}
/**
* Tests the removeOperationInProgress method.
*/
@Test()
public void testRemoveOperationInProgress()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
assertFalse(conn.removeOperationInProgress(1));
}
/**
* Tests the cancelOperation method.
*/
@Test()
public void testCancelOperation()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
CancelResult cancelResult =
conn.cancelOperation(1,
new CancelRequest(true, LocalizableMessage.raw("testCancelOperation")));
assertEquals(cancelResult.getResultCode(), ResultCode.CANNOT_CANCEL);
}
/**
* Tests the cancelAllOperations method.
*/
@Test()
public void testCancelAllOperations()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
conn.cancelAllOperations(new CancelRequest(true,
LocalizableMessage.raw("testCancelOperation")));
}
/**
* Tests the cancelAllOperationsExcept method.
*/
@Test()
public void testCancelAllOperationsExcept()
{
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
conn.cancelAllOperationsExcept(
new CancelRequest(true, LocalizableMessage.raw("testCancelOperation")), 1);
}
/**
* Tests the toString method.
*/
@Test()
public void testToString()
{
StringBuilder buffer = new StringBuilder();
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
conn.toString(buffer);
assertFalse(buffer.toString().equals(""));
}
}