This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0434e98eb2402e10bb153534e0eb18e2762670ba Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Thu Jun 11 17:16:16 2020 +0200 [CAMEL-11807] Upgrade camel-http-common to junit5 --- components/camel-http-common/pom.xml | 12 ++--- .../camel/http/common/DefaultHttpBindingTest.java | 7 ++- .../http/common/HttpHeaderFilterStrategyTest.java | 11 +++-- .../common/HttpOperationFailedExceptionTest.java | 10 ++-- .../common/HttpRestHeaderFilterStrategyTest.java | 15 +++--- .../http/common/HttpSendDynamicAwareTest.java | 20 ++++---- .../http/common/cookie/CookieHandlerTest.java | 56 ++++++++-------------- 7 files changed, 58 insertions(+), 73 deletions(-) diff --git a/components/camel-http-common/pom.xml b/components/camel-http-common/pom.xml index 435868f..e8e76e0 100644 --- a/components/camel-http-common/pom.xml +++ b/components/camel-http-common/pom.xml @@ -69,13 +69,13 @@ <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> @@ -83,11 +83,5 @@ <artifactId>log4j-slf4j-impl</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <version>${assertj-version}</version> - <scope>test</scope> - </dependency> </dependencies> </project> diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java index 56290cf..3cc7f02 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/DefaultHttpBindingTest.java @@ -20,8 +20,11 @@ import java.util.Date; import java.util.Locale; import org.apache.camel.Exchange; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class DefaultHttpBindingTest extends CamelTestSupport { diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java index 1f3c808..4acc8d1 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpHeaderFilterStrategyTest.java @@ -19,9 +19,12 @@ package org.apache.camel.http.common; import org.apache.camel.Exchange; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.DefaultExchange; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Before; -import org.junit.Test; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpHeaderFilterStrategyTest extends CamelTestSupport { @@ -29,7 +32,7 @@ public class HttpHeaderFilterStrategyTest extends CamelTestSupport { private Exchange exchange; @Override - @Before + @BeforeEach public void setUp() { filter = new HttpHeaderFilterStrategy(); exchange = new DefaultExchange(new DefaultCamelContext()); diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpOperationFailedExceptionTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpOperationFailedExceptionTest.java index bfa00a4..f8da284 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpOperationFailedExceptionTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpOperationFailedExceptionTest.java @@ -16,11 +16,9 @@ */ package org.apache.camel.http.common; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; public class HttpOperationFailedExceptionTest { @@ -28,7 +26,7 @@ public class HttpOperationFailedExceptionTest { public void testUriIsSanitized() { HttpOperationFailedException httpOperationFailedException = new HttpOperationFailedException("http://user:password@host", 500, "", "", null, ""); - assertThat(httpOperationFailedException.getMessage(), not(containsString("password"))); - assertThat(httpOperationFailedException.getUri(), not(containsString("password"))); + assertFalse(httpOperationFailedException.getMessage().contains("password")); + assertFalse(httpOperationFailedException.getUri().contains("password")); } } diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpRestHeaderFilterStrategyTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpRestHeaderFilterStrategyTest.java index ce2d037..dac8706 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpRestHeaderFilterStrategyTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpRestHeaderFilterStrategyTest.java @@ -17,9 +17,10 @@ package org.apache.camel.http.common; import org.apache.camel.Exchange; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpRestHeaderFilterStrategyTest { @@ -30,10 +31,10 @@ public class HttpRestHeaderFilterStrategyTest { final HttpRestHeaderFilterStrategy strategy = new HttpRestHeaderFilterStrategy("{uriToken1}{uriToken2}", "q1=%7BqueryToken1%7D%26q2=%7BqueryToken2%7D%26"); - assertThat(strategy.applyFilterToCamelHeaders("uriToken1", "value", NOT_USED)).isTrue(); - assertThat(strategy.applyFilterToCamelHeaders("uriToken2", "value", NOT_USED)).isTrue(); - assertThat(strategy.applyFilterToCamelHeaders("queryToken1", "value", NOT_USED)).isTrue(); - assertThat(strategy.applyFilterToCamelHeaders("queryToken2", "value", NOT_USED)).isTrue(); - assertThat(strategy.applyFilterToCamelHeaders("unknown", "value", NOT_USED)).isFalse(); + assertTrue(strategy.applyFilterToCamelHeaders("uriToken1", "value", NOT_USED)); + assertTrue(strategy.applyFilterToCamelHeaders("uriToken2", "value", NOT_USED)); + assertTrue(strategy.applyFilterToCamelHeaders("queryToken1", "value", NOT_USED)); + assertTrue(strategy.applyFilterToCamelHeaders("queryToken2", "value", NOT_USED)); + assertFalse(strategy.applyFilterToCamelHeaders("unknown", "value", NOT_USED)); } } diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java index e203521..1e9bf9b 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/HttpSendDynamicAwareTest.java @@ -18,16 +18,16 @@ package org.apache.camel.http.common; import org.apache.camel.http.base.HttpSendDynamicAware; import org.apache.camel.spi.SendDynamicAware.DynamicAwareEntry; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HttpSendDynamicAwareTest { private HttpSendDynamicAware httpSendDynamicAware; - @Before + @BeforeEach public void setUp() throws Exception { this.httpSendDynamicAware = new HttpSendDynamicAware(); } @@ -37,7 +37,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("http"); DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should not add port if http and not specified", "localhost", result[0]); + assertEquals("localhost", result[0], "Parse should not add port if http and not specified"); } @Test @@ -45,7 +45,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("https"); DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should not add port if https and not specified", "localhost", result[0]); + assertEquals("localhost", result[0], "Parse should not add port if https and not specified"); } @Test @@ -53,7 +53,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("http"); DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost:80/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should not port if http and port 80 specified", "localhost", result[0]); + assertEquals("localhost", result[0], "Parse should not port if http and port 80 specified"); } @Test @@ -61,7 +61,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("https"); DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost:443/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should not port if https and port 443 specified", "localhost", result[0]); + assertEquals("localhost", result[0], "Parse should not port if https and port 443 specified"); } @Test @@ -69,7 +69,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("http"); DynamicAwareEntry entry = new DynamicAwareEntry("http://localhost:8080/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should add port if http and port other than 80 specified", "localhost:8080", result[0]); + assertEquals("localhost:8080", result[0], "Parse should add port if http and port other than 80 specified"); } @Test @@ -77,7 +77,7 @@ public class HttpSendDynamicAwareTest { this.httpSendDynamicAware.setScheme("https"); DynamicAwareEntry entry = new DynamicAwareEntry("https://localhost:8443/test", null, null, null); String[] result = httpSendDynamicAware.parseUri(entry); - assertEquals("Parse should add port if https and port other than 443 specified", "localhost:8443", result[0]); + assertEquals("localhost:8443", result[0], "Parse should add port if https and port other than 443 specified"); } } diff --git a/components/camel-http-common/src/test/java/org/apache/camel/http/common/cookie/CookieHandlerTest.java b/components/camel-http-common/src/test/java/org/apache/camel/http/common/cookie/CookieHandlerTest.java index dcef9d6..2d455cc 100644 --- a/components/camel-http-common/src/test/java/org/apache/camel/http/common/cookie/CookieHandlerTest.java +++ b/components/camel-http-common/src/test/java/org/apache/camel/http/common/cookie/CookieHandlerTest.java @@ -20,38 +20,28 @@ import java.io.IOException; import java.net.CookiePolicy; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.apache.camel.Exchange; import org.apache.camel.http.base.cookie.CookieHandler; import org.apache.camel.http.base.cookie.ExchangeCookieHandler; import org.apache.camel.http.base.cookie.InstanceCookieHandler; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(Parameterized.class) public class CookieHandlerTest extends CamelTestSupport { - private CookieHandler cookieHandler; - private CookiePolicy cookiePolicy; - private int expectedNumberOfCookieValues; - private String uriStr; private Exchange exchange; - public CookieHandlerTest(CookieHandler cookieHandler, CookiePolicy cookiePolicy, String uri, int expectedNumberOfCookieValues, String description) { - this.cookieHandler = cookieHandler; - this.cookiePolicy = cookiePolicy; - this.uriStr = uri; - this.expectedNumberOfCookieValues = expectedNumberOfCookieValues; - } - /* * This test tries to set a cookie for domain .example.com from host * www.example.com or www.sub.example.com According to RFC 2965 section @@ -60,30 +50,26 @@ public class CookieHandlerTest extends CamelTestSupport { * set, the resulting Cookie header has two lines, one containing the * version and one the (single) cookie. */ - @Parameters(name = "{index}: {4} policy for {2} returns {3} Cookie header lines") - public static Iterable<Object[]> data() { - return Arrays - .asList(new Object[][] {{new InstanceCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.example.com/acme/foo", 2, - "InstanceCookieHandler with ACCEPT_ORIGINAL_SERVER"}, - {new InstanceCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.sub.example.com/acme/foo", 0, - "InstanceCookieHandler with ACCEPT_ORIGINAL_SERVER"}, - {new InstanceCookieHandler(), CookiePolicy.ACCEPT_ALL, "http://www.sub.example.com/acme/foo", 2, "InstanceCookieHandler with ACCEPT_ALL"}, - {new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.example.com/acme/foo", 2, - "ExchangeCookieHandler with ACCEPT_ORIGINAL_SERVER"}, - {new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.sub.example.com/acme/foo", 0, - "ExchangeCookieHandler with ACCEPT_ORIGINAL_SERVER"}, - {new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ALL, "http://www.sub.example.com/acme/foo", 2, "ExchangeCookieHandler with ACCEPT_ALL"}}); + public static Stream<Arguments> data() { + return Stream.of( + Arguments.of(new InstanceCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.example.com/acme/foo", 2, "InstanceCookieHandler with ACCEPT_ORIGINAL_SERVER"), + Arguments.of(new InstanceCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.sub.example.com/acme/foo", 0, "InstanceCookieHandler with ACCEPT_ORIGINAL_SERVER"), + Arguments.of(new InstanceCookieHandler(), CookiePolicy.ACCEPT_ALL, "http://www.sub.example.com/acme/foo", 2, "InstanceCookieHandler with ACCEPT_ALL"), + Arguments.of(new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.example.com/acme/foo", 2, "ExchangeCookieHandler with ACCEPT_ORIGINAL_SERVER"), + Arguments.of(new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ORIGINAL_SERVER, "http://www.sub.example.com/acme/foo", 0, "ExchangeCookieHandler with ACCEPT_ORIGINAL_SERVER"), + Arguments.of(new ExchangeCookieHandler(), CookiePolicy.ACCEPT_ALL, "http://www.sub.example.com/acme/foo", 2, "ExchangeCookieHandler with ACCEPT_ALL")); } @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); exchange = createExchangeWithBody(null); } - @Test - public void setReceiveAndTestCookie() throws IOException, URISyntaxException { + @ParameterizedTest + @MethodSource("data") + public void setReceiveAndTestCookie(CookieHandler cookieHandler, CookiePolicy cookiePolicy, String uriStr, int expectedNumberOfCookieValues, String description) throws IOException, URISyntaxException { URI uri = new URI(uriStr); cookieHandler.setCookiePolicy(cookiePolicy); Map<String, List<String>> headerMap = new HashMap<>();