2020-10-02 16:51:49 +02:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
2020-10-05 17:56:35 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2020-10-02 16:51:49 +02:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2020-10-08 15:24:23 +02:00
|
|
|
import org.springframework.http.MediaType;
|
2020-10-02 16:51:49 +02:00
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
2020-10-05 17:56:35 +02:00
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
2020-10-08 15:24:23 +02:00
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
2020-10-05 17:56:35 +02:00
|
|
|
import com.plannaplan.entities.User;
|
|
|
|
import com.plannaplan.services.UserService;
|
|
|
|
import com.plannaplan.types.UserRoles;
|
|
|
|
|
2021-01-17 17:35:11 +01:00
|
|
|
import static org.junit.Assert.assertTrue;
|
2020-10-05 17:56:35 +02:00
|
|
|
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;
|
2020-10-02 16:51:49 +02:00
|
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@SpringBootTest
|
|
|
|
@ContextConfiguration
|
2020-10-30 16:53:41 +01:00
|
|
|
public class CommisionControllerTest extends AbstractControllerTest {
|
2020-10-05 17:56:35 +02:00
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private UserService service;
|
|
|
|
|
|
|
|
private static User user;
|
2021-01-17 17:35:11 +01:00
|
|
|
private static User admin;
|
2020-10-30 14:27:13 +01:00
|
|
|
private static User otherUser;
|
|
|
|
private static User asker;
|
|
|
|
private static User otherAsker;
|
|
|
|
|
|
|
|
private static final String TEST_COMMISIONS_STUDENT_EMAIL = "commisions.student@notexisting.domain";
|
2021-01-17 17:35:11 +01:00
|
|
|
private static final String TEST_COMMISIONS_ADMIN_EMAIL = "commisions.admin@notexisiting,domain";
|
2020-10-30 14:27:13 +01:00
|
|
|
private static final String TEST_COMMISIONS_OTHER_STUDENT_EMAIL = "commisions.student2@notexisting.domain";
|
|
|
|
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
|
|
|
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
2020-10-05 17:56:35 +02:00
|
|
|
|
2020-10-30 17:22:40 +01:00
|
|
|
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
|
|
|
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
2020-10-31 15:24:17 +01:00
|
|
|
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
2020-12-10 16:50:47 +01:00
|
|
|
private static final String GET_USER_SCHEDULE_ENDPOINT = "/api/v1/commisions/user/schedule";
|
2021-01-18 14:19:09 +01:00
|
|
|
private static final String GET_ASSIGNMENTS_ENDPOINT = "/api/v1/commisions/user/assignments";
|
2020-10-30 14:27:13 +01:00
|
|
|
|
2021-01-17 17:35:11 +01:00
|
|
|
private static final String EXPORT_DATA = "/api/v1/commisions/export/csv";
|
|
|
|
|
2020-10-08 15:24:23 +02:00
|
|
|
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
|
|
|
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
2020-10-05 17:56:35 +02:00
|
|
|
|
2020-10-02 16:51:49 +02:00
|
|
|
@Test
|
2020-10-05 17:56:35 +02:00
|
|
|
public void shouldReturn4xxAddingCommision() throws Exception {
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT)).andExpect(status().is4xxClientError());
|
|
|
|
|
2020-10-02 16:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-08 15:24:23 +02:00
|
|
|
public void shouldFailedAddingCommisionDueToNoArgs() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-05 17:56:35 +02:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
2020-10-08 15:24:23 +02:00
|
|
|
.andExpect(status().is4xxClientError());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-14 14:46:45 +01:00
|
|
|
public void shouldFailAddingCommisionDueToWrongTour() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-08 15:24:23 +02:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
2021-01-14 14:46:45 +01:00
|
|
|
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().is4xxClientError());
|
2020-10-02 16:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-05 17:56:35 +02:00
|
|
|
public void shouldReturn4xxGettingAllCommisions() throws Exception {
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT)).andExpect(status().is4xxClientError());
|
2020-10-02 16:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2020-10-05 17:56:35 +02:00
|
|
|
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-05 17:56:35 +02:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
|
2020-10-29 17:45:15 +01:00
|
|
|
@Test
|
2021-01-14 14:46:45 +01:00
|
|
|
public void shouldFailAddingCommisionWithSelfIdPrividedDueToWrongTour() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
2021-01-14 14:46:45 +01:00
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
2021-01-14 14:46:45 +01:00
|
|
|
.andExpect(status().is4xxClientError());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailCommisionWithSomeoneIdPrividedAsStudent() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailCommisionAsDeanaryWithNoId() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
|
|
|
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().is4xxClientError());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailCommisionWithSelfIdPrividedAsDeanary() throws Exception {
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.asker.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldAddCommisionWithSomeoneIdPrividedAsDeanary() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
|
|
|
.andExpect(status().isOk());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailCommisionWithOtherDeanaryIdPrividedAsDeanary() throws Exception {
|
2020-10-30 14:27:13 +01:00
|
|
|
this.checkUsers();
|
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-30 14:27:13 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherAsker.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2020-10-31 15:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldGetStudentCommisionsListByDeanary() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-31 15:24:17 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailStudentCommisionsListByOtherStudent() throws Exception {
|
|
|
|
this.checkUsers();
|
2020-12-07 21:46:47 +01:00
|
|
|
|
2020-12-03 16:57:53 +01:00
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
2020-12-07 21:46:47 +01:00
|
|
|
final String token = this.service.login(user).getToken();
|
2020-10-31 15:24:17 +01:00
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
|
|
|
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
2020-12-10 16:50:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldReturn4xxInScheduleEndpoint() throws Exception {
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_USER_SCHEDULE_ENDPOINT)).andExpect(status().is4xxClientError());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldReturnOkInScheduleEdnpoint() throws Exception {
|
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
|
|
|
final String token = this.service.login(user).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_USER_SCHEDULE_ENDPOINT).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldReturnOkInScheduleEdnpointByDeanery() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
|
|
|
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
|
|
|
final String token = this.service.login(user).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + student.getId() + "/schedule").header("Authorization",
|
|
|
|
"Bearer " + token)).andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailInScheduleEdnpointByOtherStudent() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
|
|
|
final User otherStudent = this.service.checkForUser(TEST_COMMISIONS_OTHER_STUDENT_EMAIL, null);
|
|
|
|
final String token = this.service.login(student).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherStudent.getId() + "/schedule").header("Authorization",
|
|
|
|
"Bearer " + token)).andExpect(status().is4xxClientError());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldFailInScheduleEdnpointByDeaneryDeaneryRelation() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User deanery = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
|
|
|
final User otherDeanery = this.service.checkForUser(TEST_COMMISIONS_OTHER_DEANERY_EMAIL, null);
|
|
|
|
final String token = this.service.login(deanery).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherDeanery.getId() + "/schedule").header("Authorization",
|
|
|
|
"Bearer " + token)).andExpect(status().is4xxClientError());
|
2020-10-29 17:45:15 +01:00
|
|
|
}
|
|
|
|
|
2020-10-30 14:27:13 +01:00
|
|
|
private void checkUsers() {
|
2020-10-05 17:56:35 +02:00
|
|
|
if (CommisionControllerTest.user == null) {
|
2020-10-30 14:27:13 +01:00
|
|
|
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);
|
2020-10-05 17:56:35 +02:00
|
|
|
this.service.save(user);
|
|
|
|
}
|
2020-10-30 14:27:13 +01:00
|
|
|
if (CommisionControllerTest.otherUser == null) {
|
|
|
|
CommisionControllerTest.otherUser = new User(null, null, TEST_COMMISIONS_OTHER_STUDENT_EMAIL,
|
|
|
|
UserRoles.STUDENT);
|
|
|
|
this.service.save(otherUser);
|
|
|
|
}
|
2021-01-18 13:38:24 +01:00
|
|
|
if (CommisionControllerTest.admin == null) {
|
|
|
|
CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN);
|
|
|
|
this.service.save(admin);
|
|
|
|
}
|
2020-10-30 14:27:13 +01:00
|
|
|
if (CommisionControllerTest.asker == null) {
|
|
|
|
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
|
|
|
this.service.save(asker);
|
|
|
|
}
|
|
|
|
if (CommisionControllerTest.otherAsker == null) {
|
|
|
|
CommisionControllerTest.otherAsker = new User(null, null, TEST_COMMISIONS_OTHER_DEANERY_EMAIL,
|
|
|
|
UserRoles.DEANERY);
|
|
|
|
this.service.save(otherAsker);
|
|
|
|
}
|
2020-10-02 16:51:49 +02:00
|
|
|
}
|
2021-01-17 17:35:11 +01:00
|
|
|
|
|
|
|
@Test
|
2021-01-18 13:38:24 +01:00
|
|
|
public void shouldExportData() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
|
|
|
final String token = this.service.login(admin).getToken();
|
2021-01-17 17:35:11 +01:00
|
|
|
|
2021-01-18 13:38:24 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
2021-01-17 17:35:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 13:38:24 +01:00
|
|
|
public void shouldNotExportDataDueToWrongPermision() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
|
|
|
final String token = this.service.login(student).getToken();
|
2021-01-17 17:35:11 +01:00
|
|
|
|
2021-01-18 13:38:24 +01:00
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().is4xxClientError());
|
2021-01-17 17:35:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-01-18 13:38:24 +01:00
|
|
|
public void shouldExportDataBeCsvFile() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
|
|
|
final String token = this.service.login(admin).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
|
|
|
|
assertTrue(
|
|
|
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk())
|
|
|
|
.andReturn().getResponse().getContentAsString().contains("user_id, zaj_cykl_id, gr_nr"));
|
2021-01-17 17:35:11 +01:00
|
|
|
}
|
2021-01-18 14:19:09 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldRetrunOkForAssignmentEnpoint() throws Exception {
|
|
|
|
this.checkUsers();
|
|
|
|
final User admin = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
|
|
|
final String token = this.service.login(admin).getToken();
|
|
|
|
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
|
|
|
|
|
|
|
mockMvc.perform(get(GET_ASSIGNMENTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
|
|
|
.andExpect(status().isOk());
|
|
|
|
}
|
2020-10-02 16:51:49 +02:00
|
|
|
}
|