emr_demo
@ 2
emr_demo / web_emr - Copy / src / test / java / org / zerhusen / rest / PersonRestControllerTest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
package org.zerhusen.rest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import com.bestray.security.JwtTokenUtil; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @SpringBootTest public class PersonRestControllerTest { private MockMvc mvc; @MockBean private JwtTokenUtil jwtTokenUtil; @Autowired private WebApplicationContext context; @Before public void setup() { mvc = MockMvcBuilders .webAppContextSetup(context) .apply(springSecurity()) .build(); } @Test public void shouldGetUnauthorizedWithoutRole() throws Exception{ this.mvc.perform(get("/persons")) .andExpect(status().isUnauthorized()); } @Test @WithMockUser(roles = "USER") public void getPersonsSuccessfullyWithUserRole() throws Exception{ this.mvc.perform(get("/persons")) .andExpect(status().is2xxSuccessful()); } } |
Commits for emr_demo/web_emr - Copy/src/test/java/org/zerhusen/rest/PersonRestControllerTest.java
Revision | Author | Commited | Message |
---|---|---|---|
2 | girijabapi | Thu 11 Oct, 2018 04:44:08 +0000 | initial commit |