Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javaeeeee.springrest.controllers;
- import org.junit.Test;
- import org.junit.Before;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.test.context.ContextConfiguration;
- import org.springframework.test.context.junit4.SpringRunner;
- import org.springframework.test.context.web.WebAppConfiguration;
- import org.springframework.test.web.servlet.MockMvc;
- import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
- import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
- import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
- import org.springframework.test.web.servlet.setup.MockMvcBuilders;
- import org.springframework.web.context.WebApplicationContext;
- @RunWith(SpringRunner.class)
- @WebAppConfiguration
- @ContextConfiguration("classpath:test-dispatcher-servlet.xml")
- public class HelloControllerTest {
- @Autowired
- private WebApplicationContext webApplicationContext;
- private MockMvc mockMvc;
- @Before
- public void setUp() {
- this.mockMvc = MockMvcBuilders
- .webAppContextSetup(this.webApplicationContext)
- .build();
- }
- @Test
- public void testGetGreeting() throws Exception {
- this.mockMvc.perform(get("/hello"))
- .andExpect(status().isOk())
- .andExpect(content().string("Hello Spring World!"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement