use of cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer in project today-infrastructure by TAKETODAY.
the class ServletComponentScanIntegrationTests method indexedComponentsAreRegistered.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void indexedComponentsAreRegistered(String serverName, Class<?> configuration) throws IOException {
writeIndex(this.temp);
this.context = new AnnotationConfigServletWebServerApplicationContext();
try (URLClassLoader classLoader = new URLClassLoader(new URL[] { this.temp.toURI().toURL() }, getClass().getClassLoader())) {
this.context.setClassLoader(classLoader);
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
String port = this.context.getEnvironment().getProperty("local.server.port");
String response = new RestTemplate().getForObject("http://localhost:" + port + "/test", String.class);
assertThat(response).isEqualTo("alpha bravo charlie");
}
}
use of cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer in project today-infrastructure by TAKETODAY.
the class ServletWebServerApplicationContextTests method localPortIsAvailable.
@Test
void localPortIsAvailable() {
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 cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer in project today-framework by TAKETODAY.
the class ReactiveWebServerApplicationContextTests method whenContextIsRefreshedThenLocalServerPortIsAvailableFromTheEnvironment.
@Test
void whenContextIsRefreshedThenLocalServerPortIsAvailableFromTheEnvironment() {
addWebServerFactoryBean();
addHttpHandlerBean();
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 cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer in project today-framework by TAKETODAY.
the class ServletComponentScanIntegrationTests method componentsAreRegistered.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void componentsAreRegistered(String serverName, Class<?> configuration) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
String port = this.context.getEnvironment().getProperty("local.server.port");
String response = new RestTemplate().getForObject("http://localhost:" + port + "/test", String.class);
assertThat(response).isEqualTo("alpha bravo charlie");
}
use of cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer in project today-framework by TAKETODAY.
the class ServletWebServerApplicationContextTests method localPortIsAvailable.
@Test
void localPortIsAvailable() {
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");
}
Aggregations