use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method localPortIsAvailable.
@Test
public void localPortIsAvailable() throws Exception {
addWebServerFactoryBean();
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.containsProperty("local.server.port")).isTrue();
assertThat(environment.getProperty("local.server.port")).isEqualTo("8080");
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class BootCuriesHrefIntegrationTests method load.
private int load(String... properties) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.setClassLoader(new ClassLoader(getClass().getClassLoader()) {
@Override
public URL getResource(String name) {
if ("META-INF/resources/spring-boot-actuator/docs/index.html".equals(name)) {
return super.getResource("actuator-docs-index.html");
}
return super.getResource(name);
}
});
EnvironmentTestUtils.addEnvironment(this.context, properties);
this.context.register(TestConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
return Integer.parseInt(this.context.getEnvironment().getProperty("local.management.port"));
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class WebSocketMessagingAutoConfigurationTests method performStompSubscription.
private Object performStompSubscription(final String topic) throws Throwable {
EnvironmentTestUtils.addEnvironment(this.context, "server.port:0", "spring.jackson.serialization.indent-output:true");
this.context.register(WebSocketMessagingConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
WebSocketStompClient stompClient = new WebSocketStompClient(this.sockJsClient);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final AtomicReference<Object> result = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
StompSessionHandler handler = new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
session.subscribe(topic, new StompFrameHandler() {
@Override
public void handleFrame(StompHeaders headers, Object payload) {
result.set(payload);
latch.countDown();
}
@Override
public Type getPayloadType(StompHeaders headers) {
return Object.class;
}
});
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
latch.countDown();
}
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
failure.set(exception);
latch.countDown();
}
@Override
public void handleTransportError(StompSession session, Throwable exception) {
failure.set(exception);
latch.countDown();
}
};
stompClient.setMessageConverter(new SimpleMessageConverter());
stompClient.connect("ws://localhost:{port}/messaging", handler, this.context.getEnvironment().getProperty("local.server.port"));
if (!latch.await(30000, TimeUnit.SECONDS)) {
if (failure.get() != null) {
throw failure.get();
}
fail("Response was not received within 30 seconds");
}
return result.get();
}
Aggregations