From 33b1f5c82ea7443850e04101ab3ac789fbc454fb Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 16 Oct 2014 11:16:33 +0000
Subject: [PATCH] Converted opendj3 code to use SearchRequest like API
---
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/IsMemberOfVirtualAttributeProviderTestCase.java | 174 +---
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/Requests.java | 4
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/HasSubordinatesVirtualAttributeProviderTestCase.java | 31
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/AdministrationDataSync.java | 2
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/crypto/CryptoManagerSync.java | 25
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalClientConnection.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java | 31
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciHandler.java | 29
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ServerSideSortControlTestCase.java | 457 ++---------
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/PrivilegeTestCase.java | 18
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/TraditionalWorkQueueTestCase.java | 62 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/CollationMatchingRuleTest.java | 119 +-
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciListenerManager.java | 28
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java | 49 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/StructuralObjectClassVirtualAttributeProviderTestCase.java | 67 -
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalSearchOperation.java | 54
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/GroupManager.java | 83 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/GroupManagerTestCase.java | 76 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/VirtualStaticGroupTestCase.java | 56
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SubentryManager.java | 28
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java | 98 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java | 642 +++-------------
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java | 9
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java | 81 -
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/EntryDNVirtualAttributeProviderTestCase.java | 41
25 files changed, 661 insertions(+), 1,609 deletions(-)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/AdministrationDataSync.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/AdministrationDataSync.java
index 67328d7..1b1405e 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/AdministrationDataSync.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/AdministrationDataSync.java
@@ -267,7 +267,7 @@
InternalSearchOperation search;
try
{
- SearchRequest request = Requests.newSearchRequest(baseDN, SearchScope.BASE_OBJECT, "objectclass=*")
+ SearchRequest request = Requests.newSearchRequest(DN.valueOf(baseDN), SearchScope.BASE_OBJECT)
.addAttribute(attrName);
search = internalConnection.processSearch(request);
if (search.getResultCode() != ResultCode.SUCCESS)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciHandler.java
index a31fff7..063e5b7 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciHandler.java
@@ -27,13 +27,15 @@
*/
package org.opends.server.authorization.dseecompat;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.SortedSet;
import java.util.concurrent.locks.Lock;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -42,11 +44,11 @@
import org.opends.server.api.ClientConnection;
import org.opends.server.api.ConfigHandler;
import org.opends.server.backends.jeb.EntryContainer;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.controls.GetEffectiveRightsRequestControl;
import org.opends.server.core.*;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.*;
import org.opends.server.workflowelement.localbackend.*;
@@ -55,6 +57,8 @@
import static org.opends.server.authorization.dseecompat.Aci.*;
import static org.opends.server.authorization.dseecompat.EnumEvalReason.*;
import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.schema.SchemaConstants.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -1166,13 +1170,10 @@
*/
private void processConfigAcis() throws InitializationException
{
- Set<String> requestAttrs = new LinkedHashSet<String>(1);
- requestAttrs.add("aci");
LinkedList<LocalizableMessage> failedACIMsgs = new LinkedList<LocalizableMessage>();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
- ConfigHandler configBackend = DirectoryServer.getConfigHandler();
+ ConfigHandler<?> configBackend = DirectoryServer.getConfigHandler();
for (DN baseDN : configBackend.getBaseDNs())
{
try
@@ -1191,14 +1192,10 @@
}
try {
- InternalSearchOperation internalSearch = new InternalSearchOperation(
- conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
- null, baseDN, SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("aci=*"), requestAttrs, null);
- LocalBackendSearchOperation localSearch =
- new LocalBackendSearchOperation(internalSearch);
+ SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, "aci=*").addAttribute("aci");
+ InternalSearchOperation internalSearch =
+ new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request);
+ LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(internalSearch);
configBackend.search(localSearch);
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciListenerManager.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciListenerManager.java
index b1cd5ba..e0214aa 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciListenerManager.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/authorization/dseecompat/AciListenerManager.java
@@ -30,7 +30,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.api.AlertGenerator;
import org.opends.server.api.Backend;
@@ -42,13 +42,15 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.operation.*;
import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation;
import static org.opends.messages.AccessControlMessages.*;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
/**
@@ -432,17 +434,16 @@
logger.warn(WARN_ACI_ATTRIBUTE_NOT_INDEXED, backend.getBackendID(), "aci");
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
LinkedList<LocalizableMessage> failedACIMsgs = new LinkedList<LocalizableMessage>();
+
+ InternalClientConnection conn = getRootConnection();
// Add manageDsaIT control so any ACIs in referral entries will be
// picked up.
- ArrayList<Control> controls = new ArrayList<Control>(1);
- controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true));
+ LDAPControl c1 = new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true);
// Add group membership control to let a backend look for it and
// decide if it would abort searches.
- controls.add(new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE,
- false));
+ LDAPControl c2 = new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, false);
+
for (DN baseDN : backend.getBaseDNs())
{
try
@@ -457,13 +458,12 @@
logger.traceException(e);
continue;
}
+ SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, aciFilter)
+ .addControl(c1)
+ .addControl(c2)
+ .addAttribute(attrs);
InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection
- .nextOperationID(), InternalClientConnection
- .nextMessageID(), controls, baseDN,
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- aciFilter, attrs, null);
+ new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request);
LocalBackendSearchOperation localInternalSearch =
new LocalBackendSearchOperation(internalSearch);
try
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/GroupManager.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/GroupManager.java
index 20ae08b..48758d8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/GroupManager.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/GroupManager.java
@@ -32,7 +32,8 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.util.Utils;
import org.opends.server.admin.ClassPropertyDefinition;
@@ -51,18 +52,18 @@
import org.opends.server.api.plugin.PluginResult;
import org.opends.server.api.plugin.PluginResult.PostOperation;
import org.opends.server.api.plugin.PluginType;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.operation.*;
import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -96,13 +97,13 @@
* A mapping between the DNs of the config entries and the associated group
* implementations.
*/
- private ConcurrentHashMap<DN, Group> groupImplementations;
+ private ConcurrentHashMap<DN, Group<?>> groupImplementations;
/**
* A mapping between the DNs of all group entries and the corresponding group
* instances.
*/
- private DITCacheMap<Group> groupInstances;
+ private DITCacheMap<Group<?>> groupInstances;
/** Lock to protect internal data structures. */
private final ReentrantReadWriteLock lock;
@@ -132,8 +133,8 @@
PluginType.POST_SYNCHRONIZATION_MODIFY_DN), true);
this.serverContext = serverContext;
- groupImplementations = new ConcurrentHashMap<DN, Group>();
- groupInstances = new DITCacheMap<Group>();
+ groupImplementations = new ConcurrentHashMap<DN, Group<?>>();
+ groupInstances = new DITCacheMap<Group<?>>();
lock = new ReentrantReadWriteLock();
@@ -182,8 +183,7 @@
{
try
{
- Group group = loadGroup(groupConfiguration.getJavaClass(),
- groupConfiguration, true);
+ Group<?> group = loadGroup(groupConfiguration.getJavaClass(), groupConfiguration, true);
groupImplementations.put(groupConfiguration.dn(), group);
}
catch (InitializationException ie)
@@ -235,7 +235,7 @@
return new ConfigChangeResult(resultCode, false, messages);
}
- Group group = null;
+ Group<?> group = null;
try
{
group = loadGroup(configuration.getJavaClass(), configuration, true);
@@ -279,16 +279,16 @@
ResultCode resultCode = ResultCode.SUCCESS;
List<LocalizableMessage> messages = new ArrayList<LocalizableMessage>();
- Group group = groupImplementations.remove(configuration.dn());
+ Group<?> group = groupImplementations.remove(configuration.dn());
if (group != null)
{
lock.writeLock().lock();
try
{
- Iterator<Group> iterator = groupInstances.values().iterator();
+ Iterator<Group<?>> iterator = groupInstances.values().iterator();
while (iterator.hasNext())
{
- Group g = iterator.next();
+ Group<?> g = iterator.next();
if (g.getClass().getName().equals(group.getClass().getName()))
{
iterator.remove();
@@ -340,7 +340,7 @@
boolean adminActionRequired = false;
List<LocalizableMessage> messages = new ArrayList<LocalizableMessage>();
// Get the existing group implementation if it's already enabled.
- Group existingGroup = groupImplementations.get(configuration.dn());
+ Group<?> existingGroup = groupImplementations.get(configuration.dn());
// If the new configuration has the group implementation disabled, then
// disable it if it is enabled, or do nothing if it's already disabled.
@@ -348,16 +348,16 @@
{
if (existingGroup != null)
{
- Group group = groupImplementations.remove(configuration.dn());
+ Group<?> group = groupImplementations.remove(configuration.dn());
if (group != null)
{
lock.writeLock().lock();
try
{
- Iterator<Group> iterator = groupInstances.values().iterator();
+ Iterator<Group<?>> iterator = groupInstances.values().iterator();
while (iterator.hasNext())
{
- Group g = iterator.next();
+ Group<?> g = iterator.next();
if (g.getClass().getName().equals(group.getClass().getName()))
{
iterator.remove();
@@ -393,7 +393,7 @@
return new ConfigChangeResult(resultCode, adminActionRequired, messages);
}
- Group group = null;
+ Group<?> group = null;
try
{
group = loadGroup(className, configuration, true);
@@ -433,7 +433,7 @@
* @throws InitializationException If a problem occurred while attempting to
* initialize the group implementation.
*/
- private Group loadGroup(String className,
+ private Group<?> loadGroup(String className,
GroupImplementationCfg configuration,
boolean initialize)
throws InitializationException
@@ -486,7 +486,7 @@
deregisterAllGroups();
- for (Group groupImplementation : groupImplementations.values())
+ for (Group<?> groupImplementation : groupImplementations.values())
{
groupImplementation.finalizeGroupImplementation();
}
@@ -503,7 +503,7 @@
* @return An {@code Iterable} object that may be used to cursor across the
* group implementations defined in the server.
*/
- public Iterable<Group> getGroupImplementations()
+ public Iterable<Group<?>> getGroupImplementations()
{
return groupImplementations.values();
}
@@ -517,15 +517,13 @@
* @return An {@code Iterable} object that may be used to cursor across the
* group instances defined in the server.
*/
- public Iterable<Group> getGroupInstances()
+ public Iterable<Group<?>> getGroupInstances()
{
lock.readLock().lock();
try
{
// Return a copy to protect from structural changes.
- ArrayList<Group> values = new ArrayList<Group>();
- values.addAll(groupInstances.values());
- return values;
+ return new ArrayList<Group<?>>(groupInstances.values());
}
finally
{
@@ -544,7 +542,7 @@
* @return The group instance defined in the entry with the specified DN, or
* {@code null} if no such group is currently defined.
*/
- public Group getGroupInstance(DN entryDN)
+ public Group<?> getGroupInstance(DN entryDN)
{
lock.readLock().lock();
try
@@ -567,16 +565,13 @@
@Override
public void performBackendInitializationProcessing(Backend backend)
{
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
- LinkedList<Control> requestControls = new LinkedList<Control>();
- requestControls.add(new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE,
- false));
+ LDAPControl control = new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, false);
for (DN configEntryDN : groupImplementations.keySet())
{
SearchFilter filter;
- Group groupImplementation = groupImplementations.get(configEntryDN);
+ Group<?> groupImplementation = groupImplementations.get(configEntryDN);
try
{
filter = groupImplementation.getGroupDefinitionFilter();
@@ -608,13 +603,10 @@
}
+ SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter)
+ .addControl(control);
InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, nextOperationID(),
- nextMessageID(), requestControls,
- baseDN,
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER,
- 0, 0, false, filter, null, null);
+ new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request);
LocalBackendSearchOperation localSearch =
new LocalBackendSearchOperation(internalSearch);
try
@@ -636,7 +628,7 @@
{
try
{
- Group groupInstance = groupImplementation.newInstance(entry);
+ Group<?> groupInstance = groupImplementation.newInstance(entry);
groupInstances.put(entry.getName(), groupInstance);
refreshToken++;
}
@@ -667,11 +659,10 @@
lock.writeLock().lock();
try
{
- Iterator<Map.Entry<DN,Group>> iterator =
- groupInstances.entrySet().iterator();
+ Iterator<Map.Entry<DN, Group<?>>> iterator = groupInstances.entrySet().iterator();
while (iterator.hasNext())
{
- Map.Entry<DN,Group> mapEntry = iterator.next();
+ Map.Entry<DN, Group<?>> mapEntry = iterator.next();
DN groupEntryDN = mapEntry.getKey();
if (backend.handlesEntry(groupEntryDN))
{
@@ -817,11 +808,11 @@
lock.writeLock().lock();
try
{
- Set<Group> groupSet = new HashSet<Group>();
+ Set<Group<?>> groupSet = new HashSet<Group<?>>();
groupInstances.removeSubtree(oldEntry.getName(), groupSet);
String oldDNString = oldEntry.getName().toNormalizedString();
String newDNString = newEntry.getName().toNormalizedString();
- for (Group group : groupSet)
+ for (Group<?> group : groupSet)
{
StringBuilder builder = new StringBuilder(
group.getGroupDN().toNormalizedString());
@@ -985,13 +976,13 @@
*/
private void createAndRegisterGroup(Entry entry)
{
- for (Group groupImplementation : groupImplementations.values())
+ for (Group<?> groupImplementation : groupImplementations.values())
{
try
{
if (groupImplementation.isGroupDefinition(entry))
{
- Group groupInstance = groupImplementation.newInstance(entry);
+ Group<?> groupInstance = groupImplementation.newInstance(entry);
lock.writeLock().lock();
try
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SubentryManager.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SubentryManager.java
index 5829848..1c46a5c 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SubentryManager.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/core/SubentryManager.java
@@ -31,11 +31,11 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
-import org.opends.server.api.ClientConnection;
import org.opends.server.api.Backend;
import org.opends.server.api.BackendInitializationListener;
+import org.opends.server.api.ClientConnection;
import org.opends.server.api.DITCacheMap;
import org.opends.server.api.SubentryChangeListener;
import org.opends.server.api.plugin.InternalDirectoryServerPlugin;
@@ -46,8 +46,8 @@
import org.opends.server.controls.SubentriesControl;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.operation.PostOperationAddOperation;
import org.opends.server.types.operation.PostOperationDeleteOperation;
import org.opends.server.types.operation.PostOperationModifyDNOperation;
@@ -64,6 +64,8 @@
import static org.opends.messages.CoreMessages.*;
import static org.opends.server.config.ConfigConstants.*;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
/**
@@ -304,10 +306,8 @@
@Override
public void performBackendInitializationProcessing(Backend backend)
{
- InternalClientConnection conn = InternalClientConnection.getRootConnection();
-
- LinkedList<Control> requestControls = new LinkedList<Control>();
- requestControls.add(new SubentriesControl(true, true));
+ InternalClientConnection conn = getRootConnection();
+ SubentriesControl control = new SubentriesControl(true, true);
SearchFilter filter = null;
try
@@ -343,14 +343,12 @@
continue;
}
- InternalSearchOperation internalSearch = new InternalSearchOperation(
- conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
- requestControls, baseDN, SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- filter, requestAttrs, null);
- LocalBackendSearchOperation localSearch =
- new LocalBackendSearchOperation(internalSearch);
+ SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter)
+ .addAttribute(requestAttrs)
+ .addControl(control);
+ InternalSearchOperation internalSearch =
+ new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request);
+ LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(internalSearch);
try
{
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/crypto/CryptoManagerSync.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/crypto/CryptoManagerSync.java
index 13648db..b74e7d1 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/crypto/CryptoManagerSync.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/crypto/CryptoManagerSync.java
@@ -26,16 +26,13 @@
*/
package org.opends.server.crypto;
-import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.admin.ads.ADSContext;
@@ -51,6 +48,7 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
@@ -72,6 +70,7 @@
import static org.opends.server.api.plugin.PluginType.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -197,23 +196,8 @@
private void searchAdminSuffix()
{
- LinkedHashSet<String> attributes = new LinkedHashSet<String>(0);
-
- ArrayList<Control> controls = new ArrayList<Control>(0);
-
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(getRootConnection(),
- nextOperationID(),
- nextMessageID(),
- controls,
- adminSuffixDN, SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER,
- 0, 0,
- false, keySearchFilter, attributes,
- null);
-
- searchOperation.run();
-
+ SearchRequest request = newSearchRequest(adminSuffixDN, SearchScope.WHOLE_SUBTREE, keySearchFilter);
+ InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
ResultCode resultCode = searchOperation.getResultCode();
if (resultCode != ResultCode.SUCCESS)
{
@@ -234,7 +218,6 @@
logger.error(ERR_TRUSTSTORESYNC_EXCEPTION, stackTraceToSingleLineString(e));
}
}
-
}
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalClientConnection.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
index a16781e..52aaa79 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -2022,11 +2022,7 @@
// filter = Filter.alwaysTrue();
// }
InternalSearchOperation searchOperation =
- new InternalSearchOperation(this, nextOperationID(), nextMessageID(),
- request.getControls(), request.getName(), request.getScope(),
- request.getDereferenceAliasesPolicy(), request.getSizeLimit(),
- request.getTimeLimit(), request.isTypesOnly(), request.getFilter(),
- request.getAttributes(), searchListener);
+ new InternalSearchOperation(this, nextOperationID(), nextMessageID(), request, searchListener);
searchOperation.run();
return searchOperation;
}
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalSearchOperation.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalSearchOperation.java
index 7a5939a..f6d43c2 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalSearchOperation.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/InternalSearchOperation.java
@@ -129,10 +129,27 @@
}
+ /**
+ * Creates a new internal search operation with the provided information.
+ *
+ * @param internalConnection
+ * The internal client connection with which this internal search
+ * operation is associated.
+ * @param operationID
+ * The operation ID for this internal search.
+ * @param messageID
+ * The message ID for this internal search.
+ * @param request
+ * The search request
+ */
+ public InternalSearchOperation(ClientConnection internalConnection, long operationID, int messageID,
+ SearchRequest request)
+ {
+ this(internalConnection, operationID, messageID, request, null);
+ }
/**
- * Creates a new internal search operation with the provided
- * information.
+ * Creates a new internal search operation with the provided information.
*
* @param internalConnection The internal client connection with
* which this internal search operation
@@ -141,27 +158,26 @@
* search.
* @param messageID The message ID for this internal
* search.
- * @param requestControls The set of request controls for this
- * internal search.
- * @param baseDN The base DN for this internal search.
- * @param scope The scope for this internal search.
- * @param derefPolicy The alias dereferencing policy for
- * this internal search.
- * @param sizeLimit The size limit for this internal
- * search.
- * @param timeLimit The time limit for this internal
- * search.
- * @param typesOnly The typesOnly flag for this internal
- * search.
- * @param filter The filter for this internal search.
- * @param attributes The names of the requested attributes
- * for this internal search.
+ * @param request The search request
* @param searchListener The internal search listener that
* should be used to process the
* results, or <CODE>null</CODE> if
* they should be collected internally.
*/
- public InternalSearchOperation(
+ public InternalSearchOperation(ClientConnection internalConnection, long operationID, int messageID,
+ SearchRequest request, InternalSearchListener searchListener)
+ {
+ this(internalConnection, operationID, messageID,
+ request.getControls(),
+ request.getName(), request.getScope(),
+ request.getDereferenceAliasesPolicy(),
+ request.getSizeLimit(), request.getTimeLimit(), request.isTypesOnly(),
+ request.getFilter(), request.getAttributes(),
+ searchListener);
+ }
+
+ // TODO JNR remove??
+ private InternalSearchOperation(
ClientConnection internalConnection,
long operationID, int messageID,
List<Control> requestControls, DN baseDN,
@@ -193,8 +209,6 @@
setInternalOperation(true);
}
-
-
/**
* Retrieves the set of search result entries returned for this
* search.
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/Requests.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/Requests.java
index c7fe01d..0567c15 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/Requests.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/internal/Requests.java
@@ -117,7 +117,9 @@
final String filter, final String... attributeDescriptions)
throws NullPointerException, LocalizedIllegalArgumentException, DirectoryException {
Reject.ifNull(name, scope, filter);
- SearchFilter f = SearchFilter.createFilterFromString(filter);
+ SearchFilter f = "(objectclass=*)".equals(filter.toLowerCase())
+ ? SearchFilter.objectClassPresent()
+ : SearchFilter.createFilterFromString(filter);
final SearchRequest request = new SearchRequest(DN.valueOf(name), scope, f);
for (final String attributeDescription : attributeDescriptions) {
request.addAttribute(attributeDescription);
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
index 0f3257b..917d159 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
@@ -770,13 +770,8 @@
*/
public InternalSearchOperation processSearch(SearchRequest request)
{
- InternalSearchOperation searchOperation = new InternalSearchOperation(
- this, nextOperationID(), nextMessageID(),
- request.getControls(),
- request.getName(), request.getScope(),
- request.getDereferenceAliasesPolicy(),
- request.getSizeLimit(), request.getTimeLimit(), request.isTypesOnly(),
- request.getFilter(), request.getAttributes(), null);
+ InternalSearchOperation searchOperation =
+ new InternalSearchOperation(this, nextOperationID(), nextMessageID(), request);
if (! hasPrivilege(Privilege.JMX_READ, null))
{
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
index 130f8f6..03a6c13 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/replication/plugin/PersistentServerState.java
@@ -37,7 +37,6 @@
import org.opends.server.core.ModifyOperationBasis;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
-import static org.opends.server.protocols.internal.Requests.*;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPModification;
import org.opends.server.replication.common.CSN;
@@ -48,6 +47,7 @@
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
/**
* This class implements a ServerState that is stored in the backend
@@ -158,30 +158,17 @@
*/
private SearchResultEntry searchBaseEntry()
{
- try
+ // Search the database entry that is used to periodically save the ServerState
+ final SearchRequest request = newSearchRequest(baseDN, SearchScope.BASE_OBJECT).addAttribute(REPLICATION_STATE);
+ final InternalSearchOperation search = getRootConnection().processSearch(request);
+ final ResultCode resultCode = search.getResultCode();
+ if (resultCode != ResultCode.SUCCESS
+ && resultCode != ResultCode.NO_SUCH_OBJECT)
{
- final SearchRequest request =
- newSearchRequest(baseDN, SearchScope.BASE_OBJECT, "objectclass=*").addAttribute(REPLICATION_STATE);
- /*
- * Search the database entry that is used to periodically
- * save the ServerState
- */
- final InternalSearchOperation search = getRootConnection().processSearch(request);
- final ResultCode resultCode = search.getResultCode();
- if (resultCode != ResultCode.SUCCESS
- && resultCode != ResultCode.NO_SUCH_OBJECT)
- {
- logger.error(ERR_ERROR_SEARCHING_RUV, search.getResultCode().getName(), search,
- search.getErrorMessage(), baseDN);
- return null;
- }
- return getFirstResult(search);
- }
- catch (DirectoryException e)
- {
- // cannot happen
+ logger.error(ERR_ERROR_SEARCHING_RUV, search.getResultCode().getName(), search, search.getErrorMessage(), baseDN);
return null;
}
+ return getFirstResult(search);
}
/**
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ServerSideSortControlTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ServerSideSortControlTestCase.java
index f7893cc..9858fe5 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ServerSideSortControlTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/ServerSideSortControlTestCase.java
@@ -26,35 +26,32 @@
*/
package org.opends.server.controls;
-
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.AttributeType;
import org.opends.server.types.Control;
import org.opends.server.types.DN;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.opends.server.types.SearchFilter;
-import org.forgerock.opendj.ldap.SearchScope;
+import org.opends.server.types.SearchResultEntry;
import org.opends.server.types.SortKey;
import org.opends.server.types.SortOrder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
+import static org.testng.Assert.*;
/**
* This class contains a number of test cases for the server side sort request
@@ -103,9 +100,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @BeforeClass()
- public void startServer()
- throws Exception
+ @BeforeClass
+ public void startServer() throws Exception
{
TestCaseUtils.startServer();
@@ -133,8 +129,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- private void populateDB()
- throws Exception
+ private void populateDB() throws Exception
{
TestCaseUtils.clearJEBackend(true, "userRoot", "dc=example,dc=com");
@@ -241,9 +236,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testRequestConstructor1()
- throws Exception
+ @Test
+ public void testRequestConstructor1() throws Exception
{
SortKey sortKey = new SortKey(givenNameType, true);
SortOrder sortOrder = new SortOrder(sortKey);
@@ -257,12 +251,9 @@
sortKey.toString();
sortOrder.toString();
- SortKey[] sortKeys =
- {
+ sortOrder = new SortOrder(
new SortKey(snType, true),
- new SortKey(givenNameType, true)
- };
- sortOrder = new SortOrder(sortKeys);
+ new SortKey(givenNameType, true));
new ServerSideSortRequestControl(sortOrder).toString();
sortOrder.toString();
}
@@ -275,13 +266,11 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testRequestConstructor2()
- throws Exception
+ @Test
+ public void testRequestConstructor2() throws Exception
{
new ServerSideSortRequestControl("givenName").toString();
- new ServerSideSortRequestControl("givenName:caseIgnoreOrderingMatch").
- toString();
+ new ServerSideSortRequestControl("givenName:caseIgnoreOrderingMatch").toString();
new ServerSideSortRequestControl("+givenName").toString();
new ServerSideSortRequestControl("-givenName").toString();
new ServerSideSortRequestControl("givenName,sn").toString();
@@ -293,8 +282,7 @@
new ServerSideSortRequestControl("-givenName").toString();
new ServerSideSortRequestControl("-givenName,+sn").toString();
new ServerSideSortRequestControl("-givenName,-sn").toString();
- new ServerSideSortRequestControl("-givenName,-sn:caseExactOrderingMatch").
- toString();
+ new ServerSideSortRequestControl("-givenName,-sn:caseExactOrderingMatch").toString();
}
@@ -305,27 +293,17 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchGivenNameAscending()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"));
+ InternalSearchOperation internalSearch = conn.processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -339,35 +317,11 @@
expectedDNOrder.add(samZweckDN); // Sam
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
-
-
/**
* Tests performing an internal search using the server-side sort control to
* sort the entries in order of ascending givenName values using a specific
@@ -375,28 +329,14 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchGivenNameAscendingCaseExact()
- throws Exception
+ @Test
+ public void testInternalSearchGivenNameAscendingCaseExact() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl(
- "givenName:caseExactOrderingMatch"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName:caseExactOrderingMatch"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -410,62 +350,25 @@
expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
-
-
/**
* Tests performing an internal search using the server-side sort control to
* sort the entries in order of descending givenName values.
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchGivenNameDescending()
- throws Exception
+ @Test
+ public void testInternalSearchGivenNameDescending() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("-givenName"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("-givenName"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -479,31 +382,9 @@
expectedDNOrder.add(aaccfJohnsonDN); // Aaccf
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
@@ -515,28 +396,15 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchGivenNameDescendingCaseExact()
- throws Exception
+ @Test
+ public void testInternalSearchGivenNameDescendingCaseExact() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("-givenName:caseExactOrderingMatch"));
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl(
- "-givenName:caseExactOrderingMatch"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -550,31 +418,9 @@
expectedDNOrder.add(aaccfJohnsonDN); // Aaccf
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
@@ -585,27 +431,14 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchGivenNameAscendingSnAscending()
- throws Exception
+ @Test
+ public void testInternalSearchGivenNameAscendingSnAscending() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName,sn"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName,sn"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -619,62 +452,26 @@
expectedDNOrder.add(samZweckDN); // Sam
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
-
-
/**
* Tests performing an internal search using the server-side sort control to
* sort the entries in order of ascending givenName and descending sn values.
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchGivenNameAscendingSnDescending()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName,-sn"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName,-sn"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -688,62 +485,25 @@
expectedDNOrder.add(samZweckDN); // Sam
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
- assertEquals(returnedDNOrder, expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 1);
-
- ServerSideSortResponseControl responseControl;
- Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
- {
- responseControl = (ServerSideSortResponseControl)c;
- }
- else
- {
- responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- assertEquals(responseControl.getResultCode(), 0);
- assertNull(responseControl.getAttributeType());
- responseControl.toString();
+ assertNoAttributeTypeForSort(internalSearch);
}
-
-
/**
* Tests performing an internal search using the CRITICAL server-side sort control with
* an undefined attribute type.
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testCriticalSortWithUndefinedAttribute()
- throws Exception
+ @Test
+ public void testCriticalSortWithUndefinedAttribute() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl(true, "undefined"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl(true, "undefined"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.UNAVAILABLE_CRITICAL_EXTENSION);
}
@@ -755,28 +515,14 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchUndefinedOrderingRule()
- throws Exception
+ @Test
+ public void testInternalSearchUndefinedOrderingRule() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl(true,
- "givenName:undefinedOrderingMatch"));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl(true, "givenName:undefinedOrderingMatch"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertFalse(internalSearch.getResultCode() == ResultCode.SUCCESS);
}
@@ -787,45 +533,56 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testNonCriticalSortWithUndefinedAttribute()
- throws Exception
+ @Test
+ public void testNonCriticalSortWithUndefinedAttribute() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl(false,
- "bad_sort:caseExactOrderingMatch"));
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl(false, "bad_sort:caseExactOrderingMatch"));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
+ assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
+ ServerSideSortResponseControl responseControl = getServerSideSortResponseControl(internalSearch);
+ assertEquals(responseControl.getResultCode(), 16);
+ }
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
+ private void assertNoAttributeTypeForSort(InternalSearchOperation internalSearch) throws Exception
+ {
+ ServerSideSortResponseControl responseControl = getServerSideSortResponseControl(internalSearch);
+ assertEquals(responseControl.getResultCode(), ResultCode.SUCCESS.intValue());
+ assertNull(responseControl.getAttributeType());
+ responseControl.toString();
+ }
- internalSearch.run();
- assertEquals(internalSearch.getResultCode(),
- ResultCode.SUCCESS);
+ private ServerSideSortResponseControl getServerSideSortResponseControl(InternalSearchOperation internalSearch)
+ throws Exception
+ {
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
assertEquals(responseControls.size(), 1);
- ServerSideSortResponseControl responseControl;
+ return getServerSideSortResponseControl(responseControls);
+ }
+
+ private ServerSideSortResponseControl getServerSideSortResponseControl(List<Control> responseControls)
+ throws DirectoryException
+ {
Control c = responseControls.get(0);
- if(c instanceof ServerSideSortResponseControl)
+ if (c instanceof ServerSideSortResponseControl)
{
- responseControl = (ServerSideSortResponseControl)c;
+ return (ServerSideSortResponseControl) c;
}
- else
+ return ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue());
+ }
+
+ private ArrayList<DN> getDNs(LinkedList<SearchResultEntry> searchEntries)
+ {
+ ArrayList<DN> results = new ArrayList<DN>();
+ for (Entry e : searchEntries)
{
- responseControl = ServerSideSortResponseControl.DECODER.decode(
- c.isCritical(), ((LDAPControl)c).getValue());
+ results.add(e.getName());
}
- assertEquals(responseControl.getResultCode(), 16);
+ return results;
}
}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
index b2a60c5..dbc7dc6 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/controls/VLVControlTestCase.java
@@ -27,6 +27,7 @@
package org.opends.server.controls;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.forgerock.opendj.io.ASN1;
@@ -34,19 +35,20 @@
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ResultCode;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -234,7 +236,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor1()
throws Exception
{
@@ -260,7 +262,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor2NullContextID()
throws Exception
{
@@ -286,7 +288,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor2NonNullContextID()
throws Exception
{
@@ -312,7 +314,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor3()
throws Exception
{
@@ -338,7 +340,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor4NullContextID()
throws Exception
{
@@ -364,7 +366,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRequestConstructor4NonNullContextID()
throws Exception
{
@@ -388,7 +390,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testASN1ValueEncoding()
throws Exception
{
@@ -424,7 +426,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testResponseConstructor1()
throws Exception
{
@@ -446,7 +448,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testResponseConstructor2NullContextID()
throws Exception
{
@@ -468,7 +470,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testResponseConstructor2NonNullContextID()
throws Exception
{
@@ -491,28 +493,15 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchByOffsetOneOffset()
- throws Exception
+ @Test
+ public void testInternalSearchByOffsetOneOffset() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, 1, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, 1, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -521,13 +510,7 @@
expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -539,26 +522,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -584,28 +552,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByOffsetZeroOffset()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, 0, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, 0, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -614,13 +570,7 @@
expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -632,26 +582,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -677,28 +612,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByOffsetThreeOffset()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, 3, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, 3, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -707,13 +630,7 @@
expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
expectedDNOrder.add(margaretJonesDN); // Maggie
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -725,26 +642,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -769,28 +671,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByOffsetNegativeOffset()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, -1, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, -1, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
// It will be successful because it's not a critical control.
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
@@ -798,23 +688,7 @@
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
- }
- }
-
- assertNotNull(vlvResponse);
+ VLVResponseControl vlvResponse = getVLVResponseControl(responseControls);
assertEquals(vlvResponse.getVLVResultCode(),
LDAPResultCode.OFFSET_RANGE_ERROR);
}
@@ -827,28 +701,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByOffsetNegativeStartPosition()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(3, 3, 1, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(3, 3, 1, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
// It will be successful because it's not a critical control.
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
@@ -856,23 +718,7 @@
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
- }
- }
-
- assertNotNull(vlvResponse);
+ VLVResponseControl vlvResponse = getVLVResponseControl(responseControls);
assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS);
}
@@ -884,29 +730,15 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchByOffsetStartPositionTooHigh()
- throws Exception
+ @Test
+ public void testInternalSearchByOffsetStartPositionTooHigh() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(3, 3, 30, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
-
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(3, 3, 30, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -914,34 +746,12 @@
expectedDNOrder.add(samZweckDN); // Sam
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
- }
- }
-
- assertNotNull(vlvResponse);
+ VLVResponseControl vlvResponse = getVLVResponseControl(responseControls);
assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS);
assertEquals(vlvResponse.getTargetPosition(), 10);
assertEquals(vlvResponse.getContentCount(), 9);
@@ -956,28 +766,15 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchByOffsetIncompleteAfterCount()
- throws Exception
+ @Test
+ public void testInternalSearchByOffsetIncompleteAfterCount() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, 7, 0));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, 7, 0));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -985,13 +782,7 @@
expectedDNOrder.add(samZweckDN); // Sam
expectedDNOrder.add(zorroDN); // No first name
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -1003,26 +794,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -1048,28 +824,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByValueBeforeAll()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3, ByteString.valueOf("a")));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("a")));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -1078,13 +842,7 @@
expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -1096,26 +854,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -1141,29 +884,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByValueMatchesFirst()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3,
- ByteString.valueOf("aaccf")));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("aaccf")));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -1172,11 +902,7 @@
expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ ArrayList<DN> returnedDNOrder = getDNs(internalSearch.getSearchEntries());
assertEquals(returnedDNOrder, expectedDNOrder);
@@ -1190,26 +916,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -1235,29 +946,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByValueMatchesThird()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(0, 3,
- ByteString.valueOf("albert")));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("albert")));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -1266,11 +964,7 @@
expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
expectedDNOrder.add(margaretJonesDN); // Maggie
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
+ ArrayList<DN> returnedDNOrder = getDNs(internalSearch.getSearchEntries());
assertEquals(returnedDNOrder, expectedDNOrder);
@@ -1284,26 +978,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -1329,29 +1008,16 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
+ @Test
public void testInternalSearchByValueMatchesThirdWithBeforeCount()
throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("givenName"));
- requestControls.add(new VLVRequestControl(1, 3,
- ByteString.valueOf("albert")));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("givenName"))
+ .addControl(new VLVRequestControl(1, 3, ByteString.valueOf("albert")));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
ArrayList<DN> expectedDNOrder = new ArrayList<DN>();
@@ -1361,13 +1027,7 @@
expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
expectedDNOrder.add(margaretJonesDN); // Maggie
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
-
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder);
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
@@ -1379,26 +1039,11 @@
{
if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- sortResponse =
- ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- sortResponse = (ServerSideSortResponseControl)c;
- }
+ sortResponse = getServerSideSortResponseControl(c);
}
else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
{
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
+ vlvResponse = getVLVResponseControl(c);
}
else
{
@@ -1415,7 +1060,15 @@
assertEquals(vlvResponse.getContentCount(), 9);
}
-
+ private ArrayList<DN> getDNs(LinkedList<SearchResultEntry> entries)
+ {
+ ArrayList<DN> results = new ArrayList<DN>();
+ for (Entry e : entries)
+ {
+ results.add(e.getName());
+ }
+ return results;
+ }
/**
* Tests performing an internal search using the VLV control to retrieve a
@@ -1424,28 +1077,15 @@
*
* @throws Exception If an unexpected problem occurred.
*/
- @Test()
- public void testInternalSearchByValueAfterAll()
- throws Exception
+ @Test
+ public void testInternalSearchByValueAfterAll() throws Exception
{
populateDB();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- ArrayList<Control> requestControls = new ArrayList<Control>();
- requestControls.add(new ServerSideSortRequestControl("sn"));
- requestControls.add(new VLVRequestControl(0, 3, ByteString.valueOf("zz")));
-
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(objectClass=person)"),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)")
+ .addControl(new ServerSideSortRequestControl("sn"))
+ .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("zz")));
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
// It will be successful because the control isn't critical.
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
@@ -1453,27 +1093,41 @@
List<Control> responseControls = internalSearch.getResponseControls();
assertNotNull(responseControls);
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- if(c instanceof LDAPControl)
- {
- vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue());
- }
- else
- {
- vlvResponse = (VLVResponseControl)c;
- }
- }
- }
-
- assertNotNull(vlvResponse);
+ VLVResponseControl vlvResponse = getVLVResponseControl(responseControls);
assertEquals(vlvResponse.getVLVResultCode(),
LDAPResultCode.SUCCESS);
assertEquals(vlvResponse.getTargetPosition(), 10);
assertEquals(vlvResponse.getContentCount(), 9);
}
-}
+ private ServerSideSortResponseControl getServerSideSortResponseControl(Control c) throws DirectoryException
+ {
+ if (c instanceof LDAPControl)
+ {
+ return ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue());
+ }
+ return (ServerSideSortResponseControl) c;
+ }
+
+ private VLVResponseControl getVLVResponseControl(List<Control> responseControls) throws DirectoryException
+ {
+ for (Control c : responseControls)
+ {
+ if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
+ {
+ return getVLVResponseControl(c);
+ }
+ }
+ fail("Expected to find VLVResponseControl");
+ return null;
+ }
+
+ private VLVResponseControl getVLVResponseControl(Control c) throws DirectoryException
+ {
+ if (c instanceof LDAPControl)
+ {
+ return VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue());
+ }
+ return (VLVResponseControl) c;
+ }
+}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/GroupManagerTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/GroupManagerTestCase.java
index 3e42541..74a365d 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/GroupManagerTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/core/GroupManagerTestCase.java
@@ -33,10 +33,9 @@
import java.util.List;
import java.util.Set;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-import org.testng.annotations.AfterClass;
-
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.std.server.GroupImplementationCfg;
import org.opends.server.api.Group;
@@ -45,28 +44,28 @@
import org.opends.server.extensions.VirtualStaticGroup;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
-import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.MemberList;
import org.opends.server.types.MembershipException;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
import org.opends.server.types.RDN;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.SearchFilter;
-import org.forgerock.opendj.ldap.SearchScope;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
-
/**
* A set of test cases that involve the use of groups and the Directory Server
* Group Manager.
@@ -241,8 +240,7 @@
Entry user4Entry = DirectoryServer.getEntry(user4DN);
Entry user5Entry = DirectoryServer.getEntry(user5DN);
Group<? extends GroupImplementationCfg> group1Instance =
- (Group<? extends GroupImplementationCfg>)
- groupManager.getGroupInstance(group1DN);
+ groupManager.getGroupInstance(group1DN);
assertNotNull(group1Instance);
//Add even numbered groups.
group1Instance.addNestedGroup(group2DN);
@@ -321,16 +319,11 @@
addNestedGroupTestEntries();
DN group1DN = DN.valueOf("cn=group 1,ou=Groups,o=test");
DN group2DN = DN.valueOf("cn=group 2,ou=Groups,o=test");
- DN group3DN = DN.valueOf("cn=group 3,ou=Groups,o=test");
- DN group4DN = DN.valueOf("cn=group 4,ou=Groups,o=test");
DN user1DN = DN.valueOf("uid=user.1,ou=People,o=test");
Entry user1Entry = DirectoryServer.getEntry(user1DN);
Group<? extends GroupImplementationCfg> group1Instance =
- (Group<? extends GroupImplementationCfg>)
- groupManager.getGroupInstance(group1DN);
- Group<? extends GroupImplementationCfg> group2Instance =
- (Group<? extends GroupImplementationCfg>)
- groupManager.getGroupInstance(group2DN);
+ groupManager.getGroupInstance(group1DN);
+ groupManager.getGroupInstance(group2DN);
assertNotNull(group1Instance);
//Add some nested groups and members.
group1Instance.addNestedGroup(group2DN);
@@ -353,9 +346,8 @@
assertTrue(nestedGroups.isEmpty());
try
{
- MemberList memberList=group1Instance.getMembers();
- throw new AssertionError("Expected getMembers to fail but " +
- "it didn't");
+ group1Instance.getMembers();
+ fail("getMembers)() should have thrown a DirectoryException");
} catch (DirectoryException ex) {}
}
@@ -390,11 +382,9 @@
//compile warning in the getNestedGroupDNs calls below. Some IDEs
//will give a unchecked cast warning.
Group<? extends GroupImplementationCfg> group1Instance =
- (Group<? extends GroupImplementationCfg>)
- groupManager.getGroupInstance(group1DN);
+ groupManager.getGroupInstance(group1DN);
Group<? extends GroupImplementationCfg> group2Instance =
- (Group<? extends GroupImplementationCfg>)
- groupManager.getGroupInstance(group2DN);
+ groupManager.getGroupInstance(group2DN);
Group group3Instance = groupManager.getGroupInstance(group3DN);
assertNotNull(group1Instance);
assertNotNull(group2Instance);
@@ -1415,11 +1405,7 @@
// Get a client connection authenticated as user1 and make sure it handles
// group operations correctly.
InternalClientConnection conn0 = new InternalClientConnection(DN.rootDN());
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn0, nextOperationID(), nextMessageID(), null,
- DN.rootDN(), SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null, null);
+ InternalSearchOperation searchOperation = createSearchOperation(conn0);
assertFalse(conn0.isMemberOf(group1, null));
assertFalse(conn0.isMemberOf(group2, null));
@@ -1439,12 +1425,7 @@
// Get a client connection authenticated as user1 and make sure it handles
// group operations correctly.
InternalClientConnection conn1 = new InternalClientConnection(user1DN);
- searchOperation =
- new InternalSearchOperation(conn1, nextOperationID(),
- nextMessageID(), null, DN.rootDN(),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null, null);
+ searchOperation = createSearchOperation(conn1);
assertTrue(conn1.isMemberOf(group1, null));
assertFalse(conn1.isMemberOf(group2, null));
@@ -1468,12 +1449,7 @@
// Get a client connection authenticated as user2 and make sure it handles
// group operations correctly.
InternalClientConnection conn2 = new InternalClientConnection(user2DN);
- searchOperation =
- new InternalSearchOperation(conn2, nextOperationID(),
- nextMessageID(), null, DN.rootDN(),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null, null);
+ searchOperation = createSearchOperation(conn2);
assertTrue(conn2.isMemberOf(group1, null));
assertTrue(conn2.isMemberOf(group2, null));
@@ -1497,12 +1473,7 @@
// Get a client connection authenticated as user3 and make sure it handles
// group operations correctly.
InternalClientConnection conn3 = new InternalClientConnection(user3DN);
- searchOperation =
- new InternalSearchOperation(conn3, nextOperationID(),
- nextMessageID(), null, DN.rootDN(),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null, null);
+ searchOperation = createSearchOperation(conn3);
assertFalse(conn3.isMemberOf(group1, null));
assertTrue(conn3.isMemberOf(group2, null));
@@ -1544,7 +1515,11 @@
assertNull(groupManager.getGroupInstance(group3DN));
}
-
+ private InternalSearchOperation createSearchOperation(InternalClientConnection conn)
+ {
+ final SearchRequest request = newSearchRequest(DN.rootDN(), SearchScope.BASE_OBJECT);
+ return new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request);
+ }
/**
* Tests operations involving static group member lists.
@@ -2037,7 +2012,6 @@
DN groupDN = DN.valueOf("cn=Test Group of URLs,ou=Groups,o=test");
DN user1DN = DN.valueOf("uid=user.1,ou=People,o=test");
- DN user2DN = DN.valueOf("uid=user.2,ou=People,o=test");
Group groupInstance = groupManager.getGroupInstance(groupDN);
assertNotNull(groupInstance);
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/EntryDNVirtualAttributeProviderTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/EntryDNVirtualAttributeProviderTestCase.java
index ec8f3c1..ba3723f 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/EntryDNVirtualAttributeProviderTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/EntryDNVirtualAttributeProviderTestCase.java
@@ -32,16 +32,13 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn;
import org.opends.server.api.VirtualAttributeProvider;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
-import static org.opends.server.protocols.internal.Requests.*;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.*;
import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation;
@@ -50,6 +47,7 @@
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -641,17 +639,9 @@
VirtualAttributeRule rule = getRule(provider);
- SearchFilter filter = SearchFilter.createFilterFromString(filterString);
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, null, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
// This attribute is searchable for either pre-indexed or not
assertEquals(provider.isSearchable(rule, searchOperation, false),
isSearchable);
@@ -688,30 +678,13 @@
VirtualAttributeRule rule = getRule(provider);
- SearchFilter filter = SearchFilter.createFilterFromString(filterString);
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null,
- DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, null, null);
- LocalBackendSearchOperation localSearch =
- new LocalBackendSearchOperation(searchOperation);
-
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
+ LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(searchOperation);
provider.processSearch(rule, localSearch);
- if (shouldMatch)
- {
- assertEquals(searchOperation.getSearchEntries().size(), 1);
- }
- else
- {
- assertEquals(searchOperation.getSearchEntries().size(), 0);
- }
+ assertEquals(searchOperation.getSearchEntries().size(), shouldMatch ? 1 : 0);
}
}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/HasSubordinatesVirtualAttributeProviderTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/HasSubordinatesVirtualAttributeProviderTestCase.java
index 21916d6..96960a8 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/HasSubordinatesVirtualAttributeProviderTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/HasSubordinatesVirtualAttributeProviderTestCase.java
@@ -26,27 +26,28 @@
*/
package org.opends.server.extensions;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.Requests;
import org.opends.server.protocols.internal.SearchRequest;
-import static org.opends.server.protocols.internal.Requests.*;
import org.opends.server.protocols.ldap.LDAPControl;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import static org.testng.Assert.*;
@@ -424,22 +425,12 @@
public void testSearchhasSubordinatesAttrVirtualAttrsOnly(DN entryDN, boolean hasSubs)
throws Exception
{
- SearchFilter filter = SearchFilter.objectClassPresent();
- LinkedHashSet<String> attrList = new LinkedHashSet<String>(1);
- attrList.add("hasSubordinates");
+ SearchRequest request = Requests.newSearchRequest(entryDN, SearchScope.BASE_OBJECT)
+ .addAttribute("hasSubordinates")
+ .addControl(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true));
- LinkedList<Control> requestControls = new LinkedList<Control>();
- requestControls.add(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true));
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- entryDN, SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, attrList, null);
- searchOperation.run();
+ InternalClientConnection conn = getRootConnection();
+ InternalSearchOperation searchOperation = conn.processSearch(request);
assertEquals(searchOperation.getSearchEntries().size(), 1);
Entry e = searchOperation.getSearchEntries().get(0);
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/IsMemberOfVirtualAttributeProviderTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/IsMemberOfVirtualAttributeProviderTestCase.java
index 4d3afb7..0a7946c 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/IsMemberOfVirtualAttributeProviderTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/IsMemberOfVirtualAttributeProviderTestCase.java
@@ -26,10 +26,13 @@
*/
package org.opends.server.extensions;
-import java.util.*;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
+import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn;
@@ -37,14 +40,11 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
-import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
-import org.opends.server.types.Control;
import org.opends.server.types.DN;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.opends.server.types.Entry;
-import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.types.SearchFilter;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.types.VirtualAttributeRule;
@@ -53,15 +53,18 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
/**
* A set of test cases for the isMemberOf virtual attribute provider.
*/
+@SuppressWarnings("javadoc")
public class IsMemberOfVirtualAttributeProviderTestCase
extends ExtensionsTestCase
{
- // The attribute type for the isMemberOf attribute.
+ /** The attribute type for the isMemberOf attribute. */
private AttributeType isMemberOfType;
@@ -71,9 +74,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @BeforeClass()
- public void startServer()
- throws Exception
+ @BeforeClass
+ public void startServer() throws Exception
{
TestCaseUtils.restartServer();
@@ -89,7 +91,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testStaticGroupMembershipMember()
throws Exception
{
@@ -137,10 +139,8 @@
assertFalse(a.contains(ByteString.valueOf("invalid")));
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf("cn=test static group,ou=groups,o=test"));
+ getRootConnection().processDelete(DN.valueOf("cn=test static group,ou=groups,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
@@ -153,9 +153,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testStaticGroupMembershipUniqueMember()
- throws Exception
+ @Test
+ public void testStaticGroupMembershipUniqueMember() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
@@ -201,10 +200,8 @@
assertFalse(a.contains(ByteString.valueOf("invalid")));
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf("cn=test static group,ou=groups,o=test"));
+ getRootConnection().processDelete(DN.valueOf("cn=test static group,ou=groups,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
@@ -216,9 +213,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testDynamicGroupMembership()
- throws Exception
+ @Test
+ public void testDynamicGroupMembership() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
@@ -264,11 +260,8 @@
assertFalse(a.contains(ByteString.valueOf("invalid")));
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
DeleteOperation deleteOperation =
- conn.processDelete(
- DN.valueOf("cn=test dynamic group,ou=groups,o=test"));
+ getRootConnection().processDelete(DN.valueOf("cn=test dynamic group,ou=groups,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
@@ -280,9 +273,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testMultipleStaticGroups()
- throws Exception
+ @Test
+ public void testMultipleStaticGroups() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
@@ -354,8 +346,7 @@
assertFalse(a.contains(ByteString.valueOf("invalid")));
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
DeleteOperation deleteOperation =
conn.processDelete(DN.valueOf("cn=test group 1,ou=groups,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
@@ -377,9 +368,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testMultipleGroups()
- throws Exception
+ @Test
+ public void testMultipleGroups() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
@@ -472,8 +462,7 @@
assertFalse(a.contains(ByteString.valueOf("invalid")));
}
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
DeleteOperation deleteOperation =
conn.processDelete(DN.valueOf("cn=test group 1,ou=groups,o=test"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
@@ -504,7 +493,7 @@
/**
* Tests the {@code isMultiValued} method.
*/
- @Test()
+ @Test
public void testIsMultiValued()
{
IsMemberOfVirtualAttributeProvider provider =
@@ -520,7 +509,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testMatchesSubstring()
throws Exception
{
@@ -557,7 +546,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testGreaterThanOrEqualTo()
throws Exception
{
@@ -592,7 +581,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testLessThanOrEqualTo()
throws Exception
{
@@ -627,7 +616,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testApproximatelyEqualTo()
throws Exception
{
@@ -676,42 +665,28 @@
new Object[] { "(isMemberOf=*)", false, false },
new Object[] { "(isMemberOf=cn*)", false, false },
new Object[] { "(isMemberOf=invalid)", true, false },
- new Object[] { "(&(isMemberOf=invalid1)(isMemberOf=invalid2))",
- true, false },
- new Object[] { "(isMemberOf>=cn=Test Group 1,ou=Groups,o=test)",
- false, false },
- new Object[] { "(isMemberOf<=cn=Test Group 1,ou=Groups,o=test)",
- false, false },
- new Object[] { "(isMemberOf~=cn=Test Group 1,ou=Groups,o=test)",
- false, false },
- new Object[] { "(isMemberOf=cn=Test Group 1,ou=Groups,o=test)",
- true, true },
- new Object[] { "(isMemberOf=cn=Test Group 2,ou=Groups,o=test)",
- true, false },
+ new Object[] { "(&(isMemberOf=invalid1)(isMemberOf=invalid2))", true, false },
+ new Object[] { "(isMemberOf>=cn=Test Group 1,ou=Groups,o=test)", false, false },
+ new Object[] { "(isMemberOf<=cn=Test Group 1,ou=Groups,o=test)", false, false },
+ new Object[] { "(isMemberOf~=cn=Test Group 1,ou=Groups,o=test)", false, false },
+ new Object[] { "(isMemberOf=cn=Test Group 1,ou=Groups,o=test)", true, true },
+ new Object[] { "(isMemberOf=cn=Test Group 2,ou=Groups,o=test)", true, false },
new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(givenName=test))",
- true, true },
+ "(givenName=test))", true, true },
new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(isMemberOf=invalid))",
- true, false },
+ "(isMemberOf=invalid))", true, false },
new Object[] { "(&(isMemberOf=invalid)" +
- "(isMemberOf=cn=Test Group 1,ou=Groups,o=test))",
- true, false },
+ "(isMemberOf=cn=Test Group 1,ou=Groups,o=test))", true, false },
new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(givenName=not test))",
- true, false },
+ "(givenName=not test))", true, false },
new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(isMemberOf=cn=Test Group 2,ou=Groups,o=test))",
- true, false },
+ "(isMemberOf=cn=Test Group 2,ou=Groups,o=test))", true, false },
new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))",
- true, true },
+ "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", true, true },
new Object[] { "(&(isMemberOf=cn=Test Group 2,ou=Groups,o=test)" +
- "(isMemberOf=cn=Test Group 4,ou=Groups,o=test))",
- true, false },
+ "(isMemberOf=cn=Test Group 4,ou=Groups,o=test))", true, false },
new Object[] { "(|(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" +
- "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))",
- false, false },
+ "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", false, false },
};
}
@@ -745,20 +720,9 @@
VirtualAttributeCfgDefn.ConflictBehavior.
VIRTUAL_OVERRIDES_REAL);
- SearchFilter filter = SearchFilter.createFilterFromString(filterString);
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
- null,
- DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, null, null);
-
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString);
+ InternalSearchOperation searchOperation = new InternalSearchOperation(
+ getRootConnection(), nextOperationID(), nextMessageID(), request, null);
assertEquals(provider.isSearchable(rule,
new LocalBackendSearchOperation(searchOperation), false), isSearchable);
// isMemberOf is not searchable with preIndexed set to true
@@ -877,19 +841,10 @@
VirtualAttributeCfgDefn.ConflictBehavior.
VIRTUAL_OVERRIDES_REAL);
- SearchFilter filter = SearchFilter.createFilterFromString(filterString);
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
- null,
- DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, null, null);
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString);
+ InternalClientConnection conn = getRootConnection();
+ InternalSearchOperation searchOperation = new InternalSearchOperation(
+ conn, nextOperationID(), nextMessageID(), request, null);
provider.processSearch(rule, new LocalBackendSearchOperation(searchOperation));
boolean matchFound = false;
@@ -933,7 +888,7 @@
* Tests if a search using ismemberof works for a dynamic group with large
* number of entries to simulate unindexed searches.
*/
- @Test()
+ @Test
public void testLargeDynamicGroupMembership() throws Exception
{
String SUFFIX=",dc=example,dc=com";
@@ -972,26 +927,15 @@
DirectoryServer.getEntry(DN.valueOf("cn=user.0,ou=People"+SUFFIX));
assertNotNull(e);
//Do an ldapsearch.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
- new ArrayList<Control>(),
- ByteString.valueOf("dc=example,dc=com"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER,
- Integer.MAX_VALUE,
- Integer.MAX_VALUE,
- false,
- LDAPFilter.decode("(&(objectclass=Person)" +
- "(isMemberOf=cn=MyDGrp,ou=groups,dc=example,dc=com))"),
- null, null);
- searchOperation.run();
+ String filter = "(&(objectclass=Person)"
+ + "(isMemberOf=cn=MyDGrp,ou=groups,dc=example,dc=com))";
+ SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, filter)
+ .setTimeLimit(Integer.MAX_VALUE)
+ .setSizeLimit(Integer.MAX_VALUE);
+
+ InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
List<SearchResultEntry> entries = searchOperation.getSearchEntries();
assertTrue(entries.size()>4000);
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/StructuralObjectClassVirtualAttributeProviderTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/StructuralObjectClassVirtualAttributeProviderTestCase.java
index 47c6dbd..df34a90 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/StructuralObjectClassVirtualAttributeProviderTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/StructuralObjectClassVirtualAttributeProviderTestCase.java
@@ -27,24 +27,18 @@
package org.opends.server.extensions;
import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
-import static org.opends.server.protocols.internal.Requests.*;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
-import org.opends.server.types.Control;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.SearchFilter;
@@ -54,6 +48,7 @@
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -337,23 +332,10 @@
public void testSearchStructuralOCAttrRealAttrsOnly(DN entryDN)
throws Exception
{
- SearchFilter filter = SearchFilter.objectClassPresent();
- LinkedHashSet<String> attrList = new LinkedHashSet<String>(1);
- attrList.add("structuralObjectClass");
-
- LinkedList<Control> requestControls = new LinkedList<Control>();
- requestControls.add(new LDAPControl(OID_REAL_ATTRS_ONLY, true));
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection
- .nextOperationID(), InternalClientConnection
- .nextMessageID(), requestControls, entryDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false, filter,
- attrList, null);
- searchOperation.run();
+ SearchRequest request = newSearchRequest(entryDN, SearchScope.BASE_OBJECT)
+ .addAttribute("structuralObjectClass")
+ .addControl(new LDAPControl(OID_REAL_ATTRS_ONLY, true));
+ InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
assertEquals(searchOperation.getSearchEntries().size(), 1);
Entry e = searchOperation.getSearchEntries().get(0);
@@ -377,23 +359,11 @@
public void testSearchStructuralOCAttrVirtualAttrsOnly(DN entryDN)
throws Exception
{
- SearchFilter filter = SearchFilter.objectClassPresent();
- LinkedHashSet<String> attrList = new LinkedHashSet<String>(1);
- attrList.add("structuralObjectClass");
+ SearchRequest request = newSearchRequest(entryDN, SearchScope.BASE_OBJECT)
+ .addAttribute("structuralObjectClass")
+ .addControl(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true));
- LinkedList<Control> requestControls = new LinkedList<Control>();
- requestControls.add(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true));
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection
- .nextOperationID(), InternalClientConnection
- .nextMessageID(), requestControls, entryDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false, filter,
- attrList, null);
- searchOperation.run();
+ InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
assertEquals(searchOperation.getSearchEntries().size(), 1);
Entry e = searchOperation.getSearchEntries().get(0);
@@ -406,7 +376,7 @@
/**
* Tests the {@code isMultiValued} method.
*/
- @Test()
+ @Test
public void testIsMultiValued()
{
StructuralObjectClassVirtualAttributeProvider provider =
@@ -421,7 +391,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testGetValues() throws Exception
{
StructuralObjectClassVirtualAttributeProvider provider =
@@ -456,9 +426,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testHasAnyValue()
- throws Exception
+ @Test
+ public void testHasAnyValue() throws Exception
{
StructuralObjectClassVirtualAttributeProvider provider =
new StructuralObjectClassVirtualAttributeProvider();
@@ -489,9 +458,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testHasMatchingValue()
- throws Exception
+ @Test
+ public void testHasMatchingValue() throws Exception
{
StructuralObjectClassVirtualAttributeProvider provider =
new StructuralObjectClassVirtualAttributeProvider();
@@ -523,9 +491,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testHasNonMatchingValue()
- throws Exception
+ @Test
+ public void testHasNonMatchingValue() throws Exception
{
StructuralObjectClassVirtualAttributeProvider provider =
new StructuralObjectClassVirtualAttributeProvider();
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/TraditionalWorkQueueTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/TraditionalWorkQueueTestCase.java
index 1a3e64c..fc67323 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/TraditionalWorkQueueTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/TraditionalWorkQueueTestCase.java
@@ -28,12 +28,11 @@
-import static org.testng.Assert.*;
-
import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
+import org.forgerock.opendj.ldap.ModificationType;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.api.WorkQueue;
import org.opends.server.core.DirectoryServer;
@@ -41,21 +40,18 @@
import org.opends.server.plugins.DelayPreOpPlugin;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.Attributes;
-import org.opends.server.types.Control;
import org.opends.server.types.DN;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.opends.server.types.Modification;
-import org.forgerock.opendj.ldap.ModificationType;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.opends.server.types.SearchFilter;
-import org.forgerock.opendj.ldap.SearchScope;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
+import static org.testng.Assert.*;
/**
* A set of test cases for the traditional work queue.
@@ -68,9 +64,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @BeforeClass()
- public void startServer()
- throws Exception
+ @BeforeClass
+ public void startServer() throws Exception
{
TestCaseUtils.startServer();
}
@@ -81,10 +76,10 @@
* Tests to ensure that the work queue is configured and enabled within the
* Directory Server.
*/
- @Test()
+ @Test
public void testWorkQueueEnabled()
{
- WorkQueue workQueue = DirectoryServer.getWorkQueue();
+ WorkQueue<?> workQueue = DirectoryServer.getWorkQueue();
assertNotNull(workQueue);
assertTrue(workQueue instanceof TraditionalWorkQueue);
}
@@ -106,8 +101,7 @@
mods.add(new Modification(ModificationType.REPLACE,
Attributes.create(attr, "30")));
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
ModifyOperation modifyOperation = conn.processModify(dn, mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
@@ -191,19 +185,10 @@
{
TestCaseUtils.initializeTestBackend(true);
- List<Control> requestControls = DelayPreOpPlugin.createDelayControlList(5000);
- SearchFilter filter = SearchFilter.objectClassPresent();
- LinkedHashSet<String> attrs = new LinkedHashSet<String>();
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT)
+ .addControl(DelayPreOpPlugin.createDelayControlList(5000));
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),requestControls,
- DN.valueOf("o=test"),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, attrs, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
DirectoryServer.getWorkQueue().submitOperation(searchOperation);
long startTime = System.currentTimeMillis();
@@ -212,8 +197,6 @@
assertTrue((stopTime - startTime) >= 4000);
}
-
-
/**
* Tests the {@code WorkQueue.waitUntilIdle()} method for a case in which the
* work queue should not be idle for several seconds.
@@ -226,19 +209,10 @@
{
TestCaseUtils.initializeTestBackend(true);
- List<Control> requestControls = DelayPreOpPlugin.createDelayControlList(5000);
- SearchFilter filter = SearchFilter.objectClassPresent();
- LinkedHashSet<String> attrs = new LinkedHashSet<String>();
-
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT)
+ .addControl(DelayPreOpPlugin.createDelayControlList(5000));
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("o=test"),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0,
- 0, false, filter, attrs, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
DirectoryServer.getWorkQueue().submitOperation(searchOperation);
long startTime = System.currentTimeMillis();
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java
index ffac805..afd9262 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java
@@ -29,7 +29,6 @@
import java.util.List;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
@@ -37,9 +36,13 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.Requests;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.DN;
+import org.opends.server.types.VirtualAttributeRule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -53,17 +56,16 @@
public class UserDefinedVirtualAttributeProviderTestCase
extends ExtensionsTestCase
{
- // The attribute type for the description attribute.
+ /** The attribute type for the description attribute. */
private AttributeType descriptionType;
- // The attribute type for the ds-privilege-name attribute.
+ /** The attribute type for the ds-privilege-name attribute. */
private AttributeType privNameType;
- // The attribute type for the ds-pwp-password-policy-dn attribute.
+ /** The attribute type for the ds-pwp-password-policy-dn attribute. */
private AttributeType pwPolicyDNType;
-
/**
* Ensures that the Directory Server is running.
*
@@ -94,7 +96,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRuleAPISingleValued()
throws Exception
{
@@ -112,20 +114,13 @@
"ds-cfg-conflict-behavior: real-overrides-virtual",
"ds-cfg-value: single value");
- InternalClientConnection conn = getRootConnection();
try
{
+ SearchRequest request = Requests.newSearchRequest(DN.valueOf(ruleDN), SearchScope.BASE_OBJECT);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection
- .nextOperationID(), InternalClientConnection
- .nextMessageID(), null, DN.valueOf(ruleDN),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(),
- null, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
- for (VirtualAttributeRule rule : DirectoryServer
- .getVirtualAttributes())
+ for (VirtualAttributeRule rule : DirectoryServer.getVirtualAttributes())
{
if (rule.getAttributeType().equals(descriptionType))
{
@@ -141,12 +136,10 @@
ResultCode.UNWILLING_TO_PERFORM);
}
}
-
}
finally
{
- DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf(ruleDN));
+ DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
}
@@ -159,7 +152,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testRuleAPIMultiValued()
throws Exception
{
@@ -178,20 +171,13 @@
"ds-cfg-value: first value",
"ds-cfg-value: second value");
- InternalClientConnection conn = getRootConnection();
try
{
+ SearchRequest request = Requests.newSearchRequest(DN.valueOf(ruleDN), SearchScope.BASE_OBJECT);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection
- .nextOperationID(), InternalClientConnection
- .nextMessageID(), null, DN.valueOf(ruleDN),
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(),
- null, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
- for (VirtualAttributeRule rule : DirectoryServer
- .getVirtualAttributes())
+ for (VirtualAttributeRule rule : DirectoryServer.getVirtualAttributes())
{
if (rule.getAttributeType().equals(descriptionType))
{
@@ -210,21 +196,18 @@
}
finally
{
- DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf(ruleDN));
+ DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
}
-
-
/**
* Tests the creation of a description virtual attribute when there is only a
* single virtual value and no real value.
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testSingleDescriptionOnlyVirtual()
throws Exception
{
@@ -290,7 +273,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testMultipleDescriptionsOnlyVirtual()
throws Exception
{
@@ -359,7 +342,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testSingleDescriptionRealOverridesVirtual()
throws Exception
{
@@ -427,7 +410,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testSingleDescriptionVirtualOverridesReal()
throws Exception
{
@@ -494,7 +477,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testSingleDescriptionMergeRealAndVirtual()
throws Exception
{
@@ -569,7 +552,7 @@
* @throws Exception
* If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testSingleDescriptionMergeRealAndVirtualWithAttrList()
throws Exception
{
@@ -638,7 +621,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualPrivilege()
throws Exception
{
@@ -733,11 +716,9 @@
}
finally
{
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
- DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf(ruleDN));
+ DeleteOperation deleteOperation = conn.processDelete(DN.valueOf(ruleDN));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
deleteOperation = conn.processDelete(DN.valueOf(policyDN));
@@ -755,7 +736,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualPasswordPolicyDN()
throws Exception
{
@@ -820,11 +801,7 @@
}
finally
{
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
- DeleteOperation deleteOperation =
- conn.processDelete(DN.valueOf(ruleDN));
+ DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
}
}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/VirtualStaticGroupTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/VirtualStaticGroupTestCase.java
index 6d6c492..b19dc82 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/VirtualStaticGroupTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/extensions/VirtualStaticGroupTestCase.java
@@ -31,7 +31,6 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -287,7 +286,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testCreateValidGroup()
throws Exception
{
@@ -379,7 +378,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testGroupAPI()
throws Exception
{
@@ -453,7 +452,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testGroupAPINonexistent()
throws Exception
{
@@ -534,7 +533,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualGroupDynamicGroupWithMember()
throws Exception
{
@@ -560,7 +559,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualGroupStaticGroupWithMember()
throws Exception
{
@@ -586,7 +585,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualGroupStaticGroupWithUniqueMember()
throws Exception
{
@@ -612,7 +611,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualAttributeAPI()
throws Exception
{
@@ -655,15 +654,10 @@
assertEquals(provider.approximatelyEqualTo(entry, rule, null),
ConditionResult.UNDEFINED);
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchFilter filter = SearchFilter.createFilterFromString("(member=" + u1 + ")");
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filter);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null, DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(member=" + u1 + ")"),
- null, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
assertFalse(provider.isSearchable(rule, searchOperation, false));
assertFalse(provider.isSearchable(rule, searchOperation, true));
@@ -681,7 +675,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualAttributeAPINonexistent()
throws Exception
{
@@ -724,15 +718,10 @@
assertEquals(provider.approximatelyEqualTo(entry, rule, null),
ConditionResult.UNDEFINED);
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ SearchFilter filter = SearchFilter.createFilterFromString("(member=" + u1 + ")");
+ SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filter);
InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), null, DN.valueOf("o=test"),
- SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString("(member=" + u1 + ")"),
- null, null);
+ new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request);
assertFalse(provider.isSearchable(rule, searchOperation, false));
assertFalse(provider.isSearchable(rule, searchOperation, false));
@@ -749,7 +738,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualAttrDynamicGroupWithMember()
throws Exception
{
@@ -777,7 +766,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
+ @Test
public void testVirtualAttrDynamicGroupWithUpdatedMemberURLs()
throws Exception
{
@@ -794,14 +783,11 @@
ByteString v = ByteString.valueOf(u4.toString());
assertTrue(a.contains(v));
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
-
LinkedList<Modification> mods = new LinkedList<Modification>();
mods.add(new Modification(ModificationType.ADD,
Attributes.create("memberurl",
"ldap:///o=test??sub?(objectClass=person)")));
- ModifyOperation modifyOperation = conn.processModify(d1, mods);
+ ModifyOperation modifyOperation = getRootConnection().processModify(d1, mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
a = e.getAttribute(memberType).get(0);
@@ -819,9 +805,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @Test()
- public void testAllowRetrievingMembership()
- throws Exception
+ @Test
+ public void testAllowRetrievingMembership() throws Exception
{
TestCaseUtils.initializeTestBackend(true);
TestCaseUtils.addEntries(LDIF_LINES);
@@ -837,8 +822,7 @@
assertTrue(a.contains(v));
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
LinkedList<Modification> mods = new LinkedList<Modification>();
mods.add(new Modification(ModificationType.REPLACE,
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java
index 5b91b68..6a47e2f 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java
@@ -35,7 +35,11 @@
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.ldap.LDAPFilter;
-import org.opends.server.types.*;
+import org.opends.server.types.Control;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
+import org.opends.server.types.SearchResultEntry;
+import org.opends.server.types.SearchResultReference;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -107,49 +111,6 @@
/**
- * Tests the second constructor, which takes processed arguments, without
- * providing an internal search listener.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test()
- public void testConstructor2WithoutListener()
- throws Exception
- {
- InternalClientConnection conn = getRootConnection();
- new InternalSearchOperation(conn, nextOperationID(),
- nextMessageID(), new ArrayList<Control>(),
- DN.rootDN(), SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(),
- new LinkedHashSet<String>(), null);
- }
-
-
-
- /**
- * Tests the second constructor, which takes processed arguments, with an
- * internal search listener.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- @Test()
- public void testConstructor2WithListener()
- throws Exception
- {
- InternalClientConnection conn = getRootConnection();
- new InternalSearchOperation(conn, nextOperationID(),
- nextMessageID(), new ArrayList<Control>(),
- DN.rootDN(), SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0,
- false, SearchFilter.objectClassPresent(),
- new LinkedHashSet<String>(),
- new TestInternalSearchListener());
- }
-
-
-
- /**
* Tests the <CODE>getSearchEntries</CODE> and
* <CODE>getSearchReferences</CODE> methods.
*
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
index 1b55199..e22d4f9 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
@@ -35,7 +35,6 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -75,30 +74,30 @@
* This class provides a set of test cases for the Directory Server JMX
* privilege subsystem.
*/
-public class JmxPrivilegeTestCase
- extends JmxTestCase
+public class JmxPrivilegeTestCase extends JmxTestCase
{
- // An array of boolean values that indicates whether config read operations
- // should be successful for users in the corresponding slots of the
- // connections array.
+ /**
+ * An array of boolean values that indicates whether config read operations
+ * should be successful for users in the corresponding slots of the
+ * connections array.
+ */
private boolean[] successful;
- // The set of client connections that should be used when performing
- // operations.
+ /**
+ * The set of client connections that should be used when performing
+ * operations.
+ */
private JmxClientConnection[] connections;
-
-
/**
* Make sure that the server is running and that an appropriate set of
* structures are in place.
*
* @throws Exception If an unexpected problem occurs.
*/
- @Override
@BeforeClass(alwaysRun = true)
- public void setUp()
- throws Exception
+ @Override
+ public void setUp() throws Exception
{
super.setUp();
@@ -339,11 +338,10 @@
.valueOf("cn=test2 user,dc=unindexed,dc=jeb"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
- deleteOperation = conn.processDelete(DN
- .valueOf("dc=unindexed,dc=jeb"));
+ deleteOperation = conn.processDelete(DN.valueOf("dc=unindexed,dc=jeb"));
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
- for (int i = 0; (connections != null) && (i < connections.length); i++)
+ for (int i = 0; connections != null && i < connections.length; i++)
{
connections[i].finalize();
connections[i] = null;
@@ -412,8 +410,7 @@
}
// Add JMX_READ privilege
- InternalClientConnection rootConnection =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection rootConnection = getRootConnection();
ArrayList<Modification> mods = new ArrayList<Modification>();
mods.add(new Modification(ModificationType.ADD, Attributes.create(
"ds-privilege-name", "jmx-read")));
@@ -1090,9 +1087,7 @@
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "testdata")
- public void testProxyAuthV1Write(JmxClientConnection conn,
- boolean hasPrivilege)
- throws Exception
+ public void testProxyAuthV1Write(JmxClientConnection conn, boolean hasPrivilege) throws Exception
{
// We can't trust the value of hasPrivilege because root users don't get
// proxy privileges by default. So make the determination based on the
@@ -1216,9 +1211,7 @@
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "testdata")
- public void testProxyAuthV1Read(JmxClientConnection conn,
- boolean hasPrivilege)
- throws Exception
+ public void testProxyAuthV1Read(JmxClientConnection conn, boolean hasPrivilege) throws Exception
{
// We can't trust the value of hasPrivilege because root users don't get
// proxy privileges by default. So make the determination based on the
@@ -1250,13 +1243,9 @@
// Test a search operation against the PWReset Target user.
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, conn.nextOperationID(),
- conn.nextMessageID(), controls, targetDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null,
- null);
+ SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls);
+ InternalSearchOperation searchOperation = new InternalSearchOperation(
+ conn, conn.nextOperationID(), conn.nextMessageID(), request, null);
searchOperation.run();
if (hasProxyPrivilege)
@@ -1270,8 +1259,6 @@
}
}
-
-
/**
* Tests to ensure that the use of the Directory Server will properly respect
* the PROXIED_AUTH privilege for add, delete, modify and modify DN requests
@@ -1286,9 +1273,7 @@
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "testdata")
- public void testProxyAuthV2Write(JmxClientConnection conn,
- boolean hasPrivilege)
- throws Exception
+ public void testProxyAuthV2Write(JmxClientConnection conn, boolean hasPrivilege) throws Exception
{
// We can't trust the value of hasPrivilege because root users don't get
// proxy privileges by default. So make the determination based on the
@@ -1422,9 +1407,7 @@
* @throws Exception If an unexpected problem occurs.
*/
@Test(dataProvider = "testdata")
- public void testProxyAuthV2Read(JmxClientConnection conn,
- boolean hasPrivilege)
- throws Exception
+ public void testProxyAuthV2Read(JmxClientConnection conn, boolean hasPrivilege) throws Exception
{
// We can't trust the value of hasPrivilege because root users don't get
// proxy privileges by default. So make the determination based on the
@@ -1433,8 +1416,7 @@
DN targetDN = DN.valueOf("cn=PWReset Target,o=test");
ArrayList<Control> controls = new ArrayList<Control>(1);
- controls.add(new ProxiedAuthV2Control(
- ByteString.valueOf("dn:" + targetDN.toString())));
+ controls.add(new ProxiedAuthV2Control(ByteString.valueOf("dn:" + targetDN)));
// Test a compare operation against the PWReset Target user.
@@ -1457,13 +1439,9 @@
// Test a search operation against the PWReset Target user.
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(conn, conn.nextOperationID(),
- conn.nextMessageID(), controls, targetDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null,
- null);
+ SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls);
+ InternalSearchOperation searchOperation = new InternalSearchOperation(
+ conn, conn.nextOperationID(), conn.nextMessageID(), request, null);
searchOperation.run();
if (hasProxyPrivilege)
@@ -1562,16 +1540,14 @@
// Update the set of root privileges to include proxied auth.
- InternalClientConnection internalRootConn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
ArrayList<Modification> mods = new ArrayList<Modification>();
mods.add(new Modification(ModificationType.ADD,
Attributes.create("ds-cfg-default-root-privilege-name",
"proxied-auth")));
ModifyOperation modifyOperation =
- internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"),
- mods);
+ conn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
@@ -1588,8 +1564,7 @@
Attributes.create("ds-cfg-default-root-privilege-name",
"proxied-auth")));
modifyOperation =
- internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"),
- mods);
+ conn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
@@ -1612,8 +1587,7 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- private Task getCompletedTask(DN taskEntryDN)
- throws Exception
+ private Task getCompletedTask(DN taskEntryDN) throws Exception
{
TaskBackend taskBackend =
(TaskBackend) DirectoryServer.getBackend(DN.valueOf("cn=tasks"));
@@ -1621,28 +1595,26 @@
if (task == null)
{
long stopWaitingTime = System.currentTimeMillis() + 10000L;
- while ((task == null) && (System.currentTimeMillis() < stopWaitingTime))
+ while (task == null && System.currentTimeMillis() < stopWaitingTime)
{
Thread.sleep(10);
task = taskBackend.getScheduledTask(taskEntryDN);
}
}
- assertNotNull(task, "There is no such task " + taskEntryDN.toString());
+ assertNotNull(task, "There is no such task " + taskEntryDN);
if (! TaskState.isDone(task.getTaskState()))
{
long stopWaitingTime = System.currentTimeMillis() + 20000L;
- while ((! TaskState.isDone(task.getTaskState())) &&
- (System.currentTimeMillis() < stopWaitingTime))
+ while (!TaskState.isDone(task.getTaskState())
+ && System.currentTimeMillis() < stopWaitingTime)
{
Thread.sleep(10);
}
}
assertTrue(TaskState.isDone(task.getTaskState()),
- "Task " + taskEntryDN.toString()
- + " did not complete in a timely manner.");
-
+ "Task " + taskEntryDN + " did not complete in a timely manner.");
return task;
}
}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/CollationMatchingRuleTest.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/CollationMatchingRuleTest.java
index a1915eb..cae1a99 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/CollationMatchingRuleTest.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/schema/CollationMatchingRuleTest.java
@@ -27,32 +27,35 @@
package org.opends.server.schema;
import java.util.ArrayList;
-import static org.testng.Assert.*;
-
import java.util.List;
+import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
+import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.controls.ServerSideSortRequestControl;
import org.opends.server.controls.VLVRequestControl;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
+import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.tools.LDAPModify;
-import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.Control;
import org.opends.server.types.DN;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.opends.server.types.Entry;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.opends.server.types.SearchFilter;
import org.opends.server.types.SearchResultEntry;
-import org.forgerock.opendj.ldap.SearchScope;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
+import static org.testng.Assert.*;
+
/**
* This Test Class tests various collation matching rules.
*/
+@SuppressWarnings("javadoc")
public final class CollationMatchingRuleTest
extends SchemaTestCase
{
@@ -117,14 +120,11 @@
public void searchCollationEqualityUsingOID() throws Exception
{
//Search the collation rule with OID of en and no suffix in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -154,14 +154,11 @@
{
//Search the collation rule with language tag of en and no suffix
//in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -190,14 +187,11 @@
public void searchCollationLTUsingOIDSuffix() throws Exception
{
//Search the collation rule with OID of es and suffix in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -227,14 +221,11 @@
public void searchCollationLTEUsingLanguageSuffix() throws Exception
{
//Search the collation rule with tag of fr and suffix in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -264,14 +255,11 @@
public void searchCollationGTUsingLanguage() throws Exception
{
//Search the collation rule with tag of fr in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -301,14 +289,11 @@
public void searchCollationGTEUsingLanguage() throws Exception
{
//Search the collation rule with tag of es and suffix in the filter.
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -341,14 +326,11 @@
*It searches for string quebec against the value of sn which is
* Qu\u00e9bec.
*/
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
+ InternalClientConnection conn = getRootConnection();
InternalSearchOperation searchOperation =
new InternalSearchOperation(
- conn,
- InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(),
+ conn, nextOperationID(), nextMessageID(),
null,
ByteString.valueOf("uid=user,o=test"),
SearchScope.WHOLE_SUBTREE,
@@ -387,9 +369,7 @@
expectedDNOrder.add(user1);
ArrayList<Control> requestControls = new ArrayList<Control>();
requestControls.add(new ServerSideSortRequestControl("displayname:fr"));
- ValidateSortControl(expectedDNOrder,
- requestControls,
- "displayname:fr-FR.6:=A*");
+ ValidateSortControl("displayname:fr-FR.6:=A*", expectedDNOrder, requestControls);
}
@@ -407,9 +387,7 @@
expectedDNOrder.add(user1);
ArrayList<Control> requestControls = new ArrayList<Control>();
requestControls.add(new ServerSideSortRequestControl("displayname:es"));
- ValidateSortControl(expectedDNOrder,
- requestControls,
- "displayname:es.6:=A*");
+ ValidateSortControl("displayname:es.6:=A*", expectedDNOrder, requestControls);
}
@@ -427,9 +405,7 @@
expectedDNOrder.add(user4);
ArrayList<Control> requestControls = new ArrayList<Control>();
requestControls.add(new ServerSideSortRequestControl("-displayname:en"));
- ValidateSortControl(expectedDNOrder,
- requestControls,
- "displayname:en-US.6:=A*");
+ ValidateSortControl("displayname:en-US.6:=A*", expectedDNOrder, requestControls);
}
@@ -449,39 +425,24 @@
ArrayList<Control> requestControls = new ArrayList<Control>();
requestControls.add(new ServerSideSortRequestControl("displayname:fr"));
requestControls.add(new VLVRequestControl(0, 4, 1, 0));
- ValidateSortControl(expectedDNOrder,
- requestControls,
- "objectclass=inetOrgPerson");
+ ValidateSortControl("objectclass=inetOrgPerson", expectedDNOrder, requestControls);
}
- private void ValidateSortControl(ArrayList<DN> expectedDNOrder,
- ArrayList<Control> requestControls,
- String searchFilter) throws Exception
+ private void ValidateSortControl(String searchFilter,
+ ArrayList<DN> expectedDNOrder,
+ ArrayList<Control> requestControls) throws Exception
{
try
{
populateEntriesForControl();
- InternalClientConnection conn =
- InternalClientConnection.getRootConnection();
- InternalSearchOperation internalSearch =
- new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(),
- InternalClientConnection.nextMessageID(), requestControls,
- DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.createFilterFromString(searchFilter),
- null, null);
-
- internalSearch.run();
+ SearchRequest request = newSearchRequest(DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, searchFilter)
+ .addControl(requestControls);
+ InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
- ArrayList<DN> returnedDNOrder = new ArrayList<DN>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- returnedDNOrder.add(e.getName());
- }
- assertEquals(returnedDNOrder, expectedDNOrder);
+ assertEquals(getDNs(internalSearch), expectedDNOrder);
}
finally
{
@@ -489,6 +450,16 @@
}
}
+ private ArrayList<DN> getDNs(InternalSearchOperation internalSearch)
+ {
+ ArrayList<DN> results = new ArrayList<DN>();
+ for (Entry e : internalSearch.getSearchEntries())
+ {
+ results.add(e.getName());
+ }
+ return results;
+ }
+
private void populateEntriesForControl() throws Exception
{
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/PrivilegeTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/PrivilegeTestCase.java
index c8347b9..53a77fb 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/PrivilegeTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/types/PrivilegeTestCase.java
@@ -40,7 +40,6 @@
import java.util.concurrent.CopyOnWriteArraySet;
import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -1286,13 +1285,8 @@
// Test a search operation against the PWReset Target user.
- InternalSearchOperation searchOperation = new InternalSearchOperation(conn,
- nextOperationID(), nextMessageID(), controls, targetDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null,
- null);
- searchOperation.run();
+ SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls);
+ InternalSearchOperation searchOperation = conn.processSearch(request);
assertProxyPrivilege(searchOperation.getResultCode(), hasProxyPrivilege);
}
@@ -1437,12 +1431,8 @@
// Test a search operation against the PWReset Target user.
- InternalSearchOperation searchOperation = new InternalSearchOperation(conn, nextOperationID(),
- nextMessageID(), controls, targetDN,
- SearchScope.BASE_OBJECT,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- SearchFilter.objectClassPresent(), null,
- null);
+ SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls);
+ InternalSearchOperation searchOperation = conn.processSearch(request);
searchOperation.run();
assertProxyPrivilege(searchOperation.getResultCode(), hasProxyPrivilege);
}
--
Gitblit v1.10.0