Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package com.javaeeeee.springrest.controllers;
  2.  
  3. import org.junit.Test;
  4. import org.junit.Before;
  5. import org.junit.runner.RunWith;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.test.context.ContextConfiguration;
  8. import org.springframework.test.context.junit4.SpringRunner;
  9. import org.springframework.test.context.web.WebAppConfiguration;
  10. import org.springframework.test.web.servlet.MockMvc;
  11.  
  12. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
  13. import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  14. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  15.  
  16. import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  17. import org.springframework.web.context.WebApplicationContext;
  18.  
  19. @RunWith(SpringRunner.class)
  20. @WebAppConfiguration
  21. @ContextConfiguration("classpath:test-dispatcher-servlet.xml")
  22. public class HelloControllerTest {
  23.  
  24. @Autowired
  25. private WebApplicationContext webApplicationContext;
  26.  
  27. private MockMvc mockMvc;
  28.  
  29. @Before
  30. public void setUp() {
  31. this.mockMvc = MockMvcBuilders
  32. .webAppContextSetup(this.webApplicationContext)
  33. .build();
  34. }
  35.  
  36. @Test
  37. public void testGetGreeting() throws Exception {
  38. this.mockMvc.perform(get("/hello"))
  39. .andExpect(status().isOk())
  40. .andExpect(content().string("Hello Spring World!"));
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement