Compare commits

...

15 Commits
beta ... master

Author SHA1 Message Date
Marcin Woźniak cf4d8c05a2 Merge pull request 'single group fix' (#54) from single0-group-fix into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/54
2021-01-25 16:25:13 +01:00
Filip Izydorczyk 72f049b478 single group fix 2021-01-25 16:23:28 +01:00
Marcin Woźniak bb7f1b6737 Merge pull request 'fixed' (#53) from capacity-fix into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/53
2021-01-23 17:23:16 +01:00
Filip Izydorczyk ad4984bdae fixed 2021-01-23 16:45:36 +01:00
Marcin Woźniak 63def650c9 Merge pull request 'fix' (#52) from schedule-fix into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/52
2021-01-22 16:50:30 +01:00
Filip Izydorczyk a201bcc581 fix 2021-01-22 16:46:53 +01:00
Marcin Woźniak e688f8b71d Merge pull request 'gr_nr + sym' (#51) from new-response-fields into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/51
2021-01-22 16:20:34 +01:00
Filip Izydorczyk 389e557674 gr_nr + sym 2021-01-22 12:34:54 +01:00
Marcin Woźniak dd82acc1de Merge pull request 'statistics' (#50) from statistics into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/50
2021-01-21 16:49:37 +01:00
Filip Izydorczyk bfa8eb6e3e full groups statistics 2021-01-21 16:22:14 +01:00
Filip Izydorczyk a910709798 partly accepted statistics 2021-01-21 16:15:01 +01:00
Filip Izydorczyk 270e31f120 Fully accepted statistic 2021-01-21 16:08:53 +01:00
Filip Izydorczyk 6a0d425c37 Added non registered statistic 2021-01-21 15:50:20 +01:00
Filip Izydorczyk 676070c8c7 Students registered satistics 2021-01-21 15:41:56 +01:00
Filip Izydorczyk 7045844653 Groups ammounts 2021-01-21 15:05:45 +01:00
10 changed files with 499 additions and 12 deletions

View File

@ -10,17 +10,15 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* CommisionRepository.getUsers:
* Return list of:
* SELECT * FROM Commision WHERE owner_id = i .
* CommisionRepository.getUsers: Return list of: SELECT * FROM Commision WHERE
* owner_id = i .
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*
* CommisionRepository.getNewestCommision
* Return list of:
* SELECT * FROM Commision WHERE owner_id = i Order by commisionDate desc.
* CommisionRepository.getNewestCommision Return list of: SELECT * FROM
* Commision WHERE owner_id = i Order by commisionDate desc.
*
* Where i, ?1 are equale to variables.
* Where i, ?1 are equale to variables.
*/
@Repository
public interface CommisionRepository extends JpaRepository<Commision, Long> {
@ -30,4 +28,10 @@ public interface CommisionRepository extends JpaRepository<Commision, Long> {
@Query("FROM Commision WHERE owner_id = ?1 order by commisionDate desc")
List<Commision> getNewestCommision(@Param("owner_id") Long id);
/**
* @return ammount of uniqe users that have a commision placed on first array
* element
*/
@Query("SELECT COUNT(DISTINCT owner_id) AS count FROM Commision")
Object[] getUsersAssigned();
}

View File

@ -1,6 +1,7 @@
package com.plannaplan.services;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@ -153,4 +154,22 @@ public class GroupService {
return response;
}
/**
* @return amount of groups with full capacity taken
*/
public Integer getFullgroupsAmmount() {
Integer response = 0;
final Iterator<Groups> groups = this.repo.findAll().iterator();
while (groups.hasNext()) {
final Groups group = groups.next();
if (group.getCapacity() <= group.getRegisteredStudents().size()) {
response += 1;
}
}
return response;
}
}

View File

@ -1,13 +1,16 @@
package com.plannaplan.services;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import com.plannaplan.entities.Commision;
import com.plannaplan.entities.User;
import com.plannaplan.exceptions.UserNotFoundException;
import com.plannaplan.models.UserApiResponse;
import com.plannaplan.repositories.CommisionRepository;
import com.plannaplan.repositories.UserRepository;
import com.plannaplan.types.UserRoles;
@ -25,6 +28,12 @@ public class UserService {
@Autowired
private UsosApiService service;
@Autowired
private CommisionRepository comRepo;
@Autowired
private CommisionService comService;
public UserService() {
super();
}
@ -169,4 +178,52 @@ public class UserService {
}).collect(Collectors.toList());
}
/**
* @return ammount of how many users created an assignment
*/
public int getAmmountOfUsersWithAssignedGroups() {
int response = 0;
final Object dbResponse = this.comRepo.getUsersAssigned()[0];
if (dbResponse != null) {
response = ((Long) dbResponse).intValue();
}
return response;
}
/**
* @return ammount of how many users haven't created an assignment yet
*/
public Integer getAmmountOfUsersWithNoAssignedGroups() {
return this.getAllStudents().size() - this.getAmmountOfUsersWithAssignedGroups();
}
/**
* @return ammount of how many users have full schedule accepted
*/
public Integer getAmmountOfUsersWithAcceptedSchedules() {
final List<User> students = this.getAllStudents();
Integer accepted = 0;
final Iterator<User> it = students.iterator();
while (it.hasNext()) {
final User user = it.next();
final Optional<Commision> com = this.comService.getNewestCommision(user);
if (com.isPresent() && user.getStudentRegisteredGrups().size() == com.get().getAssignments().size()) {
accepted += 1;
}
}
return accepted;
}
/**
* @return ammount of how many users have partly or none schedule accepted
*/
public Integer getAmmountOfUsersWithNoAcceptedSchedules() {
return this.getAllStudents().size() - this.getAmmountOfUsersWithAcceptedSchedules();
}
}

View File

@ -0,0 +1,102 @@
package com.plannaplan.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.plannaplan.App;
import com.plannaplan.responses.models.StatisticSimpleNumberResponse;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.UserService;
/**
* Rest controller to enpoint that help deveopler test the app
*/
@RestController
@CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/statistics")
@Api(tags = {
"StatisticsController" }, value = "StatisticsController", description = "Statistics are meant to be used by deanery only so in every endpoint you need to provide DEANERY token.")
public class StatisticsController {
@Autowired
private GroupService groupService;
@Autowired
private UserService userService;
/**
* @return if tour was set
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/groups/created")
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.groupService.getGroupsAmmount());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return if tour was set
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/groups/full")
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsFullAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.groupService.getFullgroupsAmmount());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return amount of registered to some groups
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/registered")
public ResponseEntity<StatisticSimpleNumberResponse> getCommisionsAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithAssignedGroups());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return amount of students not registered to any groups
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/noregistered")
public ResponseEntity<StatisticSimpleNumberResponse> getNonCommisionsAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithNoAssignedGroups());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return amount of students that have fully accepted schedules
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/accepted")
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithAcceptedSchedules());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return amount of students that have purtly accepted schedules
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/accepted/partly")
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedPartlyAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithNoAcceptedSchedules());
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -16,6 +16,7 @@ import io.swagger.annotations.ApiModel;
public class AssignmentResponse {
private Long id;
private String name;
private String symbol;
private GroupWithCapacityResponse classes;
private GroupWithCapacityResponse lecture;
@ -27,10 +28,18 @@ public class AssignmentResponse {
public AssignmentResponse(Course course, Groups lecture, Groups classes) {
this.id = course.getId();
this.name = course.getName();
this.symbol = course.getSymbol();
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture);
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
}
/**
* @return returns symbol of assigned course
*/
public String getSymbol() {
return symbol;
}
/**
* @param course course entity
* @param lecture lecture Groups entity
@ -41,6 +50,7 @@ public class AssignmentResponse {
public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap<Long, Integer> ammounts) {
this.id = course.getId();
this.name = course.getName();
this.symbol = course.getSymbol();
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getId()));
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes, ammounts.get(classes.getId()));
}
@ -95,9 +105,15 @@ public class AssignmentResponse {
* places
*/
public AssignmentResponse(Course course, Assignment lecture, Assignment classes, HashMap<Long, Integer> ammounts) {
this.id = course.getId();
this.name = course.getName();
this.classes = new GroupWithCapacityResponse(classes, ammounts.get(classes.getGroup().getId()));
this.lecture = new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getGroup().getId()));
this.symbol = course.getSymbol();
this.classes = classes != null
? new GroupWithCapacityResponse(classes, ammounts.get(classes.getGroup().getId()))
: null;
this.lecture = lecture != null
? new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getGroup().getId()))
: null;
}
/**
@ -106,9 +122,11 @@ public class AssignmentResponse {
* @param classes class Groups entity
*/
public AssignmentResponse(Course course, Assignment lecture, Assignment classes) {
this.id = course.getId();
this.name = course.getName();
this.classes = new GroupWithCapacityResponse(classes);
this.lecture = new GroupWithCapacityResponse(lecture);
this.symbol = course.getSymbol();
this.classes = classes != null ? new GroupWithCapacityResponse(classes) : null;
this.lecture = lecture != null ? new GroupWithCapacityResponse(lecture) : null;
}
/**

View File

@ -42,6 +42,8 @@ public class GroupDefaultResponse {
@ApiModelProperty(value = "Used only in resposnes realted to user assignments. For example in /api/v1/users/schedule.")
private Boolean isAccepted;
private Integer grNr;
/**
* creat new entity
*
@ -55,6 +57,14 @@ public class GroupDefaultResponse {
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
this.room = group.getRoom() != null ? group.getRoom() : "";
this.type = group.getType() != null ? GroupType.isLectureOrClass(group.getType()) : null;
this.grNr = group.getGrNr() != null ? group.getGrNr() : null;
}
/**
* @return group number
*/
public Integer getGrNr() {
return grNr;
}
/**

View File

@ -50,6 +50,7 @@ public class GroupWithCapacityResponse extends GroupDefaultResponse {
*/
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
super(assignment, takenPlaces);
this.capacity = assignment.getGroup().getCapacity();
}
/**

View File

@ -0,0 +1,23 @@
package com.plannaplan.responses.models;
/**
* Simple api response for number statistics
*/
public class StatisticSimpleNumberResponse {
private Integer ammount;
/**
* @param ammount to return as api response
*/
public StatisticSimpleNumberResponse(Integer ammount) {
this.ammount = ammount;
}
/**
* @return ammount
*/
public Integer getAmmount() {
return ammount;
}
}

View File

@ -9,6 +9,7 @@ public abstract class CoursesResponse {
private Long id;
private String name;
private String symbol;
/**
* create instance
@ -18,6 +19,7 @@ public abstract class CoursesResponse {
public CoursesResponse(Course course) {
this.id = course.getId() != null ? course.getId() : null;
this.name = course.getName() != null ? course.getName() : "";
this.symbol = course.getSymbol() != null ? course.getSymbol() : "";
}
/**
@ -27,6 +29,13 @@ public abstract class CoursesResponse {
return name;
}
/**
* @return course symbol
*/
public String getSymbol() {
return symbol;
}
/**
* @return db id
*/

View File

@ -0,0 +1,244 @@
package com.plannaplan.controllers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
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;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
import com.plannaplan.entities.User;
import com.plannaplan.services.UserService;
import com.plannaplan.types.UserRoles;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class StatisticsControllerTest extends AbstractControllerTest {
private static final String GROUP_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/created";
private static final String GROUP_FULL_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/full";
private static final String USER_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/registered";
private static final String USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/noregistered";
private static final String USER_ACCEPTED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/accepted";
private static final String USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/accepted/partly";
@Autowired
private UserService userService;
/* GROUP AMMOUNTS TESTS */
@Test
public void shouldFailWithWrongAccesGroupsAmmounts() throws Exception {
final String mail = "shouldFailWithWrongAccesGroupsAmmounts@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingGroupsAmmounts() throws Exception {
final String mail = "shouldOkGettingGroupsAmmounts@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenGroupsAmmounts() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS ASSIGNED TESTS */
@Test
public void shouldFailWithWrongAccesRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccesRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenRegisteredStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS NO ASSIGNED TESTS */
@Test
public void shouldFailWithWrongAccesNoRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccesNoRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingNoRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingNoRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenNoRegisteredStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS FULL ACCPTED TESTS */
@Test
public void shouldFailWithWrongAccessAcceptedStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccessAcceptedStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingAcceptedStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingAcceptedStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenAcceptedStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS PARTLY ACCPTED TESTS */
@Test
public void shouldFailWithWrongAccessPartlyAcceptedStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccessPartlyAcceptedStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingPartlyAcceptedStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingPartlyAcceptedStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenPartlyAcceptedStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_PARTLY_ACCEPTED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
/* USERS FULL TAKEN GROUPS TESTS */
@Test
public void shouldFailWithWrongAccessFullGroupsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccessFullGroupsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingFullGroupsAmmount() throws Exception {
final String mail = "shouldOkGettingFullGroupsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenFullGroupsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(GROUP_FULL_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
}