Skip to content

Commit

Permalink
fix(deps): update testng to v7.10.1
Browse files Browse the repository at this point in the history
backport fix of a4a1a5d for citrus `v3.4.0`.
bug has originally been reported in citrusframework#1090.

closes citrusframework#1146.
  • Loading branch information
bbortt committed Apr 15, 2024
1 parent e8382c9 commit 1d11f92
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<spring.restdocs.version>2.0.7.RELEASE</spring.restdocs.version>
<sshd.version>2.9.2</sshd.version>
<subethasmtp.version>3.1.7</subethasmtp.version>
<testng.version>7.7.1</testng.version>
<testng.version>7.10.1</testng.version>
<vertx.version>3.9.14</vertx.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<xalan.version>2.7.2</xalan.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,31 +41,43 @@
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}
* and {@link GherkinTestActionRunner}.
*
* @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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -186,44 +196,49 @@ 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) {
}

/**
* Prepares the test context.
*
* <p>
* Provides a hook for test context modifications before the test gets executed.
*
* @param testContext the test context.
Expand All @@ -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
Expand Down
Loading

0 comments on commit 1d11f92

Please sign in to comment.