From cbf6bfd149ce305652be0aac68d210778b5cbba6 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 03 Oct 2013 11:59:25 +0000
Subject: [PATCH] ReplicationTestCase.java: Change entryList and configEntryList from LinkedList to Set and renamed them to entriesToCleanup and configEntriesToCleanup. Extracted method connect() and waitForSpecificMsg() + Changed the return type of the existing waitForSpecificMsg() methods. In configureReplication(), added 2 String parameters + extracted method addSynchroServerEntry() and addConfigEntry(). Simplified code a lot.

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/SchemaReplicationTest.java |   62 +++++++++----------------------
 1 files changed, 18 insertions(+), 44 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/SchemaReplicationTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/SchemaReplicationTest.java
index ff51088..f1ab201 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/SchemaReplicationTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/SchemaReplicationTest.java
@@ -32,6 +32,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.assertj.core.api.Assertions;
 import org.opends.messages.Category;
 import org.opends.messages.Message;
 import org.opends.messages.Severity;
@@ -92,7 +93,6 @@
         + "ds-cfg-replication-port: " + replServerPort + "\n"
         + "ds-cfg-replication-db-directory: SchemaReplicationTest\n"
         + "ds-cfg-replication-server-id: 105\n";
-    replServerEntry = TestCaseUtils.entryFromLdifString(replServerLdif);
 
     // suffix synchronized
     String testName = "schemaReplicationTest";
@@ -104,9 +104,8 @@
         + "ds-cfg-base-dn: cn=schema\n"
         + "ds-cfg-replication-server: localhost:" + replServerPort + "\n"
         + "ds-cfg-server-id: 1\n";
-    synchroServerEntry = TestCaseUtils.entryFromLdifString(domainLdif);
 
-    configureReplication();
+    configureReplication(replServerLdif, domainLdif);
   }
 
   /**
@@ -140,30 +139,21 @@
       modOp.setInternalOperation(true);
       modOp.run();
 
-      ResultCode code = modOp.getResultCode();
-      assertTrue(code.equals(ResultCode.SUCCESS),
-                 "The original operation failed: " + code.getResultCodeName());
+      assertEquals(modOp.getResultCode(), ResultCode.SUCCESS,
+          "The original operation failed");
 
       // See if the client has received the msg
       ReplicationMsg msg = broker.receive();
-
-      assertTrue(msg instanceof ModifyMsg,
-                 "The received replication message is not a MODIFY msg");
+      Assertions.assertThat(msg).isInstanceOf(ModifyMsg.class);
       ModifyMsg modMsg = (ModifyMsg) msg;
 
       Operation receivedOp = modMsg.createOperation(connection);
-      assertEquals(modMsg.getDN(), baseDN,
-                 "The received message is not for cn=schema");
-
-      assertTrue(receivedOp instanceof ModifyOperation,
-                 "The received replication message is not a MODIFY msg");
+      assertEquals(modMsg.getDN(), baseDN, "The received message is not for cn=schema");
+      Assertions.assertThat(receivedOp).isInstanceOf(ModifyOperation.class);
       ModifyOperation receivedModifyOperation = (ModifyOperation) receivedOp;
 
-      List<RawModification> rcvdRawMods =
-        receivedModifyOperation.getRawModifications();
-
       this.rcvdMods = new ArrayList<Modification>();
-      for (RawModification m : rcvdRawMods)
+      for (RawModification m : receivedModifyOperation.getRawModifications())
       {
         this.rcvdMods.add(m.toModification());
       }
@@ -183,15 +173,12 @@
       modOp.setInternalOperation(true);
       modOp.run();
 
-      code = modOp.getResultCode();
-      assertTrue(code.equals(ResultCode.SUCCESS),
-                 "The original operation failed" + code.getResultCodeName());
+      assertEquals(modOp.getResultCode(), ResultCode.SUCCESS,
+          "The original operation failed");
 
       // See if the client has received the msg
       msg = broker.receive();
-
-      assertTrue(msg instanceof ModifyMsg,
-                 "The received replication message is not a MODIFY msg");
+      Assertions.assertThat(msg).isInstanceOf(ModifyMsg.class);
     }
     finally
     {
@@ -227,9 +214,7 @@
       boolean found = checkEntryHasAttribute(baseDN, "attributetypes",
         "( 2.5.44.77.33 NAME 'dummy' )",
         10000, true);
-
-      if (found == false)
-        fail("The modification has not been correctly replayed.");
+      assertTrue(found, "The modification has not been correctly replayed.");
     }
     finally
     {
@@ -272,24 +257,16 @@
 
       // receive the message on the broker side.
       ReplicationMsg msg = broker.receive();
-
-      assertTrue(msg instanceof ModifyMsg,
-        "The received replication message is not a MODIFY msg");
+      Assertions.assertThat(msg).isInstanceOf(ModifyMsg.class);
       ModifyMsg modMsg = (ModifyMsg) msg;
 
       Operation receivedOp = modMsg.createOperation(connection);
-      assertEquals(modMsg.getDN(), baseDN,
-        "The received message is not for cn=schema");
-
-      assertTrue(receivedOp instanceof ModifyOperation,
-        "The received replication message is not a MODIFY msg");
+      assertEquals(modMsg.getDN(), baseDN, "The received message is not for cn=schema");
+      Assertions.assertThat(receivedOp).isInstanceOf(ModifyOperation.class);
       ModifyOperation receivedModifyOperation = (ModifyOperation) receivedOp;
 
-      List<RawModification> rcvdRawMods =
-        receivedModifyOperation.getRawModifications();
-
       this.rcvdMods = new ArrayList<Modification>();
-      for (RawModification m : rcvdRawMods)
+      for (RawModification m : receivedModifyOperation.getRawModifications())
       {
         this.rcvdMods.add(m.toModification());
       }
@@ -327,11 +304,8 @@
         {
           break;
         }
-        if (count++ > 50)
-        {
-          fail("The Schema persistentState (CSN:" + stateStr
-              + ") has not been saved to " + path + " : " + fileStr);
-        }
+        assertTrue(count++ <= 50, "The Schema persistentState (CSN:" + stateStr
+            + ") has not been saved to " + path + " : " + fileStr);
         TestCaseUtils.sleep(100);
       }
     } finally

--
Gitblit v1.10.0