123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.neo.web;
- import static org.hamcrest.Matchers.equalTo;
- import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
- 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.boot.test.SpringApplicationConfiguration;
- import org.springframework.http.MediaType;
- import org.springframework.mock.web.MockServletContext;
- import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import org.springframework.test.web.servlet.MockMvc;
- import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
- import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
- import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
- import org.springframework.test.web.servlet.setup.MockMvcBuilders;
- import static org.hamcrest.Matchers.equalTo;
- import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
- import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
- import com.neo.web.HelloController;
- @RunWith(SpringJUnit4ClassRunner.class)
- @SpringApplicationConfiguration(classes = MockServletContext.class)
- @WebAppConfiguration
- public class HelloControlerTests {
- private MockMvc mvc;
- @Before
- public void setUp() throws Exception {
- mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
- }
- @Test
- public void getHello() throws Exception {
- mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andDo(MockMvcResultHandlers.print())
- .andReturn();
- }
-
-
- @Test
- public void testHello() throws Exception {
- mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk())
- .andExpect(content().string(equalTo("Hello World")));
- }
- }
|