From ddf7385f6d72164c9e66aff00b3a4f076ec69c78 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 21 Apr 2016 16:03:20 +0000
Subject: [PATCH] Consolidated InternalClientConnection.processModifyDN() methods
---
opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java | 128 ++-----------------------------
opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java | 4
opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java | 28 +++----
opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Adapters.java | 18 ---
opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java | 7 +
5 files changed, 33 insertions(+), 152 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Adapters.java b/opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Adapters.java
index 7069860..71875e6 100644
--- a/opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Adapters.java
+++ b/opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Adapters.java
@@ -56,7 +56,6 @@
import org.opends.server.core.CompareOperation;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.ExtendedOperation;
-import org.opends.server.core.ModifyDNOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchListener;
import org.opends.server.protocols.internal.InternalSearchOperation;
@@ -72,15 +71,10 @@
import static org.forgerock.opendj.ldap.LdapException.*;
import static org.forgerock.util.promise.Promises.*;
-/**
- * This class provides a connection factory and an adapter for the OpenDJ 2.x
- * server.
- */
+/** This class provides a connection factory and an adapter for the OpenDJ 2.x server. */
public final class Adapters {
- /**
- * Constructor.
- */
+ /** Constructor. */
private Adapters() {
// No implementation required.
}
@@ -226,13 +220,7 @@
@Override
public Result modifyDN(final ModifyDNRequest request) throws LdapException {
- final ModifyDNOperation modifyDNOperation =
- icc.processModifyDN(valueOfObject(request.getName()),
- valueOfObject(request.getNewRDN()),
- request.isDeleteOldRDN(),
- request.getNewSuperior() != null ? valueOfObject(request.getNewSuperior()) : null,
- to(request.getControls()));
- return getResponseResult(modifyDNOperation);
+ return getResponseResult(icc.processModifyDN(request));
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
index 52a1401..60cdc7b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/protocols/internal/InternalClientConnection.java
@@ -80,6 +80,7 @@
import org.opends.server.util.ModifyDNChangeRecordEntry;
import static org.forgerock.opendj.adapter.server3x.Converters.*;
+import static org.forgerock.opendj.ldap.ByteString.*;
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.util.CollectionUtils.*;
@@ -597,7 +598,6 @@
// time limit for internal client connections.
}
- /** {@inheritDoc} */
@Override
public boolean isConnectionValid()
{
@@ -1546,81 +1546,6 @@
toRawModifications(modifyRequest.getModifications()), to(modifyRequest.getControls()));
}
-
- /**
- * Processes an internal modify DN operation with the provided
- * information.
- *
- * @param rawEntryDN The current DN of the entry to rename.
- * @param rawNewRDN The new RDN to use for the entry.
- * @param deleteOldRDN The flag indicating whether the old RDN
- * value is to be removed from the entry.
- *
- * @return A reference to the modify DN operation that was
- * processed and contains information about the result of
- * the processing.
- */
- public ModifyDNOperation processModifyDN(String rawEntryDN,
- String rawNewRDN,
- boolean deleteOldRDN)
- {
- return processModifyDN(ByteString.valueOfUtf8(rawEntryDN),
- ByteString.valueOfUtf8(rawNewRDN),
- deleteOldRDN, null, null);
- }
-
-
-
- /**
- * Processes an internal modify DN operation with the provided
- * information.
- *
- * @param rawEntryDN The current DN of the entry to rename.
- * @param rawNewRDN The new RDN to use for the entry.
- * @param deleteOldRDN The flag indicating whether the old RDN
- * value is to be removed from the entry.
- * @param controls The set of controls to include in the
- * request.
- *
- * @return A reference to the modify DN operation that was
- * processed and contains information about the result of
- * the processing.
- */
- public ModifyDNOperation processModifyDN(String rawEntryDN,
- String rawNewRDN,
- boolean deleteOldRDN,
- List<Control> controls)
- {
- return processModifyDN(ByteString.valueOfUtf8(rawEntryDN),
- ByteString.valueOfUtf8(rawNewRDN),
- deleteOldRDN, null, controls);
- }
-
-
-
- /**
- * Processes an internal modify DN operation with the provided
- * information.
- *
- * @param rawEntryDN The current DN of the entry to rename.
- * @param rawNewRDN The new RDN to use for the entry.
- * @param deleteOldRDN The flag indicating whether the old RDN
- * value is to be removed from the entry.
- *
- * @return A reference to the modify DN operation that was
- * processed and contains information about the result of
- * the processing.
- */
- public ModifyDNOperation processModifyDN(ByteString rawEntryDN,
- ByteString rawNewRDN,
- boolean deleteOldRDN)
- {
- return processModifyDN(rawEntryDN, rawNewRDN, deleteOldRDN, null,
- null);
- }
-
-
-
/**
* Processes an internal modify DN operation with the provided
* information.
@@ -1678,35 +1603,6 @@
ByteString.valueOfUtf8(rawNewSuperior), controls);
}
-
-
- /**
- * Processes an internal modify DN operation with the provided
- * information.
- *
- * @param rawEntryDN The current DN of the entry to rename.
- * @param rawNewRDN The new RDN to use for the entry.
- * @param deleteOldRDN The flag indicating whether the old RDN
- * value is to be removed from the entry.
- * @param rawNewSuperior The new superior for the modify DN
- * operation, or <CODE>null</CODE> if the
- * entry will remain below the same parent.
- *
- * @return A reference to the modify DN operation that was
- * processed and contains information about the result of
- * the processing.
- */
- public ModifyDNOperation processModifyDN(ByteString rawEntryDN,
- ByteString rawNewRDN,
- boolean deleteOldRDN,
- ByteString rawNewSuperior)
- {
- return processModifyDN(rawEntryDN, rawNewRDN, deleteOldRDN,
- rawNewSuperior, null);
- }
-
-
-
/**
* Processes an internal modify DN operation with the provided
* information.
@@ -1852,26 +1748,25 @@
* Processes an internal modify DN operation with the provided information.
*
* @param modifyDNRequest
- * The modify DN request with information about the processing to perform.
+ * The modify DN requests with information about the processing to perform.
* @return A reference to the modify DN operation that was processed and contains information about
* the result of the processing.
*/
public ModifyDNOperation processModifyDN(ModifyDNRequest modifyDNRequest)
{
- return processModifyDN(modifyDNRequest.getName(),
- modifyDNRequest.getNewRDN(),
- modifyDNRequest.isDeleteOldRDN(),
- modifyDNRequest.getNewSuperior());
+ ModifyDNRequest r = modifyDNRequest;
+ ByteString rawNewSuperior = r.getNewSuperior() != null ? valueOfObject(r.getNewSuperior()) : null;
+ return processModifyDN(valueOfObject(r.getName()), valueOfObject(r.getNewRDN()), r.isDeleteOldRDN(),
+ rawNewSuperior, to(r.getControls()));
}
/**
- * Processes an internal search operation with the provided
- * information.
+ * Processes an internal search operation with the provided information.
*
- * @param request The search request.
- * @return A reference to the internal search operation that was
- * processed and contains information about the result of
- * the processing.
+ * @param request
+ * The search request.
+ * @return A reference to the internal search operation that was processed and contains
+ * information about the result of the processing.
*/
public InternalSearchOperation processSearch(final SearchRequest request)
{
@@ -2241,7 +2136,6 @@
return 0;
}
- /** {@inheritDoc} */
@Override
public int getSSF() {
//Always return strongest value.
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java
index 4cdd024..e4d25ad 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java
@@ -16,6 +16,7 @@
*/
package org.opends.server.backends;
+import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
@@ -381,15 +382,13 @@
assertTrue(DirectoryServer.entryExists(beforeDN));
assertFalse(DirectoryServer.entryExists(afterDN));
- InternalClientConnection conn = getRootConnection();
- ModifyDNOperation modifyDNOperation =
- conn.processModifyDN("ou=leaf before,o=ldif", "ou=leaf after", true);
+ ModifyDNOperation modifyDNOperation = processModifyDN("ou=leaf before,o=ldif", "ou=leaf after", true);
assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(DirectoryServer.entryExists(beforeDN));
assertTrue(DirectoryServer.entryExists(afterDN));
- DeleteOperation deleteOperation = conn.processDelete(afterDN);
+ DeleteOperation deleteOperation = getRootConnection().processDelete(afterDN);
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(DirectoryServer.entryExists(afterDN));
}
@@ -411,14 +410,11 @@
"objectClass: organizationalUnit",
"ou: new entry");
- InternalClientConnection conn = getRootConnection();
- ModifyDNOperation modifyDNOperation =
- conn.processModifyDN("ou=new entry,o=ldif", "ou=People", true);
- assertEquals(modifyDNOperation.getResultCode(),
- ResultCode.ENTRY_ALREADY_EXISTS);
+ ModifyDNOperation modifyDNOperation = processModifyDN("ou=new entry,o=ldif", "ou=People", true);
+ assertEquals(modifyDNOperation.getResultCode(), ResultCode.ENTRY_ALREADY_EXISTS);
assertTrue(DirectoryServer.entryExists(DN.valueOf("ou=new entry,o=ldif")));
- DeleteOperation deleteOperation = conn.processDelete("ou=new entry,o=ldif");
+ DeleteOperation deleteOperation = getRootConnection().processDelete("ou=new entry,o=ldif");
assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(DirectoryServer.entryExists(DN.valueOf("ou=new entry,o=ldif")));
}
@@ -483,9 +479,7 @@
assertTrue(DirectoryServer.entryExists(childBeforeDN));
assertFalse(DirectoryServer.entryExists(childAfterDN));
- InternalClientConnection conn = getRootConnection();
- ModifyDNOperation modifyDNOperation =
- conn.processModifyDN("ou=People,o=ldif", "ou=Users", true);
+ ModifyDNOperation modifyDNOperation = processModifyDN("ou=People,o=ldif", "ou=Users", true);
assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
assertFalse(DirectoryServer.entryExists(beforeDN));
@@ -494,8 +488,7 @@
assertFalse(DirectoryServer.entryExists(childBeforeDN));
assertTrue(DirectoryServer.entryExists(childAfterDN));
- modifyDNOperation =
- conn.processModifyDN("ou=Users,o=ldif", "ou=People", true);
+ modifyDNOperation = processModifyDN("ou=Users,o=ldif", "ou=People", true);
assertTrue(DirectoryServer.entryExists(beforeDN));
assertFalse(DirectoryServer.entryExists(afterDN));
@@ -504,7 +497,10 @@
assertFalse(DirectoryServer.entryExists(childAfterDN));
}
-
+ private ModifyDNOperation processModifyDN(String name, String newRDN, boolean deleteOldRDN)
+ {
+ return getRootConnection().processModifyDN(newModifyDNRequest(name, newRDN).setDeleteOldRDN(deleteOldRDN));
+ }
/**
* Tests to ensure that a base-level search works as expected.
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java b/opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java
index bed66ba..c5eaa61 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java
@@ -24,6 +24,7 @@
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
+import org.forgerock.opendj.ldap.requests.ModifyDNRequest;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.TestCaseUtils;
import org.opends.server.controls.ProxiedAuthV1Control;
@@ -53,6 +54,7 @@
import static org.assertj.core.api.Assertions.*;
import static org.forgerock.opendj.ldap.ResultCode.*;
+import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.util.ServerConstants.*;
@@ -916,8 +918,9 @@
assertFalse(DirectoryServer.entryExists(
dn("uid=first.test,ou=Users,dc=example,dc=com")));
- ModifyDNOperation modifyDNOperation =
- getRootConnection().processModifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
+ ModifyDNRequest modifyDNRequest =
+ newModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users").setDeleteOldRDN(true);
+ ModifyDNOperation modifyDNOperation = getRootConnection().processModifyDN(modifyDNRequest);
assertSuccess(modifyDNOperation);
// assertEquals(InvocationCounterPlugin.getSubordinateModifyDNCount(), 2);
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
index a1d9731..d44c553 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
@@ -563,7 +563,7 @@
InternalClientConnection conn = getRootConnection();
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(ByteString.valueOfUtf8("cn=test,o=test"),
- ByteString.valueOfUtf8("cn=test2"), true);
+ ByteString.valueOfUtf8("cn=test2"), true, null, null);
assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS);
}
@@ -589,7 +589,7 @@
ModifyDNOperation modifyDNOperation =
conn.processModifyDN(ByteString.valueOfUtf8("cn=test,o=test"),
ByteString.valueOfUtf8("cn=test2"), true,
- ByteString.valueOfUtf8("dc=example,dc=com"));
+ ByteString.valueOfUtf8("dc=example,dc=com"), null);
assertEquals(modifyDNOperation.getResultCode(),
ResultCode.UNWILLING_TO_PERFORM);
}
--
Gitblit v1.10.0