From 7b27696288b5ae0b18e7fcce198882da9c3d453a Mon Sep 17 00:00:00 2001 From: Timon Borter Date: Mon, 15 Apr 2024 08:37:23 +0200 Subject: [PATCH] fix(deps): update testng to v7.10.1 backport fix of a4a1a5daec800cfc070c9df1135db958df31e1ad for citrus `v3.4.0`. bug has originally been reported in #1090. closes #1146. --- .../BeanDefinitionParserTestSupport.java | 34 +++++++----- .../com/consol/citrus/UnitTestSupport.java | 33 +++++++----- pom.xml | 2 +- .../citrus/cucumber/UnitTestSupport.java | 25 +++++---- .../citrus/testng/TestNGCitrusSupport.java | 46 ++++++++++------ .../spring/TestNGCitrusSpringSupport.java | 54 ++++++++++++------- .../citrus/testng/AbstractTestNGUnitTest.java | 4 +- .../consol/citrus/dsl/UnitTestSupport.java | 23 ++++---- 8 files changed, 135 insertions(+), 86 deletions(-) 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 @@ 2.0.7.RELEASE 2.9.2 3.1.7 - 7.7.1 + 7.10.1 3.9.14 1.6.3 2.7.2 diff --git a/runtime/citrus-cucumber/src/test/java/com/consol/citrus/cucumber/UnitTestSupport.java b/runtime/citrus-cucumber/src/test/java/com/consol/citrus/cucumber/UnitTestSupport.java index a8328b205e..f79fe35282 100644 --- a/runtime/citrus-cucumber/src/test/java/com/consol/citrus/cucumber/UnitTestSupport.java +++ b/runtime/citrus-cucumber/src/test/java/com/consol/citrus/cucumber/UnitTestSupport.java @@ -13,17 +13,22 @@ 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.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; +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; @@ -33,23 +38,23 @@ public class UnitTestSupport extends AbstractTestNGUnitTest { @Autowired private JUnitReporter jUnitReporter; - /** Citrus instance */ + /** + * Citrus instance + */ protected Citrus citrus; @BeforeClass(alwaysRun = true) - public void beforeSuite(ITestContext testContext) throws Exception { + public void 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. - */ @AfterClass(alwaysRun = true) public void afterSuite(ITestContext testContext) { - if (citrus != null) { - citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups()); + if (nonNull(citrus)) { + citrus.afterSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } } diff --git a/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/TestNGCitrusSupport.java b/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/TestNGCitrusSupport.java index 1f9ed5424c..a2e4b400a8 100644 --- a/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/TestNGCitrusSupport.java +++ b/runtime/citrus-testng/src/main/java/com/consol/citrus/testng/TestNGCitrusSupport.java @@ -19,10 +19,6 @@ package com.consol.citrus.testng; -import java.lang.reflect.Method; -import java.util.Date; -import java.util.List; - import com.consol.citrus.Citrus; import com.consol.citrus.CitrusContext; import com.consol.citrus.GherkinTestActionRunner; @@ -45,14 +41,20 @@ import org.slf4j.LoggerFactory; import org.testng.IHookCallBack; import org.testng.IHookable; -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 static java.util.Objects.nonNull; + /** * Basic Citrus TestNG support base class 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} @@ -60,16 +62,22 @@ * * @author Christoph Deppisch */ -@Listeners( { TestNGCitrusMethodInterceptor.class } ) +@Listeners({TestNGCitrusMethodInterceptor.class}) public class TestNGCitrusSupport implements IHookable, 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; @Override @@ -108,6 +116,7 @@ public void run(final IHookCallBack callBack, ITestResult testResult) { /** * Run method prepares and executes test case. + * * @param testResult * @param method * @param methodTestLoaders @@ -172,6 +181,7 @@ public final void before() { /** * Subclasses may add before test actions on the provided context. + * * @param context the Citrus context. */ protected void before(CitrusContext context) { @@ -186,36 +196,41 @@ public final void after() { /** * Subclasses may add after test actions on the provided context. + * * @param context the Citrus context. */ protected void after(CitrusContext context) { } @BeforeSuite(alwaysRun = true) - public final void beforeSuite(ITestContext testContext) { + public final void beforeSuite() { citrus = Citrus.newInstance(); CitrusAnnotations.injectCitrusFramework(this, citrus); beforeSuite(citrus.getCitrusContext()); - citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups()); + citrus.beforeSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } /** * Subclasses may add before suite actions on the provided context. + * * @param context the Citrus context. */ protected void beforeSuite(CitrusContext context) { } @AfterSuite(alwaysRun = true) - public final void afterSuite(ITestContext testContext) { - if (citrus != null) { + public final void afterSuite() { + if (nonNull(citrus)) { afterSuite(citrus.getCitrusContext()); - citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups()); + citrus.afterSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } } /** * Subclasses may add after suite actions on the provided context. + * * @param context the Citrus context. */ protected void afterSuite(CitrusContext context) { @@ -223,7 +238,7 @@ protected void afterSuite(CitrusContext context) { /** * Prepares the test context. - * + *

* 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 metho CitrusAnnotations.injectAll(this, citrus, ctx); - TestLoader testLoader ; + TestLoader testLoader; if (method.getAnnotation(CitrusTestSource.class) != null && !methodTestLoaders.isEmpty()) { testLoader = methodTestLoaders.get(invocationCount % methodTestLoaders.size()); @@ -201,6 +209,7 @@ public final void before() { /** * Subclasses may add before test actions on the provided context. + * * @param context the Citrus context. */ protected void before(CitrusContext context) { @@ -215,13 +224,14 @@ public final void after() { /** * Subclasses may add after test actions on the provided context. + * * @param context the Citrus context. */ protected void after(CitrusContext context) { } @BeforeSuite(alwaysRun = true) - public final void beforeSuite(ITestContext testContext) { + public final void beforeSuite() { try { springTestContextPrepareTestInstance(); } catch (Exception e) { @@ -232,26 +242,30 @@ public final void beforeSuite(ITestContext testContext) { citrus = Citrus.newInstance(new CitrusSpringContextProvider(applicationContext)); CitrusAnnotations.injectCitrusFramework(this, citrus); beforeSuite(citrus.getCitrusContext()); - citrus.beforeSuite(testContext.getSuite().getName(), testContext.getIncludedGroups()); + citrus.beforeSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } /** * Subclasses may add before suite actions on the provided context. + * * @param context the Citrus context. */ protected void beforeSuite(CitrusContext context) { } @AfterSuite(alwaysRun = true) - public final void afterSuite(ITestContext testContext) { - if (citrus != null) { + public final void afterSuite() { + if (nonNull(citrus)) { afterSuite(citrus.getCitrusContext()); - citrus.afterSuite(testContext.getSuite().getName(), testContext.getIncludedGroups()); + citrus.afterSuite(Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } } /** * Subclasses may add after suite actions on the provided context. + * * @param context the Citrus context. */ protected void afterSuite(CitrusContext context) { @@ -259,7 +273,7 @@ protected void afterSuite(CitrusContext context) { /** * Prepares the test context. - * + *

* 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/test/java/com/consol/citrus/dsl/UnitTestSupport.java b/vintage/citrus-java-dsl/src/test/java/com/consol/citrus/dsl/UnitTestSupport.java index 7ac9fce105..90f79fa178 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 @@ -14,10 +14,13 @@ 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 +44,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()); + if (nonNull(citrus)) { + citrus.afterSuite( + Reporter.getCurrentTestResult().getTestContext().getSuite().getName(), + Reporter.getCurrentTestResult().getTestContext().getIncludedGroups()); } }