|
| 1 | +package br.ufrn.dct.apf.controller; |
| 2 | + |
| 3 | +import org.springframework.beans.factory.annotation.Autowired; |
| 4 | +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 6 | +import org.springframework.test.web.servlet.MockMvc; |
| 7 | +import org.testng.annotations.AfterMethod; |
| 8 | +import org.testng.annotations.BeforeMethod; |
| 9 | +import org.testng.annotations.Test; |
| 10 | +import org.testng.asserts.SoftAssert; |
| 11 | + |
| 12 | +import br.ufrn.dct.apf.service.ProjectService; |
| 13 | +import br.ufrn.dct.apf.service.UserService; |
| 14 | + |
| 15 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 16 | +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
| 17 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 18 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
| 19 | +import static org.hamcrest.Matchers.containsString; |
| 20 | + |
| 21 | +@WebMvcTest(LoginController.class) |
| 22 | +public class LoginControllerTest extends AbstractControllerTest { |
| 23 | + |
| 24 | + private SoftAssert softAssert; |
| 25 | + |
| 26 | + @BeforeMethod |
| 27 | + public void startTest() { |
| 28 | + softAssert = new SoftAssert(); |
| 29 | + } |
| 30 | + |
| 31 | + @AfterMethod |
| 32 | + public void endTest() { |
| 33 | + softAssert = null; |
| 34 | + } |
| 35 | + |
| 36 | + @Autowired |
| 37 | + private MockMvc mockMvc; |
| 38 | + |
| 39 | + @MockBean |
| 40 | + private UserService userService; |
| 41 | + |
| 42 | + @MockBean |
| 43 | + private ProjectService projectService; |
| 44 | + |
| 45 | + @Test |
| 46 | + public void getRootURL() throws Exception { |
| 47 | + softAssert.assertNotNull(mockMvc); |
| 48 | + mockMvc.perform(get("/")) |
| 49 | + .andDo(print()) |
| 50 | + .andExpect(status().isOk()) |
| 51 | + .andExpect(content().string(containsString("action=\"/login\""))); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void getRegistrationURL() throws Exception { |
| 56 | + softAssert.assertNotNull(mockMvc); |
| 57 | + mockMvc.perform(get("/registration")) |
| 58 | + .andDo(print()) |
| 59 | + .andExpect(status().isOk()); |
| 60 | + } |
| 61 | +} |
0 commit comments