diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java
index 2fa93c20a9..b4559939ae 100644
--- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java
+++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/ChainElementsTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2022 the original author or authors.
+ * Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ package org.springframework.integration.xml.config;
import java.io.ByteArrayInputStream;
import java.util.Properties;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -31,7 +31,7 @@ import org.springframework.core.io.InputStreamResource;
import org.springframework.integration.xml.transformer.XPathTransformer;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
@@ -43,21 +43,12 @@ import static org.assertj.core.api.Assertions.fail;
public class ChainElementsTests {
@Test
- public void chainXPathTransformer() throws Exception {
- try {
- bootStrap("xpath-transformer");
- fail("Expected a BeanDefinitionParsingException to be thrown.");
- }
- catch (BeanDefinitionParsingException e) {
- final String expectedMessage = "Configuration problem: " +
- "The 'input-channel' attribute isn't allowed for a nested " +
- "(e.g. inside a ) endpoint element: 'int-xml:xpath-transformer'.";
- final String actualMessage = e.getMessage();
- assertThat(actualMessage.startsWith(expectedMessage))
- .as("Error message did not start with '" + expectedMessage +
- "' but instead returned: '" + actualMessage + "'").isTrue();
- }
-
+ public void chainXPathTransformer() {
+ assertThatExceptionOfType(BeanDefinitionParsingException.class)
+ .isThrownBy(() -> bootStrap("xpath-transformer"))
+ .withMessageStartingWith("Configuration problem: " +
+ "The 'input-channel' attribute isn't allowed for a nested " +
+ "(e.g. inside a ) endpoint element: 'int-xml:xpath-transformer'.");
}
@Test
@@ -68,37 +59,21 @@ public class ChainElementsTests {
}
@Test
- public void chainXPathRouterOrder() throws Exception {
- try {
- bootStrap("xpath-router-order");
- fail("Expected a BeanDefinitionParsingException to be thrown.");
- }
- catch (BeanDefinitionParsingException e) {
- final String expectedMessage = "Configuration problem: " +
- "'int-xml:xpath-router' must not define an 'order' attribute " +
- "when used within a chain.";
- final String actualMessage = e.getMessage();
- assertThat(actualMessage.startsWith(expectedMessage))
- .as("Error message did not start with '" + expectedMessage +
- "' but instead returned: '" + actualMessage + "'").isTrue();
- }
-
+ public void chainXPathRouterOrder() {
+ assertThatExceptionOfType(BeanDefinitionParsingException.class)
+ .isThrownBy(() -> bootStrap("xpath-router-order"))
+ .withMessageStartingWith("Configuration problem: " +
+ "'int-xml:xpath-router' must not define an 'order' attribute " +
+ "when used within a chain.");
}
@Test
- public void chainXPathTransformerPoller() throws Exception {
- try {
- bootStrap("xpath-transformer-poller");
- fail("Expected a BeanDefinitionParsingException to be thrown.");
- }
- catch (BeanDefinitionParsingException e) {
- final String expectedMessage = "Configuration problem: " +
- "'int-xml:xpath-transformer' must not define a 'poller' " +
- "sub-element when used within a chain.";
- final String actualMessage = e.getMessage();
- assertThat(actualMessage).as("Error message did not start with '" + expectedMessage +
- "' but instead returned: '" + actualMessage + "'").startsWith(expectedMessage);
- }
+ public void chainXPathTransformerPoller() {
+ assertThatExceptionOfType(BeanDefinitionParsingException.class)
+ .isThrownBy(() -> bootStrap("xpath-transformer-poller"))
+ .withMessageStartingWith("Configuration problem: " +
+ "'int-xml:xpath-transformer' must not define a 'poller' " +
+ "sub-element when used within a chain.");
}
@Test
@@ -114,11 +89,11 @@ public class ChainElementsTests {
"org/springframework/integration/xml/config/chain-elements-config.properties"));
pfb.afterPropertiesSet();
Properties prop = pfb.getObject();
- StringBuffer buffer = new StringBuffer();
- buffer.append(prop.getProperty("xmlheaders"))
- .append(prop.getProperty(configProperty))
- .append(prop.getProperty("xmlfooter"));
- ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes());
+ String buffer =
+ prop.getProperty("xmlheaders") +
+ prop.getProperty(configProperty) +
+ prop.getProperty("xmlfooter");
+ ByteArrayInputStream stream = new ByteArrayInputStream(buffer.getBytes());
GenericApplicationContext ac = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/DefaultConfigurationTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/DefaultConfigurationTests.java
index a736184588..a78b69ebae 100644
--- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/DefaultConfigurationTests.java
+++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/DefaultConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2022 the original author or authors.
+ * Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
package org.springframework.integration.xml.config;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -28,8 +28,7 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ErrorHandler;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
+ *
* @since 1.0.3
*/
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration
+@SpringJUnitConfig
public class DefaultConfigurationTests {
@Autowired
diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java
index 97cf30c666..6c5655bc91 100644
--- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java
+++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2022 the original author or authors.
+ * Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,12 @@ import java.util.List;
import javax.xml.transform.dom.DOMResult;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
@@ -35,6 +34,7 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.MultiValueMap;
import org.springframework.xml.transform.StringResult;
@@ -44,23 +44,19 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Jonas Partner
* @author Mark Fisher
* @author Gary Russell
+ * @author Artem Bilan
*/
+@SpringJUnitConfig
public class MarshallingTransformerParserTests {
+ @Autowired
private ApplicationContext appContext;
+ @Autowired
private PollableChannel output;
-
- @Before
- public void setUp() {
- this.appContext = new ClassPathXmlApplicationContext("MarshallingTransformerParserTests-context.xml", getClass());
- this.output = (PollableChannel) appContext.getBean("output");
- }
-
-
@Test
- public void testParse() throws Exception {
+ public void testParse() {
EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("parseOnly");
assertThat(TestUtils.getPropertyValue(consumer, "handler.order")).isEqualTo(2);
assertThat(TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout")).isEqualTo(123L);
@@ -70,13 +66,13 @@ public class MarshallingTransformerParserTests {
@SuppressWarnings("unchecked")
List list = (List) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
- assertThat(list).containsExactly((SmartLifecycle) consumer);
+ assertThat(list).containsExactly(consumer);
}
@Test
- public void testDefault() throws Exception {
+ public void testDefault() {
MessageChannel input = (MessageChannel) appContext.getBean("marshallingTransformerNoResultFactory");
- GenericMessage