Search in sources :

Example 26 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class CustomContainerWebSocketsApplicationTests method reverseEndpoint.

@Test
public void reverseEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class).properties("websocket.uri:ws://localhost:" + PORT + "/ws/reverse").run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0);
    assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 27 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class SampleAtmosphereApplicationTests method chatEndpoint.

@Test
public void chatEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class).properties("websocket.uri:ws://localhost:" + this.port + "/chat/websocket").run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();
    assertThat(count).isEqualTo(0L);
    assertThat(messagePayloadReference.get()).contains("{\"message\":\"test\",\"author\":\"test\",\"time\":");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class SampleSessionRedisApplicationTests method sessionExpiry.

@Test
public void sessionExpiry() throws Exception {
    String port = null;
    try {
        ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionRedisApplication.class).properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer()).run();
        port = context.getEnvironment().getProperty("local.server.port");
    } catch (RuntimeException ex) {
        if (!redisServerRunning(ex)) {
            return;
        }
        throw ex;
    }
    URI uri = URI.create("http://localhost:" + port + "/");
    RestTemplate restTemplate = new RestTemplate();
    ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
    String uuid1 = response.getBody();
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie"));
    RequestEntity<Void> request = new RequestEntity<>(requestHeaders, HttpMethod.GET, uri);
    String uuid2 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid1).isEqualTo(uuid2);
    Thread.sleep(5000);
    String uuid3 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid2).isNotEqualTo(uuid3);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) HttpHeaders(org.springframework.http.HttpHeaders) ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) URI(java.net.URI) RestTemplate(org.springframework.web.client.RestTemplate) RequestEntity(org.springframework.http.RequestEntity) Test(org.junit.Test)

Example 29 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class SampleElasticsearchApplicationTests method testDefaultSettings.

@Test
public void testDefaultSettings() throws Exception {
    new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
    String output = this.outputCapture.toString();
    assertThat(output).contains("firstName='Alice', lastName='Smith'");
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test)

Example 30 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-boot by spring-projects.

the class ShutdownParentEndpointTests method shutdownParent.

@Test
public void shutdownParent() throws Exception {
    this.context = new SpringApplicationBuilder(Empty.class).child(Config.class).web(WebApplicationType.NONE).run();
    CountDownLatch latch = this.context.getBean(Config.class).latch;
    assertThat((String) getEndpointBean().invoke().get("message")).startsWith("Shutting down");
    assertThat(this.context.isActive()).isTrue();
    assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)36 Test (org.junit.Test)32 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 DefaultTokenServices (org.springframework.security.oauth2.provider.token.DefaultTokenServices)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 URI (java.net.URI)1 RoutesCollector (org.apache.camel.spring.boot.RoutesCollector)1 Logger (org.slf4j.Logger)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)1 Banner (org.springframework.boot.Banner)1 SpringApplication (org.springframework.boot.SpringApplication)1 JmxAutoConfiguration (org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration)1 ParentContextApplicationContextInitializer (org.springframework.boot.builder.ParentContextApplicationContextInitializer)1 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)1 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ApplicationListener (org.springframework.context.ApplicationListener)1