package com.example;

import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DemoApplication.class)
@WebIntegrationTest(randomPort=true)
public class DemoApplicationTests {

    @Autowired
    private WebApplicationContext context;

    private MockMvc mvc;

    @Before
    public void setup() {
        mvc = MockMvcBuilders
                .webAppContextSetup(context)
                .build();
    }

    @Test
    public void restTest() throws Exception {
        mvc.perform(put("/mice/0f629be4-e6cc-11e5-bb3b-3bf5fa6b2828").content(
                new ObjectMapper().writeValueAsString(ImmutableMap.of("name", "My Mouse"))
        ))
        .andExpect(status().isCreated())
        .andExpect(header().string("Location", endsWith("/mice/0f629be4-e6cc-11e5-bb3b-3bf5fa6b2828")))
        .andDo(print())
        .andDo((a) -> {
            // follow the location header.
            mvc.perform(get(a.getResponse().getHeader("Location")))
            .andDo(print())
            .andExpect(status().isOk());
        });
    }

}

@@ -695,38 +695,30 @@
 est.
-SpringApplicationConfiguration
+context.SpringBootTest
 ;%0Aim
@@ -752,33 +752,52 @@
 ot.test.
-WebIntegrationTes
+context.SpringBootTest.WebEnvironmen
 t;%0Aimpor
@@ -840,35 +840,24 @@
 unit4.Spring
-JUnit4Class
 Runner;%0Aimpo
@@ -1154,19 +1154,8 @@
 ring
-JUnit4Class
 Runn
@@ -1175,101 +1175,60 @@
 ring
-ApplicationConfiguration(classes = DemoApplication.class)%0A@WebIntegrationTest(randomPort=true
+BootTest(webEnvironment = WebEnvironment.RANDOM_PORT
 )%0Apu
@@ -1262,16 +1262,42 @@
 ests %7B%0A%0A
+    private MockMvc mvc;%0A%0A
     @Aut
@@ -1351,34 +1351,8 @@
 t;%0A%0A
-    private MockMvc mvc;%0A%0A
     

update to 1.4.0 featured test improvements