Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /**
  2. * Example of a @AutoConfigureMockMvc test. This test gives the unit test access to a mock
  3. * Spring Application context, but does not actually start the server.
  4. *
  5. * The entire application context is mocked in this case (@Controller, @Service, etc...). See
  6. * the @WebMvcTest for an example.
  7. */
  8.  
  9. package com.healthpartners.foundation.sso;
  10.  
  11. import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  12. import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
  13. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern;
  14. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  15.  
  16. import org.junit.Test;
  17. import org.junit.runner.RunWith;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
  20. import org.springframework.test.context.ActiveProfiles;
  21. import org.springframework.test.context.junit4.SpringRunner;
  22. import org.springframework.test.web.servlet.MockMvc;
  23.  
  24. @RunWith(SpringRunner.class)
  25. @AutoConfigureMockMvc
  26. @ActiveProfiles("test")
  27. public class ExampleAutoConfigureMockMvcTest {
  28.  
  29. @Autowired
  30. private MockMvc mockMvc;
  31.  
  32. @Test
  33. public void shouldRedirect() throws Exception {
  34. this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().is3xxRedirection())
  35. .andExpect(redirectedUrlPattern("/index.html**"));
  36. }
  37.  
  38. }
Add Comment
Please, Sign In to add comment