package com.plannaplan.controllers; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration public class TokenControllerTest extends AbstractControllerTest { private final String TOKEN_ENDPOINT = "/token"; @Test public void shouldFailWithNoParameter() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); mockMvc.perform(get(TOKEN_ENDPOINT)).andExpect(status().isBadRequest()); } @Test public void shouldFailWithWrongTicket() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); mockMvc.perform(get(TOKEN_ENDPOINT).param("ticket", "totaly-wrong-ticket")) .andExpect(status().is4xxClientError()); } @Test @Ignore public void shouldReturnToken() throws Exception { // have no idea how to make this test independent from user that run this String ticket = ""; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); mockMvc.perform(get(TOKEN_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk()); } }