diff --git a/core/citrus-spring/src/test/java/com/consol/citrus/BeanDefinitionParserTestSupport.java b/core/citrus-spring/src/test/java/com/consol/citrus/BeanDefinitionParserTestSupport.java
index dbebef6123..bb8053de1c 100644
--- a/core/citrus-spring/src/test/java/com/consol/citrus/BeanDefinitionParserTestSupport.java
+++ b/core/citrus-spring/src/test/java/com/consol/citrus/BeanDefinitionParserTestSupport.java
@@ -10,18 +10,22 @@
import com.consol.citrus.testng.AbstractBeanDefinitionParserTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import org.testng.ITestContext;
+import org.testng.Reporter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
+import static java.util.Objects.nonNull;
+
/**
* @author Christoph Deppisch
*/
@ContextConfiguration(classes = CitrusSpringConfig.class)
public class BeanDefinitionParserTestSupport extends AbstractBeanDefinitionParserTest {
- /** Factory bean for test context */
+ /**
+ * Factory bean for test context
+ */
@Autowired
protected TestContextFactoryBean testContextFactory;
@@ -31,26 +35,28 @@ public class BeanDefinitionParserTestSupport extends AbstractBeanDefinitionParse
@Autowired
private JUnitReporter jUnitReporter;
- /** Citrus instance */
+ /**
+ * Citrus instance
+ */
protected Citrus citrus;
- @BeforeSuite(alwaysRun = true)
@Override
- public void beforeSuite(ITestContext testContext) throws Exception {
- super.beforeSuite(testContext);
+ @BeforeSuite(alwaysRun = true)
+ public void beforeSuite() throws Exception {
+ super.beforeSuite();
citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext));
- citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ citrus.beforeSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
- /**
- * Runs tasks after test suite.
- * @param testContext the test context.
- */
@AfterSuite(alwaysRun = true)
- public void afterSuite(ITestContext testContext) {
- if (citrus != null) {
- citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ public void afterSuite() {
+ if (nonNull(citrus)) {
+ citrus.afterSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
}
diff --git a/core/citrus-spring/src/test/java/com/consol/citrus/UnitTestSupport.java b/core/citrus-spring/src/test/java/com/consol/citrus/UnitTestSupport.java
index 2dd413a38d..727d6d3fdd 100644
--- a/core/citrus-spring/src/test/java/com/consol/citrus/UnitTestSupport.java
+++ b/core/citrus-spring/src/test/java/com/consol/citrus/UnitTestSupport.java
@@ -10,18 +10,22 @@
import com.consol.citrus.testng.AbstractTestNGUnitTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import org.testng.ITestContext;
+import org.testng.Reporter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
+import static java.util.Objects.nonNull;
+
/**
* @author Christoph Deppisch
*/
@ContextConfiguration(classes = CitrusSpringConfig.class)
public class UnitTestSupport extends AbstractTestNGUnitTest {
- /** Factory bean for test context */
+ /**
+ * Factory bean for test context
+ */
@Autowired
protected TestContextFactoryBean testContextFactory;
@@ -31,26 +35,27 @@ public class UnitTestSupport extends AbstractTestNGUnitTest {
@Autowired
private JUnitReporter jUnitReporter;
- /** Citrus instance */
+ /**
+ * Citrus instance
+ */
protected Citrus citrus;
- @BeforeSuite(alwaysRun = true)
@Override
- public void beforeSuite(ITestContext testContext) throws Exception {
- super.beforeSuite(testContext);
+ @BeforeSuite(alwaysRun = true)
+ public void beforeSuite() throws Exception {
+ super.beforeSuite();
citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext));
- citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ citrus.beforeSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
- /**
- * Runs tasks after test suite.
- * @param testContext the test context.
- */
@AfterSuite(alwaysRun = true)
- public void afterSuite(ITestContext testContext) {
- if (citrus != null) {
- citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ public void afterSuite() {
+ if (nonNull(citrus)) {
+ citrus.afterSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
}
diff --git a/pom.xml b/pom.xml
index 8f44f7fcf2..4cd63269c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -208,7 +208,7 @@
* Provides a hook for test context modifications before the test gets executed.
*
* @param testContext the test context.
@@ -237,6 +252,7 @@ protected TestContext prepareTestContext(final TestContext testContext) {
* Creates new test loader which has TestNG test annotations set for test execution. Only
* suitable for tests that get created at runtime through factory method. Subclasses
* may overwrite this in order to provide custom test loader with custom test annotations set.
+ *
* @param testName
* @param packageName
* @return
diff --git a/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/spring/TestNGCitrusSpringSupport.java b/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/spring/TestNGCitrusSpringSupport.java
index 6a20cae13f..9a489135c4 100644
--- a/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/spring/TestNGCitrusSpringSupport.java
+++ b/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/spring/TestNGCitrusSpringSupport.java
@@ -19,11 +19,6 @@
package com.consol.citrus.testng.spring;
-import java.lang.reflect.Method;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-
import com.consol.citrus.Citrus;
import com.consol.citrus.CitrusContext;
import com.consol.citrus.CitrusSpringContext;
@@ -53,14 +48,21 @@
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.util.Assert;
import org.testng.IHookCallBack;
-import org.testng.ITestContext;
import org.testng.ITestResult;
+import org.testng.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import static java.util.Objects.nonNull;
+
/**
* Basic Citrus TestNG support base class with Spring support automatically handles test case runner creation. Also provides method parameter resolution
* and resource injection. Users can just extend this class and make use of the action runner methods provided in {@link com.consol.citrus.TestActionRunner}
@@ -70,17 +72,22 @@
* @author Christoph Deppisch
*/
@ContextConfiguration(classes = CitrusSpringConfig.class)
-@Listeners( { TestNGCitrusSpringMethodInterceptor.class } )
-public class TestNGCitrusSpringSupport extends AbstractTestNGSpringContextTests
- implements GherkinTestActionRunner {
+@Listeners({TestNGCitrusSpringMethodInterceptor.class})
+public class TestNGCitrusSpringSupport extends AbstractTestNGSpringContextTests implements GherkinTestActionRunner {
- /** Logger */
+ /**
+ * Logger
+ */
protected final Logger log = LoggerFactory.getLogger(getClass());
- /** Citrus instance */
+ /**
+ * Citrus instance
+ */
protected Citrus citrus;
- /** Test builder delegate */
+ /**
+ * Test builder delegate
+ */
private TestCaseRunner delegate;
private TestCase testCase;
@@ -121,6 +128,7 @@ public void run(final IHookCallBack callBack, ITestResult testResult) {
/**
* Run method prepares and executes test case.
+ *
* @param testResult
* @param method
* @param methodTestLoaders
@@ -159,7 +167,7 @@ protected void run(ITestResult testResult, Method method, List
* Provides a hook for test context modifications before the test gets executed.
*
* @param testContext the test context.
@@ -273,6 +287,7 @@ protected TestContext prepareTestContext(final TestContext testContext) {
* Creates new test loader which has TestNG test annotations set for test execution. Only
* suitable for tests that get created at runtime through factory method. Subclasses
* may overwrite this in order to provide custom test loader with custom test annotations set.
+ *
* @param testName
* @param packageName
* @return
@@ -293,6 +308,7 @@ protected TestLoader createTestLoader(String testName, String packageName, Strin
/**
* Constructs the test case to execute.
+ *
* @return
*/
protected TestCase getTestCase() {
diff --git a/utils/citrus-test-support/src/main/java/com/consol/citrus/testng/AbstractTestNGUnitTest.java b/utils/citrus-test-support/src/main/java/com/consol/citrus/testng/AbstractTestNGUnitTest.java
index 091c68653d..60a5609825 100644
--- a/utils/citrus-test-support/src/main/java/com/consol/citrus/testng/AbstractTestNGUnitTest.java
+++ b/utils/citrus-test-support/src/main/java/com/consol/citrus/testng/AbstractTestNGUnitTest.java
@@ -23,7 +23,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.util.Assert;
-import org.testng.ITestContext;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
@@ -47,11 +46,10 @@ public abstract class AbstractTestNGUnitTest extends AbstractTestNGSpringContext
/**
* Runs tasks before test suite.
- * @param testContext the test context.
* @throws Exception on error.
*/
@BeforeSuite(alwaysRun = true)
- public void beforeSuite(ITestContext testContext) throws Exception {
+ public void beforeSuite() throws Exception {
springTestContextPrepareTestInstance();
Assert.notNull(applicationContext, "Missing proper application context in before suite initialization");
}
diff --git a/vintage/citrus-java-dsl/src/main/java/com/consol/citrus/testng/AbstractTestNGCitrusTest.java b/vintage/citrus-java-dsl/src/main/java/com/consol/citrus/testng/AbstractTestNGCitrusTest.java
index ca1bdf74b6..9ba22cce8f 100644
--- a/vintage/citrus-java-dsl/src/main/java/com/consol/citrus/testng/AbstractTestNGCitrusTest.java
+++ b/vintage/citrus-java-dsl/src/main/java/com/consol/citrus/testng/AbstractTestNGCitrusTest.java
@@ -16,11 +16,6 @@
package com.consol.citrus.testng;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Optional;
-
import com.consol.citrus.Citrus;
import com.consol.citrus.CitrusSpringContext;
import com.consol.citrus.CitrusSpringContextProvider;
@@ -44,12 +39,20 @@
import org.testng.IHookCallBack;
import org.testng.ITestContext;
import org.testng.ITestResult;
+import org.testng.Reporter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Optional;
+
+import static java.util.Objects.nonNull;
+
/**
* Abstract base test implementation for testng test cases. Providing test listener support and
* loading basic application context files for Citrus.
@@ -58,14 +61,18 @@
* @deprecated in favor of using {@link com.consol.citrus.testng.spring.TestNGCitrusSpringSupport}
*/
@ContextConfiguration(classes = CitrusSpringConfig.class)
-@Listeners( { TestNGCitrusMethodInterceptor.class } )
+@Listeners({TestNGCitrusMethodInterceptor.class})
@Deprecated
public abstract class AbstractTestNGCitrusTest extends AbstractTestNGSpringContextTests {
- /** Logger */
+ /**
+ * Logger
+ */
protected final Logger log = LoggerFactory.getLogger(getClass());
- /** Citrus instance */
+ /**
+ * Citrus instance
+ */
protected Citrus citrus;
private TestCase testCase;
@@ -103,6 +110,7 @@ public void run(IHookCallBack callBack, ITestResult testResult) {
/**
* Run method prepares and executes test case.
+ *
* @param testResult
* @param method
* @param testLoader
@@ -202,34 +210,29 @@ protected Object resolveAnnotatedResource(ITestResult testResult, Class> param
}
}
- /**
- * Runs tasks before test suite.
- * @param testContext the test context.
- * @throws Exception on error.
- */
@BeforeSuite(alwaysRun = true)
- public void beforeSuite(ITestContext testContext) throws Exception {
+ public void beforeSuite() throws Exception {
springTestContextPrepareTestInstance();
Assert.notNull(applicationContext, "Missing proper application context in before suite initialization");
citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext));
- citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ citrus.beforeSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
- /**
- * Runs tasks after test suite.
- * @param testContext the test context.
- */
@AfterSuite(alwaysRun = true)
- public void afterSuite(ITestContext testContext) {
- if (citrus != null) {
- citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ public void afterSuite() {
+ if (nonNull(citrus)) {
+ citrus.afterSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
}
/**
* Prepares the test context.
- *
+ *
* Provides a hook for test context modifications before the test gets executed.
*
* @param testContext the test context.
@@ -243,6 +246,7 @@ protected TestContext prepareTestContext(final TestContext testContext) {
* Creates new test loader which has TestNG test annotations set for test execution. Only
* suitable for tests that get created at runtime through factory method. Subclasses
* may overwrite this in order to provide custom test loader with custom test annotations set.
+ *
* @param testName
* @param packageName
* @return
@@ -257,14 +261,15 @@ protected TestLoader createTestLoader(String testName, String packageName, Strin
testLoader.setPackageName(packageName);
CitrusAnnotations.injectCitrusContext(testLoader, Optional.ofNullable(citrus)
- .map(Citrus::getCitrusContext)
- .orElseGet(() -> CitrusSpringContext.create(applicationContext)));
+ .map(Citrus::getCitrusContext)
+ .orElseGet(() -> CitrusSpringContext.create(applicationContext)));
testLoader.configureTestCase(t -> testCase = t);
return testLoader;
}
/**
* Constructs the test case to execute.
+ *
* @return
*/
protected TestCase getTestCase() {
diff --git a/vintage/citrus-java-dsl/src/test/java/com/consol/citrus/dsl/UnitTestSupport.java b/vintage/citrus-java-dsl/src/test/java/com/consol/citrus/dsl/UnitTestSupport.java
index 7ac9fce105..6591172bff 100644
--- a/vintage/citrus-java-dsl/src/test/java/com/consol/citrus/dsl/UnitTestSupport.java
+++ b/vintage/citrus-java-dsl/src/test/java/com/consol/citrus/dsl/UnitTestSupport.java
@@ -13,11 +13,13 @@
import com.consol.citrus.testng.AbstractTestNGUnitTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import org.testng.ITestContext;
+import org.testng.Reporter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
+import static java.util.Objects.nonNull;
+
/**
* @author Christoph Deppisch
*/
@@ -41,23 +43,23 @@ public class UnitTestSupport extends AbstractTestNGUnitTest {
/** Citrus instance */
protected Citrus citrus;
- @BeforeSuite(alwaysRun = true)
@Override
- public void beforeSuite(ITestContext testContext) throws Exception {
- super.beforeSuite(testContext);
+ @BeforeSuite(alwaysRun = true)
+ public void beforeSuite() throws Exception {
+ super.beforeSuite();
citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext));
- citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ citrus.beforeSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
- /**
- * Runs tasks after test suite.
- * @param testContext the test context.
- */
@AfterSuite(alwaysRun = true)
- public void afterSuite(ITestContext testContext) {
- if (citrus != null) {
- citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups());
+ public void afterSuite() {
+ if (nonNull(citrus)) {
+ citrus.afterSuite(
+ Reporter.getCurrentTestResult().getTestContext().getSuite().getName(),
+ Reporter.getCurrentTestResult().getTestContext().getIncludedGroups());
}
}