From 7a513878d4797fe8379a4b222111445235d39ae2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 11 Feb 2015 12:40:18 +0000
Subject: [PATCH] Code cleanup

---
 opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ImportIDSet.java                         |    4 +-
 opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ImportLDIFTestCase.java |  100 ++++++++++++++++++++++----------------------------
 2 files changed, 46 insertions(+), 58 deletions(-)

diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ImportIDSet.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ImportIDSet.java
index 45705d4..f3591f8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ImportIDSet.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ImportIDSet.java
@@ -428,13 +428,13 @@
   public byte[] toDatabase()
   {
     if(isDefined) {
-      return encode();
+      return encodeDefined();
     } else {
       return JebFormat.entryIDUndefinedSizeToDatabase(undefinedSize);
     }
   }
 
-  private byte[] encode()
+  private byte[] encodeDefined()
   {
     final int encodedSize = count * 8;
     final byte[] bytes = new byte[encodedSize];
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ImportLDIFTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ImportLDIFTestCase.java
index 7a50342..03901ef 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ImportLDIFTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ImportLDIFTestCase.java
@@ -22,10 +22,13 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2013-2014 ForgeRock AS.
+ *      Portions Copyright 2013-2015 ForgeRock AS.
  */
 package org.opends.server.tools;
 
+import static org.opends.server.TestCaseUtils.*;
+import static org.testng.Assert.*;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
@@ -43,9 +46,6 @@
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import static org.opends.server.TestCaseUtils.*;
-import static org.testng.Assert.*;
-
 @SuppressWarnings("javadoc")
 public class ImportLDIFTestCase extends ToolsTestCase
 {
@@ -68,17 +68,28 @@
     configFilePath = DirectoryServer.getConfigFile();
     TaskUtils.disableBackend(beID);
 
-    String entry = "dn: dc=example,dc=com\n" + "objectclass: domain\n"
-        + "objectclass: top\n" + "dc: example\n\n"
-        + "dn: uid=user.0,dc=example,dc=com\n" + "objectClass: person\n"
+    String entry =
+        "dn: dc=example,dc=com\n"
+        + "objectclass: domain\n"
+        + "objectclass: top\n"
+        + "dc: example\n"
+        + "\n"
+        + "dn: uid=user.0,dc=example,dc=com\n"
+        + "objectClass: person\n"
         + "objectClass: inetorgperson\n"
-        + "objectClass: organizationalPerson\n" + "objectClass: top\n"
-        + "givenName: Aaccf\n" + "sn: Amar\n" + "cn: Aaccf Amar\n"
-        + "employeeNumber: 0\n" + "uid: user.0\n"
-        + "mail: user.0@example.com\n" + "userPassword: password\n"
+        + "objectClass: organizationalPerson\n"
+        + "objectClass: top\n"
+        + "givenName: Aaccf\n"
+        + "sn: Amar\n"
+        + "cn: Aaccf Amar\n"
+        + "employeeNumber: 0\n"
+        + "uid: user.0\n"
+        + "mail: user.0@example.com\n"
+        + "userPassword: password\n"
         + "telephoneNumber: +1 380-535-2354\n"
         + "description: This is the description for Aaccf Amar\n"
-        + "creatorsName: cn=Import\n" + "modifiersName: cn=Import\n";
+        + "creatorsName: cn=Import\n"
+        + "modifiersName: cn=Import\n";
 
     tempDir = TestCaseUtils.createTemporaryDirectory("importLDIFtest");
     homeDirName = tempDir.getAbsolutePath();
@@ -117,8 +128,7 @@
         "-i",
         "+"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     // Expecting a non-empty reject file.
     assertRejectedFile(reject, false);
   }
@@ -149,8 +159,7 @@
         "-i",
         "*"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     // Expecting an empty reject file.
     assertRejectedFile(reject, true);
 
@@ -186,8 +195,7 @@
         "-R",
         rejectFilePath
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     // Reject file should be empty.
     assertRejectedFile(reject, true);
     // check the presence of some random attributes.
@@ -224,8 +232,7 @@
         "-R",
         rejectFilePath
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     // Reject file should be empty.
     assertRejectedFile(reject, true);
     // check the presence of some random attributes.
@@ -240,7 +247,7 @@
 
   /**
    * Tests an import of LDIF with all the user attributes included but
-   * "description"
+   * "description".
    */
   @Test
   public void testImportLDIFIncludeUserExcludeDescription() throws Exception
@@ -266,8 +273,7 @@
         "description"
     };
 
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, true);
     assertEntry(false,
         Attributes.create("description", "This is the description for Aaccf Amar"));
@@ -299,8 +305,7 @@
         "*"
     };
 
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, false);
   }
 
@@ -331,16 +336,13 @@
         "-e",
         "+"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, true);
     assertEntry(false,
         Attributes.create("creatorsname", "cn=Import"),
         Attributes.create("modifiersname", "cn=Import"));
   }
 
-
-
   /**
    * Tests an import of LDIF with all user attributes and one
    * operational attribute included..
@@ -348,7 +350,6 @@
   @Test
   public void testImportLDIFUserAndOperational() throws Exception
   {
-
     File reject = File.createTempFile("reject", ".ldif");
     String rejectFilePath = reject.getAbsolutePath();
     String[] args =
@@ -368,8 +369,7 @@
         "-i",
         "creatorsname"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, true);
     assertEntry(true, Attributes.create("creatorsname", "cn=Import"));
   }
@@ -383,7 +383,6 @@
   @Test
   public void testImportLDIFSelectiveIncludeAttributes() throws Exception
   {
-
     File reject = File.createTempFile("reject", ".ldif");
     String rejectFilePath = reject.getAbsolutePath();
     String[] args =
@@ -409,8 +408,7 @@
         "-i",
         "creatorsname"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, true);
     assertEntry(true,
         Attributes.create("creatorsname", "cn=Import"));
@@ -447,8 +445,7 @@
         "-e",
         "creatorsname"
     };
-    assertEquals(
-        ImportLDIF.mainImportLDIF(args, false, System.out, System.err), 0);
+    assertEquals(importLDIF(args), 0);
     assertRejectedFile(reject, true);
     assertEntry(true,
         Attributes.create("modifiersname", "cn=Import"),
@@ -458,7 +455,10 @@
         Attributes.create("givenname", "Aaccf"));
   }
 
-
+  private int importLDIF(String[] args)
+  {
+    return ImportLDIF.mainImportLDIF(args, false, System.out, System.err);
+  }
 
   /**
    * Utility method which is called by the testcase for asserting the rejected
@@ -473,21 +473,11 @@
   {
     try
     {
-      if (shouldBeEmpty)
-      {
-        if (reject.length() > 0)
-        {
-          RootCfg root = ServerManagementContext.getInstance()
-              .getRootConfiguration();
-          fail("Unexpected content in reject file:\n\n" + readFile(reject)
-              + "\n\nThe backend was configured with the following base DNs: "
-              + root.getBackend(beID).getBaseDN() + "\n\n");
-        }
-      }
-      else
-      {
-        assertFalse(reject.length() == 0);
-      }
+      final RootCfg root = ServerManagementContext.getInstance().getRootConfiguration();
+      final String errorMsg = "Unexpected content in reject file:\n\n" + readFile(reject)
+          + "\n\nThe backend was configured with the following base DNs: "
+          + root.getBackend(beID).getBaseDN() + "\n\n";
+      assertEquals(reject.length() == 0, shouldBeEmpty, errorMsg);
     }
     finally
     {
@@ -522,9 +512,7 @@
     }
   }
 
-  /**
-   * Clean up method.
-   */
+  /** Clean up method. */
   @AfterClass
   public void cleanUp() throws Exception
   {

--
Gitblit v1.10.0