Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.AvailablePortFinder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

class VertxHttpBridgeEndpointTest extends VertxHttpTestSupport {
private static final int PORT = AvailablePortFinder.getNextAvailable();
@RegisterExtension
static AvailablePortFinder.Port PORT = AvailablePortFinder.find();

@Test
void bridgeEndpointWithQueryStringDoesNotDuplicateHeaders() throws Exception {
Expand Down Expand Up @@ -89,15 +91,15 @@ protected RoutesBuilder createRouteBuilder() throws Exception {
@Override
public void configure() throws Exception {
from(getTestServerUri() + "/upstream")
.toF("vertx-http:http://localhost:%d/downstream?bridgeEndpoint=true", PORT);
.toF("vertx-http:http://localhost:%d/downstream?bridgeEndpoint=true", PORT.getPort());

from(getTestServerUri() + "/upstream/prefix?matchOnUriPrefix=true")
.toF("vertx-http:http://localhost:%d/downstream?bridgeEndpoint=true", PORT);
.toF("vertx-http:http://localhost:%d/downstream?bridgeEndpoint=true", PORT.getPort());

fromF("undertow:http://localhost:%d/downstream", PORT)
fromF("undertow:http://localhost:%d/downstream", PORT.getPort())
.to("mock:result");

fromF("undertow:http://localhost:%d/downstream/test", PORT)
fromF("undertow:http://localhost:%d/downstream/test", PORT.getPort())
.to("mock:result");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
restConfiguration().port(port);
restConfiguration().port(port.getPort());

rest()
.post("/greeting")
Expand All @@ -57,7 +57,7 @@ public void configure() {

from("direct:greet")
.removeHeaders("CamelHttp*")
.toF("vertx-http:http://localhost:%d/hello?httpMethod=POST", port)
.toF("vertx-http:http://localhost:%d/hello?httpMethod=POST", port.getPort())
.to("mock:result");

from("direct:hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.AvailablePortFinder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class VertxHttpProxyServerTest extends VertxHttpTestSupport {

private final int port2 = AvailablePortFinder.getNextAvailable();
@RegisterExtension
AvailablePortFinder.Port port2 = AvailablePortFinder.find();

@Test
public void testProxyConfiguration() {
String result = template.requestBody(getProducerUri() + "?proxyHost=localhost&proxyPort="
+ port2 + "&proxyUsername=foo"
+ port2.getPort() + "&proxyUsername=foo"
+ "&proxyPassword=bar&proxyType=HTTP",
null, String.class);
assertEquals("Hello Proxied World", result);
Expand All @@ -41,7 +43,7 @@ public void testProxyConfiguration() {
public void testProxyComponent() {
VertxHttpComponent comp = context.getComponent("vertx-http", VertxHttpComponent.class);
comp.setProxyHost("localhost");
comp.setProxyPort(port2);
comp.setProxyPort(port2.getPort());
comp.setProxyUsername("foo");
comp.setProxyPassword("bar");
comp.setProxyType(ProxyType.HTTP);
Expand All @@ -64,7 +66,7 @@ public void configure() {
from(getTestServerUri())
.setBody(constant("Hello Proxied World"));

fromF("undertow:http://localhost:%d", port2)
fromF("undertow:http://localhost:%d", port2.getPort())
.to(getTestServerUri());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@
import io.vertx.core.impl.btc.BlockedThreadEvent;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.extension.RegisterExtension;

public class VertxHttpTestSupport extends CamelTestSupport {

protected final int port = AvailablePortFinder.getNextAvailable();
@RegisterExtension
AvailablePortFinder.Port port = AvailablePortFinder.find();

protected String getTestServerUrl() {
return String.format("http://localhost:%d", port);
return String.format("http://localhost:%d", port.getPort());
}

protected String getTestServerUri() {
return String.format("undertow:%s", getTestServerUrl());
}

protected String getProducerUri() {
return String.format("vertx-http:http://localhost:%d", port);
return String.format("vertx-http:http://localhost:%d", port.getPort());
}

protected int getPort() {
return port;
return port.getPort();
}

protected Vertx createVertxWithThreadBlockedHandler(Handler<BlockedThreadEvent> handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void testGlobalServerSSLContextParameters() throws Exception {

public void configure() {
from("direct:start")
.toF("vertx-websocket:localhost:%d/echo?", port);
.toF("vertx-websocket:localhost:%d/echo?", port.getPort());

fromF("vertx-websocket:localhost:%d/echo?", port)
fromF("vertx-websocket:localhost:%d/echo?", port.getPort())
.setBody(simple("Hello ${body}"))
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void configure() {
.endChoice();

fromF("vertx-websocket:localhost:%d/test?fireWebSocketConnectionEvents=true&serverOptions=#serverOptions&bridgeErrorHandler=true",
port)
port.getPort())
.choice()
.when(simple("${header.CamelVertxWebsocket.event} == 'OPEN'"))
.process(exchange -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("vertx-websocket:localhost:%d/echo/slow", port)
.toF("vertx-websocket:localhost:%d/echo/slow?sendToAll=true", port);
fromF("vertx-websocket:localhost:%d/echo/slow", port.getPort())
.toF("vertx-websocket:localhost:%d/echo/slow?sendToAll=true", port.getPort());

fromF("vertx-websocket:localhost:%d/echo/slow?consumeAsClient=true", port)
fromF("vertx-websocket:localhost:%d/echo/slow?consumeAsClient=true", port.getPort())
.delay(600).syncDelayed()
.to("mock:clientConsumerResult");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected RoutesBuilder createRouteBuilder() throws Exception {
@Override
public void configure() throws Exception {
from("direct:start")
.toF("vertx-websocket:localhost:%d/slow", port);
.toF("vertx-websocket:localhost:%d/slow", port.getPort());

fromF("vertx-websocket:localhost:%d/slow", port)
fromF("vertx-websocket:localhost:%d/slow", port.getPort())
.delay(600).syncDelayed()
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
import io.vertx.ext.web.RoutingContext;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.extension.RegisterExtension;

public class VertxWebSocketTestSupport extends CamelTestSupport {

protected final int port = AvailablePortFinder.getNextAvailable();
protected final int port2 = AvailablePortFinder.getNextAvailable();
@RegisterExtension
AvailablePortFinder.Port port = AvailablePortFinder.find();
@RegisterExtension
AvailablePortFinder.Port port2 = AvailablePortFinder.find();

/**
* Returns the randomized port used for the Vert.x server if no port was provided to the consumer.
Expand All @@ -49,8 +52,8 @@ public int getVertxServerRandomPort() {
Map<VertxWebsocketHostKey, VertxWebsocketHost> registry = component.getVertxHostRegistry();
return registry.values()
.stream()
.filter(wsHost -> wsHost.getPort() != port)
.filter(wsHost -> wsHost.getPort() != port2)
.filter(wsHost -> wsHost.getPort() != port.getPort())
.filter(wsHost -> wsHost.getPort() != port2.getPort())
.findFirst()
.get()
.getPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void testConsumeAsClientBinaryMessage() throws InterruptedException {
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedMessageCount(5);

String uri = String.format("vertx-websocket:localhost:%d/echo", port);
String uri = String.format("vertx-websocket:localhost:%d/echo", port.getPort());
for (int i = 1; i <= 5; i++) {
template.sendBody(uri, "Hello World".getBytes(StandardCharsets.UTF_8));
}
Expand All @@ -43,11 +43,11 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
fromF("vertx-websocket:localhost:%d/echo", port)
fromF("vertx-websocket:localhost:%d/echo", port.getPort())
.log("Server consumer received message: ${body}")
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port);
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port.getPort());

fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true", port)
fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true", port.getPort())
.log("Client consumer received message: ${body}")
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void testMaxReconnect() throws Exception {
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedBodiesReceived("Hello World");

String uri = String.format("vertx-websocket:localhost:%d/echo", port);
String uri = String.format("vertx-websocket:localhost:%d/echo", port.getPort());
template.sendBody(uri, "Hello World");
mockEndpoint.assertIsSatisfied();

Expand Down Expand Up @@ -69,12 +69,12 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
fromF("vertx-websocket:localhost:%d/echo", port).routeId("server")
fromF("vertx-websocket:localhost:%d/echo", port.getPort()).routeId("server")
.log("Server consumer: Received message: ${body}")
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port);
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port.getPort());

fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true&reconnectInterval=10&maxReconnectAttempts=1",
port)
port.getPort())
.log("Client consumer 1: Received message: ${body}")
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void testReconnect() throws Exception {
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedBodiesReceived("Hello World");

String uri = String.format("vertx-websocket:localhost:%d/echo", port);
String uri = String.format("vertx-websocket:localhost:%d/echo", port.getPort());
template.sendBody(uri, "Hello World");
mockEndpoint.assertIsSatisfied();

Expand Down Expand Up @@ -69,11 +69,11 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
fromF("vertx-websocket:localhost:%d/echo", port).routeId("server")
fromF("vertx-websocket:localhost:%d/echo", port.getPort()).routeId("server")
.log("Server consumer: Received message: ${body}")
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port);
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port.getPort());

fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true&reconnectInterval=10", port)
fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true&reconnectInterval=10", port.getPort())
.log("Client consumer 1: Received message: ${body}")
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void testConsumeAsClientTextMessage() throws InterruptedException {
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedMessageCount(5);

String uri = String.format("vertx-websocket:localhost:%d/echo", port);
String uri = String.format("vertx-websocket:localhost:%d/echo", port.getPort());
for (int i = 1; i <= 5; i++) {
template.sendBody(uri, "Hello World " + i);
}
Expand All @@ -41,11 +41,11 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
fromF("vertx-websocket:localhost:%d/echo", port)
fromF("vertx-websocket:localhost:%d/echo", port.getPort())
.log("Server consumer received message: ${body}")
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port);
.toF("vertx-websocket:localhost:%d/echo?sendToAll=true", port.getPort());

fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true", port)
fromF("vertx-websocket:localhost:%d/echo?consumeAsClient=true", port.getPort())
.log("Client consumer received message: ${body}")
.to("mock:result");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.AvailablePortFinder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.apache.camel.component.vertx.websocket.VertxWebsocketConstants.ORIGIN_HTTP_HEADER_NAME;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -38,7 +39,8 @@

public class VertxWebsocketEndpointConfigurationTest extends VertxWebSocketTestSupport {

private static final int PORT = AvailablePortFinder.getNextAvailable();
@RegisterExtension
static AvailablePortFinder.Port PORT = AvailablePortFinder.find();

@BindToRegistry("clientOptions")
HttpClientOptions clientOptions = new HttpClientOptions();
Expand All @@ -49,7 +51,7 @@ public class VertxWebsocketEndpointConfigurationTest extends VertxWebSocketTestS
@Test
public void testHttpClientOptions() {
VertxWebsocketEndpoint endpoint = context
.getEndpoint("vertx-websocket:localhost:" + PORT + "/options/client?clientOptions=#clientOptions",
.getEndpoint("vertx-websocket:localhost:" + PORT.getPort() + "/options/client?clientOptions=#clientOptions",
VertxWebsocketEndpoint.class);

assertSame(clientOptions, endpoint.getConfiguration().getClientOptions());
Expand All @@ -58,7 +60,7 @@ public void testHttpClientOptions() {
@Test
public void testHttpServerOptions() {
VertxWebsocketEndpoint endpoint = context
.getEndpoint("vertx-websocket:localhost:" + PORT + "/options/server?serverOptions=#serverOptions",
.getEndpoint("vertx-websocket:localhost:" + PORT.getPort() + "/options/server?serverOptions=#serverOptions",
VertxWebsocketEndpoint.class);

assertSame(serverOptions, endpoint.getConfiguration().getServerOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
fromF("vertx-websocket:localhost:%d/test/a", port)
fromF("vertx-websocket:localhost:%d/test/a", port.getPort())
.setBody(simple("Hello ${body}"))
.to("mock:result");

fromF("vertx-websocket:localhost:%d/test/b", port)
fromF("vertx-websocket:localhost:%d/test/b", port.getPort())
.setBody(simple("Hello ${body}"))
.to("mock:result");

fromF("vertx-websocket:localhost:%d/test/c", port)
fromF("vertx-websocket:localhost:%d/test/c", port.getPort())
.setBody(simple("Hello ${body}"))
.to("mock:result");

fromF("vertx-websocket:localhost:%d/test", port2)
fromF("vertx-websocket:localhost:%d/test", port2.getPort())
.setBody(simple("Hello ${body}"))
.to("mock:result2");
}
Expand Down
Loading
Loading