Skip to content

Commit

Permalink
POM/test: AbstractUnitTest moved to test-ng module, fixed cycle dep
Browse files Browse the repository at this point in the history
This probably doesn't compile, but...
- AbstractUnitTest and UnitTestMixin are moved to tools/test-ng
- UnitTestMixin doesn't need TestUtil for display duties anymore
  • Loading branch information
virgo47 committed Mar 1, 2020
1 parent 46800ad commit b9ead3a
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 151 deletions.
5 changes: 0 additions & 5 deletions infra/prism-impl/pom.xml
Expand Up @@ -147,11 +147,6 @@
<artifactId>test-ng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.infra</groupId>
<artifactId>test-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions infra/schema/pom.xml
Expand Up @@ -153,12 +153,6 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.infra</groupId>
<artifactId>test-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
8 changes: 5 additions & 3 deletions infra/test-util/pom.xml
Expand Up @@ -18,7 +18,7 @@
<artifactId>test-util</artifactId>
<packaging>jar</packaging>

<name>midPoint Infrastructure - testing mock utils</name>
<name>midPoint Infrastructure - testing utils (lvl 2)</name>

<repositories>
<repository>
Expand Down Expand Up @@ -105,8 +105,10 @@
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<version>4.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
Expand Down
Expand Up @@ -6,11 +6,13 @@
*/
package com.evolveum.midpoint.test.util;

import org.jetbrains.annotations.NotNull;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.evolveum.midpoint.tools.testng.UnitTestMixin;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

Expand All @@ -33,7 +35,7 @@ public abstract class AbstractSpringTest extends AbstractTestNGSpringContextTest
public void startTestContext(ITestResult testResult) {
Class<?> testClass = testResult.getMethod().getTestClass().getRealClass();
String testMethodName = testResult.getMethod().getMethodName();
TestUtil.displayTestTitle(testClass.getSimpleName() + "." + testMethodName);
displayTestTitle(testClass.getSimpleName() + "." + testMethodName);

TEST_CONTEXT_THREAD_LOCAL.set(testResult);
}
Expand All @@ -45,6 +47,19 @@ public void finishTestContext(ITestResult testResult) {
displayDefaultTestFooter(testResult);
}

@Override
public Trace logger() {
return logger;
}

@NotNull
public String contextName() {
ITestResult context = TEST_CONTEXT_THREAD_LOCAL.get();
return context != null
? getClass().getSimpleName() + "." + context.getMethod().getMethodName()
: getClass().getSimpleName();
}

@Override
public String getTestNameShort() {
return TEST_CONTEXT_THREAD_LOCAL.get().getMethod().getMethodName();
Expand Down
Expand Up @@ -44,7 +44,6 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.TestNameHolder;
import com.evolveum.midpoint.util.JAXBUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
Expand All @@ -62,12 +61,6 @@ public class TestUtil {

public static final int MAX_EXCEPTION_MESSAGE_LENGTH = 500;

public static final String TEST_LOG_PREFIX = "=====[ ";
public static final String TEST_LOG_SUFFIX = " ]======================================";
public static final String TEST_OUT_PREFIX = "\n\n=====[ ";
public static final String TEST_OUT_SUFFIX = " ]======================================\n";
public static final String TEST_OUT_FOOTER_PREFIX = "====== ";
public static final String TEST_OUT_FOOTER_SUFFIX = "\n";
public static final String TEST_OUT_SECTION_PREFIX = "\n\n----- ";
public static final String TEST_OUT_SECTION_SUFFIX = " --------------------------------------\n";
public static final String TEST_LOG_SECTION_PREFIX = "----- ";
Expand Down Expand Up @@ -161,49 +154,6 @@ public static void assertExceptionSanity(ObjectAlreadyExistsException e) {
+ e.getMessage().length() + " characters): " + e.getMessage();
}

public static void displayTestTitle(String testName) {
System.out.println(TEST_OUT_PREFIX + testName + TEST_OUT_SUFFIX);
LOGGER.info(TEST_LOG_PREFIX + testName + TEST_LOG_SUFFIX);
TestNameHolder.setCurrentTestName(testName);
}

public static void displayTestTitle(Object testCase, String testName) {
String qualifiedTestName = testCase.getClass().getSimpleName() + "." + testName;
System.out.println(TEST_OUT_PREFIX + qualifiedTestName + TEST_OUT_SUFFIX);
LOGGER.info(TEST_LOG_PREFIX + qualifiedTestName + TEST_LOG_SUFFIX);
TestNameHolder.setCurrentTestName(qualifiedTestName);
}

public static void displayFooter(String footerText) {
System.out.println(TEST_OUT_FOOTER_PREFIX + footerText + TEST_OUT_FOOTER_SUFFIX);
LOGGER.info(TEST_LOG_PREFIX + footerText + TEST_LOG_SUFFIX);
}

@Deprecated // use version with separate testName and description
public static void displayWhen(String what) {
System.out.println(TEST_OUT_SECTION_PREFIX + " WHEN " + what + TEST_OUT_SECTION_SUFFIX);
LOGGER.info(TEST_LOG_SECTION_PREFIX + " WHEN " + what + TEST_LOG_SECTION_SUFFIX);
}

public static void displayWhen(String testName, String description) {
if (description == null) {
description = "";
}
System.out.println(TEST_OUT_SECTION_PREFIX + testName + ": WHEN " + description + TEST_OUT_SECTION_SUFFIX);
LOGGER.info(TEST_LOG_SECTION_PREFIX + testName + ": WHEN " + description + TEST_LOG_SECTION_SUFFIX);
}

@Deprecated // use version with separate testName and description
public static void displayThen(String testName) {
System.out.println(TEST_OUT_SECTION_PREFIX + " THEN " + testName + TEST_OUT_SECTION_SUFFIX);
LOGGER.info(TEST_LOG_SECTION_PREFIX + " THEN " + testName + TEST_LOG_SECTION_SUFFIX);
}

public static void displayThen(String testName, String part) {
System.out.println(TEST_OUT_SECTION_PREFIX + testName + ": THEN " + part + TEST_OUT_SECTION_SUFFIX);
LOGGER.info(TEST_LOG_SECTION_PREFIX + testName + ": THEN " + part + TEST_LOG_SECTION_SUFFIX);
}

public static void displayCleanup(String testName) {
System.out.println(TEST_OUT_SECTION_PREFIX + " CLEANUP " + testName + TEST_OUT_SECTION_SUFFIX);
LOGGER.info(TEST_LOG_SECTION_PREFIX + " CLEANUP " + testName + TEST_LOG_SECTION_SUFFIX);
Expand Down Expand Up @@ -662,7 +612,8 @@ private static void assertNoPermission(File f, Set<PosixFilePermission> permissi
assertFalse(permissions.contains(permission), f.getPath() + ": unexpected permission " + permission);
}

public static ParallelTestThread[] multithread(final String TEST_NAME, MultithreadRunner lambda, int numberOfThreads, Integer randomStartDelayRange) {
public static ParallelTestThread[] multithread(
MultithreadRunner lambda, int numberOfThreads, Integer randomStartDelayRange) {
ParallelTestThread[] threads = new ParallelTestThread[numberOfThreads];
System.out.println("Going to create " + numberOfThreads + " threads...");
for (int i = 0; i < numberOfThreads; i++) {
Expand Down

This file was deleted.

5 changes: 5 additions & 0 deletions model/model-common/pom.xml
Expand Up @@ -172,6 +172,11 @@
<artifactId>test-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-test-util</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion tools/test-ng/pom.xml
Expand Up @@ -18,7 +18,7 @@
<artifactId>test-ng</artifactId>
<packaging>jar</packaging>

<name>midPoint Infrastructure - testing support tools</name>
<name>midPoint Tools - testing utils (lvl 1)</name>

<properties>
<maven.test.skip>true</maven.test.skip>
Expand All @@ -29,5 +29,13 @@
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
</dependencies>
</project>
Expand Up @@ -4,15 +4,15 @@
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.test.util;
package com.evolveum.midpoint.tools.testng;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

/**
* Base test class providing basic {@link UnitTestMixin} implementation.
* Can be extended by any unit test class that otherwise doesn't extend anything.
Expand All @@ -21,13 +21,13 @@ public abstract class AbstractUnitTest implements UnitTestMixin {

private static final ThreadLocal<ITestResult> TEST_CONTEXT_THREAD_LOCAL = new ThreadLocal<>();

protected final Trace logger = TraceManager.getTrace(getClass());
protected final Logger logger = LoggerFactory.getLogger(getClass());

@BeforeMethod
public void startTestContext(ITestResult testResult) {
Class<?> testClass = testResult.getMethod().getTestClass().getRealClass();
String testMethodName = testResult.getMethod().getMethodName();
TestUtil.displayTestTitle(testClass.getSimpleName() + "." + testMethodName);
displayTestTitle(testClass.getSimpleName() + "." + testMethodName);

TEST_CONTEXT_THREAD_LOCAL.set(testResult);
}
Expand All @@ -39,6 +39,20 @@ public void finishTestContext(ITestResult testResult) {
displayDefaultTestFooter(testResult);
}

@Override
public Logger logger() {
return logger;
}

@Override
@NotNull
public String contextName() {
ITestResult context = TEST_CONTEXT_THREAD_LOCAL.get();
return context != null
? getClass().getSimpleName() + "." + context.getMethod().getMethodName()
: getClass().getSimpleName();
}

@Override
public String getTestNameShort() {
return TEST_CONTEXT_THREAD_LOCAL.get().getMethod().getMethodName();
Expand Down

0 comments on commit b9ead3a

Please sign in to comment.