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 } 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; 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)); 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); } /** 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) 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); 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); } } 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); } } 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()); 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()); } 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 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); } /**