Use Generated Port for Boot Test Cases
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-websocket="http://www.springframework.org/schema/integration/websocket"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/websocket
|
||||
http://www.springframework.org/schema/integration/websocket/spring-integration-websocket.xsd">
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-websocket="http://www.springframework.org/schema/integration/websocket"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
|
||||
http://www.springframework.org/schema/integration/websocket http://www.springframework.org/schema/integration/websocket/spring-integration-websocket.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<context:property-placeholder />
|
||||
|
||||
<bean id="webSocketClient" class="org.springframework.web.socket.client.standard.StandardWebSocketClient"/>
|
||||
|
||||
<int-websocket:client-container id="clientWebSocketContainer"
|
||||
client="webSocketClient"
|
||||
uri="ws://localhost:8080/time/websocket"/>
|
||||
uri="ws://localhost:${local.server.port:8080}/time/websocket"/>
|
||||
|
||||
<int-websocket:inbound-channel-adapter container="clientWebSocketContainer"
|
||||
channel="webSocketInputChannel"/>
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -50,11 +51,15 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = Application.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest
|
||||
@IntegrationTest({"server.port=0", "management.port=0"})
|
||||
public class ApplicationTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private String port;
|
||||
|
||||
@Test
|
||||
public void testWebSockets() throws InterruptedException {
|
||||
System.setProperty("local.server.port", this.port);
|
||||
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("client-context.xml",
|
||||
org.springframework.integration.samples.websocket.standard.client.Application.class);
|
||||
DirectChannel webSocketInputChannel = ctx.getBean("webSocketInputChannel", DirectChannel.class);
|
||||
|
||||
Reference in New Issue
Block a user