From 42317cc5ab606b8cffc01341d90e85ac7fb958f4 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 16 Jan 2014 00:22:16 +0000
Subject: [PATCH] Move two utility methods from SdkTestCase to TestCaseUtils so that test classes are not always forced to sub-class from SdkTestCase.

---
 opendj-core/src/test/java/org/forgerock/opendj/ldap/HeartBeatConnectionFactoryTestCase.java     |    4 +-
 opendj-core/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java                          |   28 ++++++++++++++
 opendj-config/src/test/java/org/forgerock/opendj/config/ConfigTestCase.java                     |    4 +-
 opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java                           |    7 ++-
 opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java                  |    4 +-
 opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java      |    5 +-
 opendj-core/src/test/java/org/forgerock/opendj/ldap/SdkTestCase.java                            |   30 ---------------
 opendj-config/src/test/java/org/forgerock/opendj/config/server/ConstraintTest.java              |    1 
 opendj-core/src/test/java/org/forgerock/opendj/ldif/EntryGeneratorTestCase.java                 |    4 +-
 opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithmTestCase.java |    4 +-
 opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractAsynchronousConnectionTestCase.java |   16 ++++----
 opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java        |    4 +-
 12 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/opendj-config/src/test/java/org/forgerock/opendj/config/ConfigTestCase.java b/opendj-config/src/test/java/org/forgerock/opendj/config/ConfigTestCase.java
index d8a4837..7d1f250 100644
--- a/opendj-config/src/test/java/org/forgerock/opendj/config/ConfigTestCase.java
+++ b/opendj-config/src/test/java/org/forgerock/opendj/config/ConfigTestCase.java
@@ -25,13 +25,13 @@
  */
 package org.forgerock.opendj.config;
 
-import org.forgerock.opendj.ldap.SdkTestCase;
+import org.forgerock.testng.ForgeRockTestCase;
 import org.testng.annotations.Test;
 
 /**
  * An abstract class that all unit tests should extend.
  */
 @Test(groups = { "precommit", "config" })
-public abstract class ConfigTestCase extends SdkTestCase {
+public abstract class ConfigTestCase extends ForgeRockTestCase {
    // no implementation
 }
diff --git a/opendj-config/src/test/java/org/forgerock/opendj/config/server/ConstraintTest.java b/opendj-config/src/test/java/org/forgerock/opendj/config/server/ConstraintTest.java
index 73be5bb..1dcc9df 100644
--- a/opendj-config/src/test/java/org/forgerock/opendj/config/server/ConstraintTest.java
+++ b/opendj-config/src/test/java/org/forgerock/opendj/config/server/ConstraintTest.java
@@ -26,6 +26,7 @@
 package org.forgerock.opendj.config.server;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.forgerock.opendj.ldap.TestCaseUtils.failWasExpected;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.verify;
 
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractAsynchronousConnectionTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractAsynchronousConnectionTestCase.java
index 15a852c..5adf70a 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractAsynchronousConnectionTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractAsynchronousConnectionTestCase.java
@@ -401,7 +401,7 @@
         List<SearchResultEntry> entries = new LinkedList<SearchResultEntry>();
         try {
             mockConnection.search(searchRequest, entries);
-            failWasExpected(ErrorResultException.class);
+            TestCaseUtils.failWasExpected(ErrorResultException.class);
         } catch (ErrorResultException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM);
             assertThat(entries.isEmpty());
@@ -439,7 +439,7 @@
                 Requests.newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)");
         try {
             mockConnection.searchSingleEntry(request);
-            failWasExpected(EntryNotFoundException.class);
+            TestCaseUtils.failWasExpected(EntryNotFoundException.class);
         } catch (EntryNotFoundException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_NO_RESULTS_RETURNED);
         }
@@ -453,7 +453,7 @@
                 Requests.newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)");
         try {
             mockConnection.searchSingleEntry(request);
-            failWasExpected(MultipleEntriesFoundException.class);
+            TestCaseUtils.failWasExpected(MultipleEntriesFoundException.class);
         } catch (MultipleEntriesFoundException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED);
         }
@@ -469,7 +469,7 @@
                 Requests.newSingleEntrySearchRequest("cn=test", SearchScope.WHOLE_SUBTREE, "(objectClass=*)");
         try {
             mockConnection.searchSingleEntry(request);
-            failWasExpected(MultipleEntriesFoundException.class);
+            TestCaseUtils.failWasExpected(MultipleEntriesFoundException.class);
         } catch (MultipleEntriesFoundException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED);
         }
@@ -486,7 +486,7 @@
 
         try {
             mockConnection.searchSingleEntryAsync(request, handler).get();
-            failWasExpected(MultipleEntriesFoundException.class);
+            TestCaseUtils.failWasExpected(MultipleEntriesFoundException.class);
         } catch (MultipleEntriesFoundException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED);
             verify(handler).handleErrorResult(any(ErrorResultException.class));
@@ -505,7 +505,7 @@
         ResultHandler<SearchResultEntry> handler = mock(ResultHandler.class);
         try {
             mockConnection.searchSingleEntryAsync(request, handler).get();
-            failWasExpected(MultipleEntriesFoundException.class);
+            TestCaseUtils.failWasExpected(MultipleEntriesFoundException.class);
         } catch (MultipleEntriesFoundException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED);
             verify(handler).handleErrorResult(any(ErrorResultException.class));
@@ -519,7 +519,7 @@
                 Requests.newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)");
         try {
             mockConnection.searchSingleEntry(request);
-            failWasExpected(ErrorResultException.class);
+            TestCaseUtils.failWasExpected(ErrorResultException.class);
         } catch (ErrorResultException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM);
         }
@@ -534,7 +534,7 @@
         ResultHandler<SearchResultEntry> handler = mock(ResultHandler.class);
         try {
             mockConnection.searchSingleEntryAsync(request, handler).get();
-            failWasExpected(ErrorResultException.class);
+            TestCaseUtils.failWasExpected(ErrorResultException.class);
         } catch (ErrorResultException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM);
             verify(handler).handleErrorResult(any(ErrorResultException.class));
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithmTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithmTestCase.java
index e77e63f..f0982e2 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithmTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/AbstractLoadBalancingAlgorithmTestCase.java
@@ -87,7 +87,7 @@
      */
     @BeforeClass()
     public void disableLogging() {
-        setDefaultLogLevel(Level.SEVERE);
+        TestCaseUtils.setDefaultLogLevel(Level.SEVERE);
     }
 
     /**
@@ -95,7 +95,7 @@
      */
     @AfterClass()
     public void enableLogging() {
-        setDefaultLogLevel(Level.INFO);
+        TestCaseUtils.setDefaultLogLevel(Level.INFO);
     }
 
     /**
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/HeartBeatConnectionFactoryTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/HeartBeatConnectionFactoryTestCase.java
index c533a21..01a7f34 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/HeartBeatConnectionFactoryTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/HeartBeatConnectionFactoryTestCase.java
@@ -93,7 +93,7 @@
      */
     @BeforeClass()
     public void disableLogging() {
-        setDefaultLogLevel(Level.SEVERE);
+        TestCaseUtils.setDefaultLogLevel(Level.SEVERE);
     }
 
     /**
@@ -101,7 +101,7 @@
      */
     @AfterClass()
     public void enableLogging() {
-        setDefaultLogLevel(Level.INFO);
+        TestCaseUtils.setDefaultLogLevel(Level.INFO);
     }
 
     @AfterMethod(alwaysRun = true)
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java
index 6b729c1..c00ca54 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/MemoryBackendTestCase.java
@@ -434,7 +434,7 @@
                         "objectClass: top", "dc: example"));
         try {
             reader.hasNext();
-            failWasExpected(ErrorResultIOException.class);
+            TestCaseUtils.failWasExpected(ErrorResultIOException.class);
         } catch (ErrorResultIOException e) {
             assertThat(e.getCause().getResult().getResultCode()).isEqualTo(ResultCode.SIZE_LIMIT_EXCEEDED);
         }
@@ -463,7 +463,7 @@
             connection.search(
                     Requests.newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=*)").
                     setSizeLimit(2), entries);
-            failWasExpected(ErrorResultException.class);
+            TestCaseUtils.failWasExpected(ErrorResultException.class);
         } catch (ErrorResultException e) {
             assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.SIZE_LIMIT_EXCEEDED);
             assertThat(entries).hasSize(2);
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/SdkTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/SdkTestCase.java
index b70cf4c..e13003f 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/SdkTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/SdkTestCase.java
@@ -26,16 +26,9 @@
  */
 package org.forgerock.opendj.ldap;
 
-import static org.fest.assertions.Fail.*;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 import org.forgerock.testng.ForgeRockTestCase;
 import org.testng.annotations.Test;
 
-import com.forgerock.opendj.util.StaticUtils;
-
 /**
  * An abstract class that all types unit tests should extend. A type represents
  * the classes found directly under the package org.forgerock.opendj.ldap.
@@ -43,27 +36,4 @@
 @Test(groups = { "precommit", "types", "sdk" })
 public abstract class SdkTestCase extends ForgeRockTestCase {
 
-    /**
-     * Fail with precise message giving the exception that was expected.
-     *
-     * @param exceptionClass expected exception
-     */
-    protected void failWasExpected(Class<? extends Throwable> exceptionClass) {
-        fail("should throw an exception " + exceptionClass.getSimpleName());
-    }
-
-    /**
-     * Dynamically change log level using java.util.logging framework.
-     * <p>
-     * slf4j ERROR maps to java.util.logging SEVERE
-     * slf4j INFO maps to java.util.logging INFO
-     * slf4j DEBUG maps to java.util.logging FINE
-     * slf4j TRACE maps to java.util.logging FINEST
-     *
-     * @param level logging level to use
-     */
-    protected void setDefaultLogLevel(Level level) {
-        Logger.getLogger(StaticUtils.DEFAULT_LOG.getName()).setLevel(level);
-    }
-
 }
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
index 944ad9f..b23e4e0 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
@@ -27,10 +27,12 @@
 
 package org.forgerock.opendj.ldap;
 
+import static org.fest.assertions.Fail.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -38,12 +40,15 @@
 import java.net.ServerSocket;
 import java.net.SocketAddress;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.mockito.stubbing.OngoingStubbing;
 
 import com.forgerock.opendj.util.CompletedFutureResult;
+import com.forgerock.opendj.util.StaticUtils;
 import com.forgerock.opendj.util.TimeSource;
 
 /**
@@ -241,4 +246,27 @@
         return mock;
     }
 
+    /**
+     * Fail with precise message giving the exception that was expected.
+     *
+     * @param exceptionClass expected exception
+     */
+    public static void failWasExpected(Class<? extends Throwable> exceptionClass) {
+        fail("should throw an exception " + exceptionClass.getSimpleName());
+    }
+
+    /**
+     * Dynamically change log level using java.util.logging framework.
+     * <p>
+     * slf4j ERROR maps to java.util.logging SEVERE
+     * slf4j INFO maps to java.util.logging INFO
+     * slf4j DEBUG maps to java.util.logging FINE
+     * slf4j TRACE maps to java.util.logging FINEST
+     *
+     * @param level logging level to use
+     */
+    public static void setDefaultLogLevel(Level level) {
+        Logger.getLogger(StaticUtils.DEFAULT_LOG.getName()).setLevel(level);
+    }
+
 }
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldif/EntryGeneratorTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldif/EntryGeneratorTestCase.java
index 4ec433b..dbfc8af 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldif/EntryGeneratorTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldif/EntryGeneratorTestCase.java
@@ -26,7 +26,6 @@
 package org.forgerock.opendj.ldif;
 
 import static com.forgerock.opendj.ldap.CoreMessages.*;
-
 import static org.fest.assertions.Assertions.*;
 import static org.forgerock.opendj.ldap.TestCaseUtils.getTestFilePath;
 import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
@@ -44,6 +43,7 @@
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.Entry;
 import org.forgerock.opendj.ldap.SdkTestCase;
+import org.forgerock.opendj.ldap.TestCaseUtils;
 import org.forgerock.opendj.ldap.schema.Schema;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
@@ -389,7 +389,7 @@
 
         try {
             templateFile.parse(lines, warns);
-            failWasExpected(DecodeException.class);
+            TestCaseUtils.failWasExpected(DecodeException.class);
         } catch (DecodeException e) {
             LocalizableMessage expected = ERR_ENTRY_GENERATOR_TAG_UNDEFINED_ATTRIBUTE.get("missingVar", 1);
             assertThat(e.getMessage()).isEqualTo(expected.toString());
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java
index 41839f9..436b660 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java
@@ -48,6 +48,7 @@
 import org.forgerock.opendj.ldap.Modification;
 import org.forgerock.opendj.ldap.ModificationType;
 import org.forgerock.opendj.ldap.SearchScope;
+import org.forgerock.opendj.ldap.TestCaseUtils;
 import org.forgerock.opendj.ldap.requests.AddRequest;
 import org.forgerock.opendj.ldap.requests.DeleteRequest;
 import org.forgerock.opendj.ldap.requests.ModifyRequest;
@@ -2811,7 +2812,7 @@
     public void testMakeEntryEmpty() throws Exception {
         try {
             LDIF.makeEntry();
-            failWasExpected(LocalizedIllegalArgumentException.class);
+            TestCaseUtils.failWasExpected(LocalizedIllegalArgumentException.class);
         } catch (LocalizedIllegalArgumentException e) {
             assertThat(e.getMessageObject()).isEqualTo(CoreMessages.WARN_READ_LDIF_ENTRY_NO_ENTRY_FOUND.get());
         }
@@ -2821,7 +2822,7 @@
     public void testMakeEntryWithMultipleEntries() throws Exception {
         try {
             LDIF.makeEntry(LDIF_TWO_ENTRIES);
-            failWasExpected(LocalizedIllegalArgumentException.class);
+            TestCaseUtils.failWasExpected(LocalizedIllegalArgumentException.class);
         } catch (LocalizedIllegalArgumentException e) {
             assertThat(e.getMessageObject()).isEqualTo(
                 CoreMessages.WARN_READ_LDIF_ENTRY_MULTIPLE_ENTRIES_FOUND.get(2));
@@ -2837,7 +2838,7 @@
     public void testMakeEntriesEmpty() throws Exception {
         try {
             LDIF.makeEntries();
-            failWasExpected(LocalizedIllegalArgumentException.class);
+            TestCaseUtils.failWasExpected(LocalizedIllegalArgumentException.class);
         } catch (LocalizedIllegalArgumentException e) {
             assertThat(e.getMessageObject()).isEqualTo(CoreMessages.WARN_READ_LDIF_ENTRY_NO_ENTRY_FOUND.get());
         }
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
index 3e08ebc..8171e10 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/ConnectionFactoryTestCase.java
@@ -145,7 +145,7 @@
      */
     @BeforeClass()
     public void disableLogging() {
-        setDefaultLogLevel(Level.SEVERE);
+        TestCaseUtils.setDefaultLogLevel(Level.SEVERE);
     }
 
     /**
@@ -153,7 +153,7 @@
      */
     @AfterClass()
     public void enableLogging() {
-        setDefaultLogLevel(Level.INFO);
+        TestCaseUtils.setDefaultLogLevel(Level.INFO);
     }
 
     @DataProvider
diff --git a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
index 1ce1e6e..776a00c 100644
--- a/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
+++ b/opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPListenerTestCase.java
@@ -56,6 +56,7 @@
 import org.forgerock.opendj.ldap.SearchResultHandler;
 import org.forgerock.opendj.ldap.ServerConnection;
 import org.forgerock.opendj.ldap.ServerConnectionFactory;
+import org.forgerock.opendj.ldap.TestCaseUtils;
 import org.forgerock.opendj.ldap.requests.AbandonRequest;
 import org.forgerock.opendj.ldap.requests.AddRequest;
 import org.forgerock.opendj.ldap.requests.BindRequest;
@@ -240,7 +241,7 @@
      */
     @BeforeClass()
     public void disableLogging() {
-        setDefaultLogLevel(Level.SEVERE);
+        TestCaseUtils.setDefaultLogLevel(Level.SEVERE);
     }
 
     /**
@@ -248,7 +249,7 @@
      */
     @AfterClass()
     public void enableLogging() {
-        setDefaultLogLevel(Level.INFO);
+        TestCaseUtils.setDefaultLogLevel(Level.INFO);
     }
 
     /**

--
Gitblit v1.10.0