Added new /config/tours, tests
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
@ -5,6 +5,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Date;
|
||||
@ -37,6 +38,7 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
private static final String FILE_NAME = "Zajecia.xlsx";
|
||||
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
|
||||
private static final String COURSE_ENDPOINT = "/api/v1/configurator/config/courses";
|
||||
private static final String TOURS_ENDPOINT = "/api/v1/configurator/config/tours";
|
||||
private static final String ADMIN_INIT_ENDPOINT = "/api/v1/configurator/admin/init";
|
||||
private static final String FIRST_TOUR_START = "firstTourBegin";
|
||||
private static final String FIRST_TOUR_END = "firstTourEnd";
|
||||
@ -259,7 +261,7 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeniedForCoursesDueToWrongRole() throws Exception {
|
||||
public void shouldDenyForCoursesDueToWrongRole() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorizedForCourses@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
@ -272,4 +274,73 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnOKAuthorizedForTours() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorizedForTours@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongSecondTour() throws Exception {
|
||||
final String mail = "shouldFailToursWithWrongSecondTour@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "13.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongFirstTour() throws Exception {
|
||||
final String mail = "shouldFailWithWrongFirstTour@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "10.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongSecondTourBegin() throws Exception {
|
||||
final String mail = "shouldFailWithWrongSecondTourBegin@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "13.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyForTours() throws Exception {
|
||||
final String mail = "shouldDenyForTours@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user