This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch CAMEL-23214-port-http-servers in repository https://gitbox.apache.org/repos/asf/camel.git
commit f6bcb7ac432199a7c5dfefc860ec6806079466e9 Author: Guillaume Nodet <[email protected]> AuthorDate: Fri Mar 20 06:34:27 2026 +0100 CAMEL-23214: Fix port migration in http-servers tests Replace PORT (Port object) with PORT.getPort() in fromF(), toF(), and string concatenation calls that use %d format specifiers or need an int. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../test/java/org/apache/camel/coap/CoAPComponentTest.java | 5 +++-- .../java/org/apache/camel/coap/CoAPMethodRestrictTest.java | 14 ++++++++------ .../test/java/org/apache/camel/coap/CoAPMethodTest.java | 14 ++++++++------ .../test/java/org/apache/camel/coap/CoAPObserveTest.java | 6 +++--- .../src/test/java/org/apache/camel/coap/CoAPPingTest.java | 5 +++-- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java index 275395d13fe7..454b11bd3826 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java @@ -74,12 +74,13 @@ public class CoAPComponentTest extends CoAPTestSupport { return new RouteBuilder() { @Override public void configure() { - fromF("coap://localhost:%d/TestResource", PORT).convertBodyTo(String.class).transform(body().prepend("Hello ")); + fromF("coap://localhost:%d/TestResource", PORT.getPort()).convertBodyTo(String.class) + .transform(body().prepend("Hello ")); fromF("coap+tcp://localhost:%d/TestResource", TCP_PORT.getPort()).convertBodyTo(String.class) .transform(body().prepend("Hello ")); - from("direct:start").toF("coap://localhost:%d/TestResource", PORT).to("mock:result"); + from("direct:start").toF("coap://localhost:%d/TestResource", PORT.getPort()).to("mock:result"); from("direct:starttcp").toF("coap+tcp://localhost:%d/TestResource", TCP_PORT.getPort()).to("mock:result"); } diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java index 7c4ffb2cd49d..d2ce01dd7f6a 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java @@ -53,7 +53,8 @@ public class CoAPMethodRestrictTest extends CoAPTestSupport { private void assertCoAPMethodRestrictResponse(String path, String methodRestrict, String expectedResponse) { for (String method : CoAPConstants.METHOD_RESTRICT_ALL.split(",")) { - String result = template.requestBodyAndHeader("coap://localhost:" + PORT + path, null, CoAPConstants.COAP_METHOD, + String result = template.requestBodyAndHeader("coap://localhost:" + PORT.getPort() + path, null, + CoAPConstants.COAP_METHOD, method, String.class); if (methodRestrict.contains(method)) { assertEquals(expectedResponse, result); @@ -68,16 +69,17 @@ public class CoAPMethodRestrictTest extends CoAPTestSupport { return new RouteBuilder() { @Override public void configure() { - fromF("coap://localhost:%d/test", PORT).setBody(constant("GET: /test")); + fromF("coap://localhost:%d/test", PORT.getPort()).setBody(constant("GET: /test")); - fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT).setBody(constant("GET: /test/a")); + fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT.getPort()).setBody(constant("GET: /test/a")); - fromF("coap://localhost:%d/test/a/b?coapMethodRestrict=DELETE", PORT).setBody(constant("DELETE: /test/a/b")); + fromF("coap://localhost:%d/test/a/b?coapMethodRestrict=DELETE", PORT.getPort()) + .setBody(constant("DELETE: /test/a/b")); - fromF("coap://localhost:%d/test/a/b/c?coapMethodRestrict=DELETE,GET", PORT) + fromF("coap://localhost:%d/test/a/b/c?coapMethodRestrict=DELETE,GET", PORT.getPort()) .setBody(constant("DELETE & GET: /test/a/b/c")); - fromF("coap://localhost:%d/test/b?coapMethodRestrict=GET", PORT).setBody(constant("GET: /test/b")); + fromF("coap://localhost:%d/test/b?coapMethodRestrict=GET", PORT.getPort()).setBody(constant("GET: /test/b")); } }; } diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java index 7a61064f4fd3..3673f4ebbed1 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java @@ -27,20 +27,21 @@ public class CoAPMethodTest extends CoAPTestSupport { @Test void testCoAPMethodDefaultGet() { // No body means GET - String result = template.requestBody("coap://localhost:" + PORT + "/test/a", null, String.class); + String result = template.requestBody("coap://localhost:" + PORT.getPort() + "/test/a", null, String.class); assertEquals("GET: /test/a", result); } @Test void testCoAPMethodDefaultPost() { // Providing a body means POST - String result = template.requestBody("coap://localhost:" + PORT + "/test/b", "Camel", String.class); + String result = template.requestBody("coap://localhost:" + PORT.getPort() + "/test/b", "Camel", String.class); assertEquals("Hello Camel", result); } @Test void testCoAPMethodHeader() { - String result = template.requestBodyAndHeader("coap://localhost:" + PORT + "/test/c", null, CoAPConstants.COAP_METHOD, + String result = template.requestBodyAndHeader("coap://localhost:" + PORT.getPort() + "/test/c", null, + CoAPConstants.COAP_METHOD, "DELETE", String.class); assertEquals("DELETE: /test/c", result); } @@ -50,11 +51,12 @@ public class CoAPMethodTest extends CoAPTestSupport { return new RouteBuilder() { @Override public void configure() { - fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT).setBody(constant("GET: /test/a")); + fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT.getPort()).setBody(constant("GET: /test/a")); - fromF("coap://localhost:%d/test/b?coapMethodRestrict=POST", PORT).setBody(simple("Hello ${body}")); + fromF("coap://localhost:%d/test/b?coapMethodRestrict=POST", PORT.getPort()).setBody(simple("Hello ${body}")); - fromF("coap://localhost:%d/test/c?coapMethodRestrict=DELETE", PORT).setBody(constant("DELETE: /test/c")); + fromF("coap://localhost:%d/test/c?coapMethodRestrict=DELETE", PORT.getPort()) + .setBody(constant("DELETE: /test/c")); } }; } diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPObserveTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPObserveTest.java index fb6c09e51ef6..315aa77fa1fa 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPObserveTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPObserveTest.java @@ -92,16 +92,16 @@ public class CoAPObserveTest extends CoAPTestSupport { public void configure() { AtomicInteger i = new AtomicInteger(0); - fromF("coap://localhost:%d/TestResource?observable=true", PORT) + fromF("coap://localhost:%d/TestResource?observable=true", PORT.getPort()) .log("Received1: ${body}") .process(exchange -> exchange.getMessage().setBody("Hello " + i.get())); from("direct:notify") .process(exchange -> i.incrementAndGet()) .log("Sending ${body}") - .toF("coap://localhost:%d/TestResource?notify=true", PORT); + .toF("coap://localhost:%d/TestResource?notify=true", PORT.getPort()); - fromF("coap://localhost:%d/TestResource?observe=true", PORT) + fromF("coap://localhost:%d/TestResource?observe=true", PORT.getPort()) .log("Received2: ${body}") .to("mock:sourceResults"); } diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java index e59013abdda1..bdc3f5043510 100644 --- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java +++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java @@ -41,10 +41,11 @@ public class CoAPPingTest extends CoAPTestSupport { return new RouteBuilder() { @Override public void configure() { - fromF("coap://localhost:%d/TestResource", PORT).to("log:exch").transform(body().convertTo(Boolean.class)) + fromF("coap://localhost:%d/TestResource", PORT.getPort()).to("log:exch") + .transform(body().convertTo(Boolean.class)) .to("log:exch"); - from("direct:start").toF("coap://localhost:%d/TestResource", PORT).to("mock:result"); + from("direct:start").toF("coap://localhost:%d/TestResource", PORT.getPort()).to("mock:result"); } }; }
