2021-01-10 10:57:33 +01:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
2021-01-10 12:45:51 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-01-10 10:57:33 +01:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2021-01-10 12:45:51 +01:00
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.test.annotation.DirtiesContext;
|
|
|
|
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
2021-01-10 10:57:33 +01:00
|
|
|
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;
|
|
|
|
|
2021-01-10 12:45:51 +01:00
|
|
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
2021-01-10 10:57:33 +01:00
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
2021-01-10 12:45:51 +01:00
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
2021-01-10 10:57:33 +01:00
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
2021-01-10 12:45:51 +01:00
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
import com.plannaplan.entities.Assignment;
|
|
|
|
import com.plannaplan.entities.Commision;
|
2021-01-18 16:21:32 +01:00
|
|
|
import com.plannaplan.entities.Course;
|
2021-01-10 14:15:58 +01:00
|
|
|
import com.plannaplan.entities.Exchange;
|
2021-01-10 12:45:51 +01:00
|
|
|
import com.plannaplan.entities.Groups;
|
|
|
|
import com.plannaplan.entities.User;
|
2021-01-10 14:15:58 +01:00
|
|
|
import com.plannaplan.services.AssignmentService;
|
|
|
|
import com.plannaplan.services.CommisionService;
|
2021-01-18 16:21:32 +01:00
|
|
|
import com.plannaplan.services.CourseService;
|
2021-01-10 14:15:58 +01:00
|
|
|
import com.plannaplan.services.ExchangeService;
|
2021-01-10 12:45:51 +01:00
|
|
|
import com.plannaplan.services.GroupService;
|
|
|
|
import com.plannaplan.services.UserService;
|
|
|
|
import com.plannaplan.types.UserRoles;
|
|
|
|
import com.plannaplan.types.WeekDay;
|
|
|
|
|
2021-01-10 10:57:33 +01:00
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@SpringBootTest
|
|
|
|
@ContextConfiguration
|
2021-01-10 12:45:51 +01:00
|
|
|
public class ExchangeControllerTest extends AbstractControllerTest {
|
|
|
|
|
|
|
|
private final static String EXCHANGE_ENDPOINT = "/api/v1/exchanges/exchange";
|
|
|
|
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
|
|
|
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private UserService userService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private GroupService groupService;
|
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
@Autowired
|
|
|
|
private AssignmentService assignmentService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private CommisionService commisionService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ExchangeService exchangeService;
|
|
|
|
|
2021-01-18 16:21:32 +01:00
|
|
|
@Autowired
|
|
|
|
private CourseService courseService;
|
|
|
|
|
2021-01-10 10:57:33 +01:00
|
|
|
@Test
|
2021-01-10 12:45:51 +01:00
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
|
|
|
public void shouldGetAllUsersExchanges() throws Exception {
|
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldGetAllUsersExchanges@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
this.exchangeService.save(new Exchange(assignment, groupDesired));
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/all").header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-10 12:45:51 +01:00
|
|
|
public void shouldFailGettingNotExistingExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailGettingNotExistingExchange@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
|
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-10 12:45:51 +01:00
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldGetSingleExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(new User(null, null, "shouldGetSingleExchange@ExchangeController.test",
|
|
|
|
"11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailGettingExchangeDueToPermission() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailGettingExchangeDueToPermission@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
|
|
|
|
|
|
|
final User user2 = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailGettingExchangeDueToPermission2@ExchangeController.test", "11112", UserRoles.STUDENT, 321));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token2 = this.userService.login(user2).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailPostDueToAssignmentNotFound() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailPostDueToAssignmentNotFound@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
|
|
|
|
2021-01-18 16:21:32 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(
|
|
|
|
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldInsertExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(
|
|
|
|
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
|
|
|
|
this.assignmentService.callAcceptAlgorythm();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
|
|
|
.andExpect(status().isOk());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailInsertExchangeDueToMissingGroup() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailInsertExchangeDueToMissingGroup@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8).content("{\"assignment\": " + user.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailInsertExchangeDueToMissingAssignment() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailInsertExchangeDueToMissingAssignment@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8).content("{\"group\": " + group.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailInsertExchangeDueToMissingParam() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailInsertExchangeDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(
|
|
|
|
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldDenyExchangeDueToAssigmentOverlapping() throws Exception {
|
|
|
|
final User user = this.userService
|
|
|
|
.save(new User(null, null, "shouldDenyExchangeDueToAssigmentOverlapping@ExchangeController.test",
|
|
|
|
"11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
this.exchangeService.save(new Exchange(assignment, group));
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(
|
|
|
|
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + user.getId() + ", \"group\": " + group.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
2021-01-10 14:15:58 +01:00
|
|
|
|
2021-01-10 12:45:51 +01:00
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldDenyPostDueToAssignmentNotAccepted() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldDenyPostDueToAssignmentNotAccepted@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 12:45:51 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(212, "A2-1", null, 420, WeekDay.WEDNESDAY, null));
|
2021-01-10 14:15:58 +01:00
|
|
|
final Groups group2 = this.groupService.save(new Groups(213, "A2-2", null, 420, WeekDay.MONDAY, null));
|
2021-01-18 16:21:32 +01:00
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
2021-01-10 12:45:51 +01:00
|
|
|
|
2021-01-10 14:15:58 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(
|
|
|
|
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-10 12:45:51 +01:00
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldDeleteExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(
|
|
|
|
new User(null, null, "shouldDeleteExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailDeleteDueToWrongPermissions() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailDeleteDueToWrongPermissions@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:15:58 +01:00
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
final Exchange exchange = this.exchangeService.save(new Exchange(assignment, groupDesired));
|
|
|
|
|
|
|
|
final User user2 = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailDeleteDueToWrongPermissions@ExchangeController2.test", "11112", UserRoles.STUDENT, 322));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token2 = this.userService.login(user2).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(get(EXCHANGE_ENDPOINT + "/" + exchange.getId()).header("Authorization", "Bearer " + token2))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailDeleteDueToMissingParam() throws Exception {
|
|
|
|
final User user = this.userService.save(
|
|
|
|
new User(null, null, "shouldFailDeleteDueToMissingParam@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(delete(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
2021-01-10 12:45:51 +01:00
|
|
|
|
|
|
|
@Test
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailDeleteDueToExchangeNotFound() throws Exception {
|
2021-01-10 12:45:51 +01:00
|
|
|
final User user = this.userService.save(new User(null, null,
|
2021-01-18 16:21:32 +01:00
|
|
|
"shouldFailDeleteDueToExchangeNotFound@ExchangeController.test", UserRoles.STUDENT));
|
2021-01-10 14:15:58 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(delete(EXCHANGE_ENDPOINT + "/" + user.getId()).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 12:45:51 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 10:57:33 +01:00
|
|
|
@Test
|
2021-01-10 12:45:51 +01:00
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
2021-01-18 16:21:32 +01:00
|
|
|
public void shouldFailPostDueToGroupAlreadyAccepted() throws Exception {
|
|
|
|
final User user = this.userService.save(new User(null, null,
|
|
|
|
"shouldFailPostDueToGroupAlreadyAccepted@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
2021-01-10 14:24:39 +01:00
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", null, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups group2 = this.groupService.save(new Groups(216, "A2-3", null, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
this.assignmentService.save(new Assignment(group2, commision));
|
|
|
|
this.assignmentService.callAcceptAlgorythm();
|
|
|
|
this.exchangeService.save(new Exchange(assignment, group2));
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
2021-01-18 16:21:32 +01:00
|
|
|
mockMvc.perform(
|
|
|
|
post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + group2.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
|
|
|
public void shouldFailForDiffrentCoursesExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(
|
|
|
|
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Course course = this.courseService
|
|
|
|
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC"));
|
|
|
|
final Course course2 = this.courseService
|
|
|
|
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse2", "SFFDCEC-2"));
|
|
|
|
final Groups group = this.groupService.save(new Groups(215, "A2-2", course, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course2, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
|
|
|
|
this.assignmentService.callAcceptAlgorythm();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
|
|
|
public void shouldFailForDiffrentGroupTypesExchange() throws Exception {
|
|
|
|
final User user = this.userService.save(
|
|
|
|
new User(null, null, "shouldInsertExchange@ExchangeController.test", "11111", UserRoles.STUDENT, 320));
|
|
|
|
final String token = this.userService.login(user).getToken();
|
|
|
|
final Course course = this.courseService
|
|
|
|
.save(new Course("shouldFailForDiffrentCoursesExchangeCourse", "SFFDCEC"));
|
|
|
|
final Groups group = this.groupService.save(new Groups(12, "A2-2", course, 520, WeekDay.TUESDAY, null));
|
|
|
|
final Groups groupDesired = this.groupService.save(new Groups(216, "A2-3", course, 530, WeekDay.MONDAY, null));
|
|
|
|
final Commision commision = this.commisionService.save(new Commision(user));
|
|
|
|
final Assignment assignment = this.assignmentService.save(new Assignment(group, commision));
|
|
|
|
|
|
|
|
this.assignmentService.callAcceptAlgorythm();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8)
|
|
|
|
.content("{\"assignment\": " + assignment.getId() + ", \"group\": " + groupDesired.getId() + " }"))
|
|
|
|
.andExpect(status().isBadRequest());
|
2021-01-10 10:57:33 +01:00
|
|
|
}
|
|
|
|
}
|