SHARE
TWEET

Untitled

a guest Jan 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top