AppTest -> AppLiveTest

This commit is contained in:
pivovarit 2017-02-04 17:22:28 +01:00
parent 02245b75a8
commit 4771252f6b

View File

@ -1,39 +1,39 @@
package com.baeldung.intro; package com.baeldung.intro;
import static org.hamcrest.Matchers.equalTo; import org.junit.Test;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import org.junit.runner.RunWith;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.junit.Test; import org.springframework.boot.test.context.SpringBootTest;
import org.junit.runner.RunWith; import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner; import static org.hamcrest.Matchers.equalTo;
import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@AutoConfigureMockMvc @AutoConfigureMockMvc
public class AppTest { public class AppLiveTest {
@Autowired @Autowired
private MockMvc mvc; private MockMvc mvc;
@Test @Test
public void getIndex() throws Exception { public void getIndex() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)) mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(equalTo("Index Page"))); .andExpect(content().string(equalTo("Index Page")));
} }
@Test @Test
public void getLocal() throws Exception { public void getLocal() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON)) mvc.perform(MockMvcRequestBuilders.get("/local").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(equalTo("/local"))); .andExpect(content().string(equalTo("/local")));
} }
} }