From 63f1d4c2e9787e9abf49b7026f4f46dfdba7c972 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 12 Nov 2014 20:12:04 +0000
Subject: [PATCH] Code cleanups
---
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java | 391 ++++++++++++-----------------------
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java | 230 ++++++++------------
2 files changed, 233 insertions(+), 388 deletions(-)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
index bd2d77d..c569845 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
@@ -26,27 +26,28 @@
*/
package org.opends.server.tools;
-import static org.opends.messages.ToolMessages.*;
-import static com.forgerock.opendj.cli.ArgumentConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.opends.server.util.StaticUtils.*;
-import static com.forgerock.opendj.cli.Utils.wrapText;
-import static com.forgerock.opendj.cli.Utils.filterExitCode;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.*;
import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.config.server.ConfigException;
+import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.admin.std.server.BackendCfg;
import org.opends.server.admin.std.server.LocalDBBackendCfg;
import org.opends.server.api.Backend;
import org.opends.server.backends.jeb.*;
-import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.core.CoreConfigManager;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.LockFileManager;
import org.opends.server.extensions.ConfigFileHandler;
import org.opends.server.loggers.JDKLogging;
-import org.opends.server.types.*;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
+import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
+import org.opends.server.types.InitializationException;
+import org.opends.server.types.NullOutputStream;
+import org.opends.server.types.SortKey;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.StaticUtils;
@@ -60,13 +61,18 @@
import com.forgerock.opendj.cli.SubCommandArgumentParser;
import com.forgerock.opendj.cli.TableBuilder;
import com.forgerock.opendj.cli.TextTablePrinter;
+import com.sleepycat.je.Cursor;
+import com.sleepycat.je.CursorConfig;
+import com.sleepycat.je.DatabaseEntry;
+import com.sleepycat.je.DatabaseException;
+import com.sleepycat.je.LockMode;
+import com.sleepycat.je.OperationStatus;
+import static com.forgerock.opendj.cli.ArgumentConstants.*;
+import static com.forgerock.opendj.cli.Utils.*;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.*;
-
-import com.sleepycat.je.*;
+import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.util.StaticUtils.*;
/**
* This program provides a utility that may be used to debug a JE backend. This
@@ -87,7 +93,7 @@
* Flag indicating whether or not the global arguments have already been
* initialized.
*/
- private boolean globalArgumentsInitialized = false;
+ private boolean globalArgumentsInitialized;
/** The command-line argument parser. */
private final SubCommandArgumentParser parser;
@@ -105,7 +111,7 @@
* Flag indicating whether or not the sub-commands have already been
* initialized.
*/
- private boolean subCommandsInitialized = false;
+ private boolean subCommandsInitialized;
@@ -170,7 +176,7 @@
toolDescription, false);
}
- // Displays the provided message followed by a help usage reference.
+ /** Displays the provided message followed by a help usage reference. */
private void displayMessageAndUsageReference(LocalizableMessage message) {
printMessage(message);
printMessage(LocalizableMessage.EMPTY);
@@ -529,20 +535,20 @@
// Retrieve the sub-command implementation and run it.
SubCommand subCommand = parser.getSubCommand();
try {
- if(subCommand.getName().equals("list-root-containers"))
+ if("list-root-containers".equals(subCommand.getName()))
{
return listRootContainers();
}
- else if(subCommand.getName().equals("list-entry-containers"))
+ else if("list-entry-containers".equals(subCommand.getName()))
{
return listEntryContainers(subCommand.getArgument("backendid"));
}
- else if(subCommand.getName().equals("list-database-containers"))
+ else if("list-database-containers".equals(subCommand.getName()))
{
return listDatabaseContainers(subCommand.getArgument("backendid"),
subCommand.getArgument("basedn"));
}
- else if(subCommand.getName().equals("dump-database-container"))
+ else if("dump-database-container".equals(subCommand.getName()))
{
return dumpDatabaseContainer(subCommand.getArgument("backendid"),
subCommand.getArgument("basedn"),
@@ -554,14 +560,12 @@
subCommand.getArgument("maxdatasize"),
subCommand.getArgument("mindatasize"));
}
- else if(subCommand.getName().equals("list-index-status"))
+ else if("list-index-status".equals(subCommand.getName()))
{
return listIndexStatus(subCommand.getArgument("backendid"),
subCommand.getArgument("basedn"));
}
- {
- return 0;
- }
+ return 0;
} catch (Exception e) {
printMessage(LocalizableMessage.raw(StaticUtils.stackTraceToString(e)));
return 1;
@@ -597,18 +601,7 @@
private int listEntryContainers(Argument backendID)
{
- Map<LocalDBBackendCfg, BackendImpl> jeBackends = getJEBackends();
- BackendImpl backend = null;
-
- for(BackendImpl b : jeBackends.values())
- {
- if(b.getBackendID().equalsIgnoreCase(backendID.getValue()))
- {
- backend = b;
- break;
- }
- }
-
+ BackendImpl backend = getBackendById(backendID);
if(backend == null)
{
printMessage(ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID.getValue()));
@@ -669,8 +662,6 @@
out.format("%nTotal: %d%n", count);
return 0;
-
-
}
catch(DatabaseException de)
{
@@ -680,55 +671,21 @@
}
finally
{
- try
- {
- // Close the root container
- rc.close();
- }
- catch(DatabaseException de)
- {
- // Ignore.
- }
-
- // Release the shared lock on the backend.
- try
- {
- String lockFile = LockFileManager.getBackendLockFileName(backend);
- StringBuilder failureReason = new StringBuilder();
- if (! LockFileManager.releaseLock(lockFile, failureReason))
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
- }
- }
- catch (Exception e)
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
- }
+ close(rc);
+ releaseSharedLock(backend);
}
}
- private int listDatabaseContainers(Argument backendID,
- Argument baseDN)
+ private int listDatabaseContainers(Argument backendID, Argument baseDN)
{
- Map<LocalDBBackendCfg, BackendImpl> jeBackends = getJEBackends();
- BackendImpl backend = null;
- DN base = null;
-
- for(BackendImpl b : jeBackends.values())
- {
- if(b.getBackendID().equalsIgnoreCase(backendID.getValue()))
- {
- backend = b;
- break;
- }
- }
-
+ BackendImpl backend = getBackendById(backendID);
if(backend == null)
{
printMessage(ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID.getValue()));
return 1;
}
+ DN base = null;
if(baseDN.isPresent())
{
try
@@ -788,7 +745,6 @@
if(base != null)
{
EntryContainer ec = rc.getEntryContainer(base);
-
if(ec == null)
{
printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
@@ -796,48 +752,23 @@
return 1;
}
- ArrayList<DatabaseContainer> databaseContainers =
- new ArrayList<DatabaseContainer>();
- ec.listDatabases(databaseContainers);
- for(DatabaseContainer dc : databaseContainers)
- {
- builder.startRow();
- builder.appendCell(dc.getName().replace(ec.getDatabasePrefix()+"_",
- ""));
- builder.appendCell(dc.getClass().getSimpleName());
- builder.appendCell(dc.getName());
- builder.appendCell(dc.getRecordCount());
- count++;
- }
+ count = appendDatabaseContainerRows(builder, ec, count);
}
else
{
for(EntryContainer ec : rc.getEntryContainers())
{
builder.startRow();
- ArrayList<DatabaseContainer> databaseContainers =
- new ArrayList<DatabaseContainer>();
- ec.listDatabases(databaseContainers);
- builder.appendCell("Base DN: " +
- ec.getBaseDN().toNormalizedString());
- for(DatabaseContainer dc : databaseContainers)
- {
- builder.startRow();
- builder.appendCell(dc.getName().replace(
- ec.getDatabasePrefix()+"_",""));
- builder.appendCell(dc.getClass().getSimpleName());
- builder.appendCell(dc.getName());
- builder.appendCell(dc.getRecordCount());
- count++;
- }
+ builder.appendCell("Base DN: " + ec.getBaseDN().toNormalizedString());
+ count = appendDatabaseContainerRows(builder, ec, count);
}
}
TextTablePrinter printer = new TextTablePrinter(out);
builder.print(printer);
out.format("%nTotal: %d%n", count);
- return 0;
+ return 0;
}
catch(DatabaseException de)
{
@@ -847,55 +778,81 @@
}
finally
{
- try
- {
- // Close the root container
- rc.close();
- }
- catch(DatabaseException de)
- {
- // Ignore.
- }
-
- // Release the shared lock on the backend.
- try
- {
- String lockFile = LockFileManager.getBackendLockFileName(backend);
- StringBuilder failureReason = new StringBuilder();
- if (! LockFileManager.releaseLock(lockFile, failureReason))
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
- }
- }
- catch (Exception e)
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
- }
+ close(rc);
+ releaseSharedLock(backend);
}
}
- private int listIndexStatus(Argument backendID,
- Argument baseDN)
+ private int appendDatabaseContainerRows(TableBuilder builder, EntryContainer ec, int count)
{
- Map<LocalDBBackendCfg, BackendImpl> jeBackends = getJEBackends();
- BackendImpl backend = null;
- DN base = null;
-
- for(BackendImpl b : jeBackends.values())
+ ArrayList<DatabaseContainer> databaseContainers = new ArrayList<DatabaseContainer>();
+ ec.listDatabases(databaseContainers);
+ String toReplace = ec.getDatabasePrefix() + "_";
+ for(DatabaseContainer dc : databaseContainers)
{
- if(b.getBackendID().equalsIgnoreCase(backendID.getValue()))
+ builder.startRow();
+ builder.appendCell(dc.getName().replace(toReplace, ""));
+ builder.appendCell(dc.getClass().getSimpleName());
+ builder.appendCell(dc.getName());
+ builder.appendCell(dc.getRecordCount());
+ count++;
+ }
+ return count;
+ }
+
+ private void close(RootContainer rc)
+ {
+ try
+ {
+ rc.close();
+ }
+ catch(DatabaseException ignored)
+ {
+ // Ignore.
+ }
+ }
+
+ private void releaseSharedLock(BackendImpl backend)
+ {
+ try
+ {
+ String lockFile = LockFileManager.getBackendLockFileName(backend);
+ StringBuilder failureReason = new StringBuilder();
+ if (!LockFileManager.releaseLock(lockFile, failureReason))
{
- backend = b;
- break;
+ printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
}
}
+ catch (Exception e)
+ {
+ printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
+ }
+ }
+ private BackendImpl getBackendById(Argument backendId)
+ {
+ Collection<BackendImpl> backends = getJEBackends().values();
+ String backendID = backendId.getValue();
+ for (BackendImpl b : backends)
+ {
+ if (b.getBackendID().equalsIgnoreCase(backendID))
+ {
+ return b;
+ }
+ }
+ return null;
+ }
+
+ private int listIndexStatus(Argument backendID, Argument baseDN)
+ {
+ BackendImpl backend = getBackendById(backendID);
if(backend == null)
{
printMessage(ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID.getValue()));
return 1;
}
+ DN base = null;
if(baseDN.isPresent())
{
try
@@ -960,7 +917,6 @@
EntryContainer ec = rc.getEntryContainer(base);
-
if(ec == null)
{
printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
@@ -973,24 +929,22 @@
Map<Index, StringBuilder> undefinedKeys =
new HashMap<Index, StringBuilder>();
ec.listDatabases(databaseContainers);
+ String toReplace = ec.getDatabasePrefix() + "_";
for(DatabaseContainer dc : databaseContainers)
{
if(dc instanceof Index || dc instanceof VLVIndex)
{
builder.startRow();
- builder.appendCell(dc.getName().replace(ec.getDatabasePrefix()+"_",
- ""));
+ builder.appendCell(dc.getName().replace(toReplace, ""));
builder.appendCell(dc.getClass().getSimpleName());
builder.appendCell(dc.getName());
if(dc instanceof Index)
{
- builder.appendCell(ec.getState().getIndexTrustState(null,
- (dc)));
+ builder.appendCell(ec.getState().getIndexTrustState(null, dc));
}
else if(dc instanceof VLVIndex)
{
- builder.appendCell(ec.getState().getIndexTrustState(null,
- (dc)));
+ builder.appendCell(ec.getState().getIndexTrustState(null, dc));
}
builder.appendCell(dc.getRecordCount());
@@ -1008,7 +962,7 @@
while(status == OperationStatus.SUCCESS)
{
byte[] bytes = data.getData();
- if (bytes.length == 0 || ((bytes[0] & 0x80) == 0x80))
+ if (bytes.length == 0 || (bytes[0] & 0x80) == 0x80)
{
// Entry limit has exceeded and there is no encoded
// undefined set size.
@@ -1081,8 +1035,7 @@
out.format("%nTotal: %d%n", count);
for(Map.Entry<Index, StringBuilder> e : undefinedKeys.entrySet())
{
- out.format("%nIndex: %s%n",
- e.getKey().getName().replace(ec.getDatabasePrefix()+"_", ""));
+ out.format("%nIndex: %s%n", e.getKey().getName().replace(toReplace, ""));
out.format("Undefined keys: %s%n", e.getValue().toString());
}
return 0;
@@ -1095,30 +1048,8 @@
}
finally
{
- try
- {
- // Close the root container
- rc.close();
- }
- catch(DatabaseException de)
- {
- // Ignore.
- }
-
- // Release the shared lock on the backend.
- try
- {
- String lockFile = LockFileManager.getBackendLockFileName(backend);
- StringBuilder failureReason = new StringBuilder();
- if (! LockFileManager.releaseLock(lockFile, failureReason))
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
- }
- }
- catch (Exception e)
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
- }
+ close(rc);
+ releaseSharedLock(backend);
}
}
@@ -1128,25 +1059,14 @@
Argument maxKeyValue, Argument minKeyValue,
Argument maxDataSize, Argument minDataSize)
{
- Map<LocalDBBackendCfg, BackendImpl> jeBackends = getJEBackends();
- BackendImpl backend = null;
- DN base = null;
-
- for(BackendImpl b : jeBackends.values())
- {
- if(b.getBackendID().equalsIgnoreCase(backendID.getValue()))
- {
- backend = b;
- break;
- }
- }
-
+ BackendImpl backend = getBackendById(backendID);
if(backend == null)
{
printMessage(ERR_DBTEST_NO_BACKENDS_FOR_ID.get(backendID.getValue()));
return 1;
}
+ DN base = null;
try
{
base = DN.valueOf(baseDN.getValue());
@@ -1191,7 +1111,6 @@
try
{
EntryContainer ec = rc.getEntryContainer(base);
-
if(ec == null)
{
printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
@@ -1203,10 +1122,10 @@
ArrayList<DatabaseContainer> databaseContainers =
new ArrayList<DatabaseContainer>();
ec.listDatabases(databaseContainers);
+ String toReplace = ec.getDatabasePrefix() + "_";
for(DatabaseContainer dc : databaseContainers)
{
- if(dc.getName().replace(ec.getDatabasePrefix()+"_","").
- equalsIgnoreCase(databaseName.getValue()))
+ if(dc.getName().replace(toReplace, "").equalsIgnoreCase(databaseName.getValue()))
{
databaseContainer = dc;
break;
@@ -1226,9 +1145,7 @@
long totalDataSize = 0;
int indent = 4;
- Cursor cursor =
- databaseContainer.openCursor(null, CursorConfig.DEFAULT);
-
+ Cursor cursor = databaseContainer.openCursor(null, CursorConfig.DEFAULT);
try
{
DatabaseEntry key = new DatabaseEntry();
@@ -1277,9 +1194,7 @@
{
if(minKeyValue.getValue().startsWith("0x"))
{
- start =
- StaticUtils.hexStringToByteArray(minKeyValue.getValue().
- substring(2));
+ start = hexStringToByteArray(minKeyValue.getValue().substring(2));
}
else
{
@@ -1326,9 +1241,7 @@
{
if(maxKeyValue.getValue().startsWith("0x"))
{
- end =
- StaticUtils.hexStringToByteArray(maxKeyValue.getValue().
- substring(2));
+ end = hexStringToByteArray(maxKeyValue.getValue().substring(2));
}
else
{
@@ -1379,6 +1292,7 @@
status = cursor.getFirst(key, data, lockMode);
}
+ final String lineSep = System.getProperty("line.separator");
while(status == OperationStatus.SUCCESS)
{
// Make sure this record is within the value size params
@@ -1424,8 +1338,7 @@
}
else
{
- if(defaultComparator.compare(key.getData(),
- end) > 0)
+ if (defaultComparator.compare(key.getData(), end) > 0)
{
break;
}
@@ -1468,11 +1381,10 @@
keyLabel = INFO_LABEL_DBTEST_ENTRY_ID.get();
try
{
- formatedData = System.getProperty("line.separator") +
+ formatedData = lineSep +
ID2Entry.entryFromDatabase(
ByteString.wrap(data.getData()),
- ec.getRootContainer().getCompressedSchema()).
- toLDIFString();
+ ec.getRootContainer().getCompressedSchema()).toLDIFString();
dataLabel = INFO_LABEL_DBTEST_ENTRY.get();
}
catch(Exception e)
@@ -1503,20 +1415,18 @@
formatedKey = new String(key.getData());
keyLabel = INFO_LABEL_DBTEST_INDEX_VALUE.get();
- EntryIDSet idSet = new EntryIDSet(key.getData(),
- data.getData());
+ EntryIDSet idSet = new EntryIDSet(key.getData(), data.getData());
if(idSet.isDefined())
{
int lineCount = 0;
StringBuilder builder = new StringBuilder();
- Iterator<EntryID> i = idSet.iterator();
- while(i.hasNext())
+ for (EntryID entryID : idSet)
{
- builder.append(i.next());
+ builder.append(entryID);
if(lineCount == 10)
{
- builder.append(System.getProperty("line.separator"));
+ builder.append(lineSep);
lineCount = 0;
}
else
@@ -1581,8 +1491,7 @@
entryIDBytes.length);
long entryID = JebFormat.entryIDFromDatabase(entryIDBytes);
- formatedKey = System.getProperty("line.separator") +
- String.valueOf(entryID) + ": " + builder.toString();
+ formatedKey = lineSep + entryID + ": " + builder;
}
else
{
@@ -1599,7 +1508,7 @@
long[] entryIDs = svs.getEntryIDs();
for(int i = 0; i < entryIDs.length; i++)
{
- builder.append(String.valueOf(entryIDs[i]));
+ builder.append(entryIDs[i]);
builder.append(": ");
for(int j = 0; j < sortKeys.length; j++)
{
@@ -1617,14 +1526,13 @@
}
else
{
- builder.append(value.toString());
+ builder.append(value);
}
builder.append(" ");
}
- builder.append(System.getProperty("line.separator"));
+ builder.append(lineSep);
}
- formatedData = System.getProperty("line.separator") +
- builder.toString();
+ formatedData = lineSep + builder;
dataLabel = INFO_LABEL_DBTEST_INDEX_ENTRY_ID_LIST.get();
}
catch(Exception e)
@@ -1639,18 +1547,14 @@
if(formatedKey == null)
{
StringBuilder keyBuilder = new StringBuilder();
- StaticUtils.byteArrayToHexPlusAscii(keyBuilder, key.getData(),
- indent);
- formatedKey = System.getProperty("line.separator") +
- keyBuilder.toString();
+ StaticUtils.byteArrayToHexPlusAscii(keyBuilder, key.getData(), indent);
+ formatedKey = lineSep + keyBuilder;
}
if(formatedData == null)
{
StringBuilder dataBuilder = new StringBuilder();
- StaticUtils.byteArrayToHexPlusAscii(dataBuilder, data.getData(),
- indent);
- formatedData = System.getProperty("line.separator") +
- dataBuilder.toString();
+ StaticUtils.byteArrayToHexPlusAscii(dataBuilder, data.getData(), indent);
+ formatedData = lineSep + dataBuilder;
}
out.format("%s (%d bytes): %s%n", keyLabel,
@@ -1686,37 +1590,15 @@
}
finally
{
- try
- {
- // Close the root container
- rc.close();
- }
- catch(DatabaseException de)
- {
- // Ignore.
- }
-
- // Release the shared lock on the backend.
- try
- {
- String lockFile = LockFileManager.getBackendLockFileName(backend);
- StringBuilder failureReason = new StringBuilder();
- if (! LockFileManager.releaseLock(lockFile, failureReason))
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), failureReason));
- }
- }
- catch (Exception e)
- {
- printMessage(WARN_DBTEST_CANNOT_UNLOCK_BACKEND.get(backend.getBackendID(), getExceptionMessage(e)));
- }
+ close(rc);
+ releaseSharedLock(backend);
}
}
private Map<LocalDBBackendCfg, BackendImpl> getJEBackends()
{
ArrayList<Backend> backendList = new ArrayList<Backend>();
- ArrayList<BackendCfg> entryList = new ArrayList<BackendCfg>();
+ ArrayList<BackendCfg> entryList = new ArrayList<BackendCfg>();
ArrayList<List<DN>> dnList = new ArrayList<List<DN>>();
BackendToolUtils.getBackends(backendList, entryList, dnList);
@@ -1724,14 +1606,13 @@
new LinkedHashMap<LocalDBBackendCfg, BackendImpl>();
for(int i = 0; i < backendList.size(); i++)
{
- Backend backend = backendList.get(i);
+ Backend<?> backend = backendList.get(i);
if(backend instanceof BackendImpl)
{
jeBackends.put((LocalDBBackendCfg)entryList.get(i),
(BackendImpl)backend);
}
}
-
return jeBackends;
}
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
index 148dca6..2247bea 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/plugins/ReferentialIntegrityPluginTestCase.java
@@ -48,16 +48,20 @@
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.types.*;
import org.opends.server.types.Attributes;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.opends.server.types.RDN;
-import org.testng.annotations.*;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+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.*;
/**
@@ -66,7 +70,7 @@
@SuppressWarnings("javadoc")
public class ReferentialIntegrityPluginTestCase extends PluginTestCase {
- //Config DNs and attributes.
+ /** Config DNs and attributes. */
private DN configDN;
private String dsConfigAttrType="ds-cfg-attribute-type";
private String dsConfigBaseDN="ds-cfg-base-dn";
@@ -77,46 +81,45 @@
"ds-cfg-check-references-filter-criteria";
private String dsConfigPluginType = "ds-cfg-plugin-type";
- //Suffixes to use for non-public naming context tests.
+ /** Suffixes to use for non-public naming context tests. */
private String exSuffix="dc=example,dc=com";
private String testSuffix="o=test";
- //dc=example,dc=com entries.
+ /** Dc=example,dc=com entries. */
private String user1="uid=user.1, ou=People, ou=dept," + exSuffix;
private String user2="uid=user.2, ou=People, ou=dept," + exSuffix;
private String user3="uid=user.3, ou=People, ou=dept," + exSuffix;
- //Test entry to use for rename tests.
+ /** Test entry to use for rename tests. */
private String tuser1="uid=user.1, ou=People, ou=dept," + testSuffix;
- //Old superior, new superior and new RDN for move tree tests.
+ /** Old superior, new superior and new RDN for move tree tests. */
private String newSuperior="ou=moved dept," + exSuffix;
private String oldSuperior="ou=people, ou=dept," + exSuffix;
private String newRdn="ou=moved people";
- //DNs to verfiy that the moved tree test worked.
+ /** DNs to verfiy that the moved tree test worked. */
private String user1_moved= "uid=user.1," + newRdn + ',' +newSuperior;
private String user2_moved= "uid=user.2," + newRdn + ',' + newSuperior;
private String user3_moved= "uid=user.3," + newRdn + ',' + newSuperior;
- //DN to test that the rename test worked.
+ /** DN to test that the rename test worked. */
private String tuser1_rename=
"cn=new user.1, ou=People, ou=dept," + testSuffix;
private String tuser1_rdn="cn=new user.1";
- //Test DNs to add to various groups.
+ /** Test DNs to add to various groups. */
private String tuser2="uid=user.2, ou=People, ou=dept," + testSuffix;
private String tuser3="uid=user.3, ou=People, ou=dept," + testSuffix;
- //Groups to use for member and uniquemember attrbutes in dc=example, dc=com
- //suffix.
+ /** Groups to use for member and uniquemember attributes in dc=example, dc=com suffix. */
private String group = "cn=group, ou=groups," + exSuffix;
private String ugroup = "cn=group, ou=unique groups," + exSuffix;
- //DN to use for seeAlso attrbutes.
+ /** DN to use for seeAlso attributes. */
private String spPerson = "cn=special person, ou=Special People," + exSuffix;
- //Same as above but for o=test suffix.
+ /** Same as above but for o=test suffix. */
private String tgroup = "cn=group, ou=groups," + testSuffix;
private String tugroup = "cn=group, ou=unique groups," + testSuffix;
private String tspPerson =
@@ -128,9 +131,8 @@
* the correct suffixes.
*
* @throws Exception If an unexpected result is returned.
- *
*/
- @Test()
+ @Test
public void testModDNMoveTree() throws Exception {
//Add attributes interested in: member, uniquemember, seealso.
replaceAttrEntry(configDN, dsConfigAttrType,"member");
@@ -165,9 +167,8 @@
* under the correct suffixes.
*
* @throws Exception If an unexpected result is returned.
- *
*/
- @Test()
+ @Test
public void testReferentialDeleteTree() throws Exception {
// Add attributes interested in: member, uniquemember, seealso.
replaceAttrEntry(configDN, dsConfigAttrType,"member");
@@ -208,15 +209,13 @@
isAttributeValueEntry(spPerson, true, "seealso", user1, user2, user3);
}
- /**
+ /**
* Test that a rename changes the correct entries under
* the correct suffixes.
*
* @throws Exception If an unexpected result is returned.
- *
*/
-
- @Test()
+ @Test
public void testModDNMoveEntry() throws Exception {
//Add attributes interested in: member, uniquemember, seealso.
replaceAttrEntry(configDN, dsConfigAttrType,"member");
@@ -247,9 +246,8 @@
* Test a delete using public naming contexts as base DNs.
*
* @throws Exception If an unexpected result is returned.
- *
*/
- @Test()
+ @Test
public void testReferentialDelete() throws Exception {
replaceAttrEntry(configDN, dsConfigAttrType,"member");
addAttrEntry(DN.valueOf(tgroup), "member", tuser1, tuser2, tuser3);
@@ -260,13 +258,12 @@
/**
* Test that delete using public naming context works in both background
- * processing (set interval to 1 and wait 2 seconds) and forground. The
- * changes are made without restarting the server.
+ * processing (set interval to 1 and wait 2 seconds) and foreground.
+ * The changes are made without restarting the server.
*
* @throws Exception If an unexpected result happens.
- *
*/
- @Test()
+ @Test
public void testReferentialDeleteBackGround() throws Exception {
replaceAttrEntry(configDN, dsConfigAttrType,"member");
//Set interval to 1 second, this should start the background thread
@@ -277,8 +274,7 @@
//Wait two seconds and then check the group.
Thread.sleep(2000);
isMember(tgroup, false, tuser1, tuser2, tuser3);
- //Change the interval to zero seconds, this should stop the background
- //thread.
+ //Change the interval to zero seconds, this should stop the background thread
replaceAttrEntry(configDN, dsConfigUpdateInterval,"0 seconds");
addEntries(tuser1, tuser2, tuser3);
addAttrEntry(DN.valueOf(tgroup), "member", tuser1, tuser2, tuser3);
@@ -291,9 +287,8 @@
* Test delete using multiple attribute types and public naming contexts.
*
* @throws Exception If an unexpected result happened.
- *
*/
- @Test()
+ @Test
public void testReferentialDeleteAttrs() throws Exception {
replaceAttrEntry(configDN, dsConfigAttrType,"member");
addAttrEntry(configDN, dsConfigAttrType,"uniquemember", "seealso");
@@ -302,19 +297,16 @@
addAttrEntry(DN.valueOf(tspPerson), "seealso", tuser1, tuser2, tuser3);
deleteEntries(tuser1, tuser2, tuser3);
isMember(tgroup, false, tuser1, tuser2, tuser3);
- isAttributeValueEntry(tugroup, false, "uniquemember",
- tuser1, tuser2, tuser3);
- isAttributeValueEntry(tspPerson, false,"seealso",
- tuser1, tuser2, tuser3);
+ isAttributeValueEntry(tugroup, false, "uniquemember", tuser1, tuser2, tuser3);
+ isAttributeValueEntry(tspPerson, false,"seealso", tuser1, tuser2, tuser3);
}
/**
* Check delete with multiple attribute types and multiple suffixes.
*
* @throws Exception If an unexpected result happened.
- *
*/
- @Test()
+ @Test
public void testReferentialDeleteAttrsSuffix() throws Exception {
replaceAttrEntry(configDN, dsConfigAttrType,"member");
addAttrEntry(configDN, dsConfigAttrType,"uniquemember", "seealso");
@@ -810,9 +802,8 @@
*
* @throws Exception If an unexpected problem occurs.
*/
- @BeforeClass()
- public void startServer()
- throws Exception
+ @BeforeClass
+ public void startServer() throws Exception
{
TestCaseUtils.startServer();
configDN= DN.valueOf("cn=Referential Integrity ,cn=Plugins,cn=config");
@@ -823,7 +814,6 @@
* entries.
*
* @throws Exception If an unexpected problem occurs.
- *
*/
@BeforeMethod
public void clearConfigEntries() throws Exception {
@@ -1106,18 +1096,19 @@
*
*/
private AttributeType getAttrType(String attrTypeString) {
- AttributeType attrType =
- DirectoryServer.getAttributeType(attrTypeString);
+ AttributeType attrType = DirectoryServer.getAttributeType(attrTypeString);
if (attrType == null)
+ {
attrType = DirectoryServer.getDefaultAttributeType(attrTypeString);
+ }
return attrType;
}
private void deleteEntries(String... dns) throws Exception{
InternalClientConnection conn = getRootConnection();
for(String dn : dns) {
- DeleteOperation op=conn.processDelete(DN.valueOf(dn));
- assertEquals(op.getResultCode(), ResultCode.SUCCESS);
+ DeleteOperation op = conn.processDelete(DN.valueOf(dn));
+ assertEquals(op.getResultCode(), ResultCode.SUCCESS);
}
}
@@ -1153,12 +1144,13 @@
* @throws Exception If an unexpected membership occurs.
*
*/
- private void isMember(String group, boolean expected, String... dns)
- throws Exception {
+ private void isMember(String group, boolean expected, String... dns) throws Exception {
GroupManager groupManager=DirectoryServer.getGroupManager();
Group<?> instance=groupManager.getGroupInstance(DN.valueOf(group));
for(String dn : dns)
+ {
assertEquals(instance.isMember(DN.valueOf(dn)), expected);
+ }
}
private void isAttributeValueEntry(String entryDN, boolean expected,
@@ -1214,29 +1206,29 @@
/**
* Perform modify DN operation.
*
- * @param dn The DN to renmame or move.
- *
+ * @param dn The DN to rename or move.
* @param rdn RDN value.
- *
* @param newSuperior New superior to move to.
- *
* @throws Exception If the operation can't be performed.
- *
*/
- private void
- doModDN(String dn, String rdn, String newSuperior) throws Exception {
+ private void doModDN(String dn, String rdn, String newSuperior) throws Exception
+ {
InternalClientConnection conn = getRootConnection();
ModifyDNOperation modDNop;
if(newSuperior != null)
+ {
modDNop = conn.processModifyDN(DN.valueOf(dn), RDN.decode(rdn), true,
DN.valueOf(newSuperior));
+ }
else
+ {
modDNop = conn.processModifyDN(DN.valueOf(dn), RDN.decode(rdn),
false, null);
+ }
assertEquals(modDNop.getResultCode(), ResultCode.SUCCESS);
}
- /**
+ /**
* Test case:
* - integrity is enforced on the attribute 'manager'
* - value of the 'manager' attribute should match the filter:
@@ -1247,9 +1239,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddUserWitManagerFilterNoNC()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddUserWitManagerFilterNoNC() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1292,9 +1283,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddUserWitManagerFilter()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddUserWitManagerFilter() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1326,7 +1316,7 @@
"manager: uid=manager,ou=people,ou=dept,dc=example,dc=com");
}
- /**
+ /**
* Test case:
* - integrity is enforced on the attribute 'manager'
* - value of the 'manager' attribute should match the filter:
@@ -1336,9 +1326,8 @@
* - CONSTRAINT VIOLATION
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddUserWithMissingManagerEntry()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddUserWithMissingManagerEntry() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1368,11 +1357,10 @@
"manager: uid=bad,ou=people,ou=dept,dc=example,dc=com");
AddOperation addOperation = getRootConnection().processAdd(entry);
- assertEquals(addOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(addOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
- /**
+ /**
* Test case:
* - integrity is enforced on the attribute 'manager'
* - value of the 'manager' attribute should match the filter:
@@ -1384,9 +1372,8 @@
* - CONSTRAINT VIOLATION
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddUserWitManagerFilterMismatch()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddUserWitManagerFilterMismatch() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1418,11 +1405,10 @@
"manager: uid=manager,ou=people,ou=dept,dc=example,dc=com");
AddOperation addOperation = getRootConnection().processAdd(entry);
- assertEquals(addOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(addOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
- /**
+ /**
* Test case:
* - integrity is enforced on the attribute 'manager'
* - value of the 'manager' attribute should match the filter:
@@ -1433,9 +1419,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddUserWithManagerNC()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddUserWithManagerNC() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1479,9 +1464,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddGroupWithFilter()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddGroupWithFilter() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1521,9 +1505,8 @@
* - CONSTRAINT VIOLATION
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddGroupWithMissingMember()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddGroupWithMissingMember() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1553,8 +1536,7 @@
);
AddOperation addOperation = getRootConnection().processAdd(entry);
- assertEquals(addOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(addOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
/**
@@ -1568,9 +1550,8 @@
* - CONSTRAINT VIOLATION
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddGroupMemberFilterMismatch()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddGroupMemberFilterMismatch() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1600,8 +1581,7 @@
);
AddOperation addOperation = getRootConnection().processAdd(entry);
- assertEquals(addOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(addOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
/**
@@ -1615,9 +1595,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityAddGroupMemberNC()
- throws Exception
+ @Test
+ public void testEnforceIntegrityAddGroupMemberNC() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1656,9 +1635,8 @@
* - add 'manager' attribute to the manager entry
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityModifyUserAddManagerFilter()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyUserAddManagerFilter() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1691,9 +1669,8 @@
* - modify 'manager' attribute to the 'user.2' entry
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityModifyUserModifyManagerFilter()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyUserModifyManagerFilter() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1730,9 +1707,8 @@
* - constraint violation
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityModifyUserAddManagerFilterMismatch()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyUserAddManagerFilterMismatch() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1753,8 +1729,7 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(user1),
"manager", "uid=manager,ou=people,ou=dept,dc=example,dc=com");
- assertEquals(modOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(modOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
/**
@@ -1766,9 +1741,8 @@
* - SUCCESS
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityModifyUserAddManagerNC()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyUserAddManagerNC() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1791,8 +1765,7 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(user1),
"manager", "uid=manager,ou=people,ou=dept,o=test");
- assertEquals(modOperation.getResultCode(),
- ResultCode.SUCCESS);
+ assertEquals(modOperation.getResultCode(), ResultCode.SUCCESS);
}
/**
@@ -1803,9 +1776,8 @@
* - constraint violation
* @throws Exception
*/
- @Test()
- public void testEnforceIntegrityModifyUserAddManagerMissing()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyUserAddManagerMissing() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1824,13 +1796,11 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(user1),
"manager", "uid=manager,ou=people,ou=dept,dc=example,dc=com");
- assertEquals(modOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(modOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
- @Test()
- public void testEnforceIntegrityModifyGroupAddMember()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyGroupAddMember() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1853,9 +1823,8 @@
assertEquals(modOperation.getResultCode(), ResultCode.SUCCESS);
}
- @Test()
- public void testEnforceIntegrityModifyGroupAddMissingMember()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyGroupAddMissingMember() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1874,13 +1843,11 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(group),
"member", "uid=user.100,ou=people,ou=dept,dc=example,dc=com");
- assertEquals(modOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(modOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
- @Test()
- public void testEnforceIntegrityModifyGroupAddMemberFilterMismatch()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyGroupAddMemberFilterMismatch() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1899,13 +1866,11 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(group),
"member", "uid=user.100,ou=people,ou=dept,dc=example,dc=com");
- assertEquals(modOperation.getResultCode(),
- ResultCode.CONSTRAINT_VIOLATION);
+ assertEquals(modOperation.getResultCode(), ResultCode.CONSTRAINT_VIOLATION);
}
- @Test()
- public void testEnforceIntegrityModifyGroupAddMemberNC()
- throws Exception
+ @Test
+ public void testEnforceIntegrityModifyGroupAddMemberNC() throws Exception
{
replaceAttrEntry(configDN, "ds-cfg-enabled", "false");
replaceAttrEntry(configDN, dsConfigPluginType,
@@ -1926,7 +1891,6 @@
ModifyOperation modOperation = addAttrEntry(DN.valueOf(group),
"member", "uid=user.1,ou=people,ou=dept,o=test");
- assertEquals(modOperation.getResultCode(),
- ResultCode.SUCCESS);
+ assertEquals(modOperation.getResultCode(), ResultCode.SUCCESS);
}
}
--
Gitblit v1.10.0