From 06fb41b5dd6e5abf8c3aba23c471d21a934ed306 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 09:32:57 +0100 Subject: [PATCH 1/8] commision controller not deleting fix --- .../com/plannaplan/services/AssignmentService.java | 8 ++++++++ .../plannaplan/controllers/CommisionController.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java b/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java index a99d0ea..8103d35 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java @@ -106,4 +106,12 @@ public class AssignmentService { this.emailService.sendAcceptationResult(e, new EmailAcceptedData(accepted, removed)); }); } + + /** + * @param toSave list of entites to save to db + * @return list of assignments entities with ids from db + */ + public List saveAll(List toSave) { + return this.repo.saveAll(toSave); + } } diff --git a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java index 4c9ded1..1d9a7cd 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CommisionController.java @@ -110,14 +110,16 @@ public class CommisionController extends TokenBasedController { final Optional comPrev = this.commisionService.getNewestCommision(user); final Commision com = new Commision(user, asker); - this.commisionService.save(com); final List addedGroups = new ArrayList<>(); + final List addedAssignments = new ArrayList<>(); + groups.stream().forEach((groupId) -> { Groups group = this.groupServcicxe.getGroupById(groupId) .orElseThrow(() -> new NullPointerException()); Assignment a = new Assignment(group, com); - this.assignmentService.save(a); + addedAssignments.add(a); + // this.assignmentService.save(a); addedGroups.add(groupId); }); @@ -127,7 +129,7 @@ public class CommisionController extends TokenBasedController { while (it.hasNext() && !isBad) { final Assignment a = it.next(); - if (a.isAccepted() && !addedGroups.contains(a.getId())) { + if (a.isAccepted() && !addedGroups.contains(a.getGroup().getId())) { isBad = true; } } @@ -139,6 +141,9 @@ public class CommisionController extends TokenBasedController { HttpStatus.BAD_REQUEST); } + this.commisionService.save(com); + this.assignmentService.saveAll(addedAssignments); + return new ResponseEntity<>("Succes", HttpStatus.OK); } catch (UserNotFoundException exception) { return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND); From 6a4ea4590055e1e1a9ed2c556d1a7f5609065640 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 10:44:35 +0100 Subject: [PATCH 2/8] brigning down group tpes --- .../java/com/plannaplan/types/GroupType.java | 22 +++++- .../com/plannaplan/types/GroupTypeTest.java | 68 +++++++++++++++++++ .../controllers/CoursesController.java | 2 +- .../mappers/AssignmentResponseMappers.java | 8 +-- .../responses/mappers/GroupsMappers.java | 4 +- .../responses/models/AssignmentResponse.java | 8 +-- .../models/CoursesWithGroupsResponse.java | 2 +- 7 files changed, 99 insertions(+), 15 deletions(-) create mode 100755 buisnesslogic/src/test/java/com/plannaplan/types/GroupTypeTest.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java b/buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java index 3b57aa8..0945095 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java +++ b/buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java @@ -1,23 +1,39 @@ package com.plannaplan.types; /** - * GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE + * GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE */ public enum GroupType { - LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"),CONSERVATORY("Konwersatorium"), PRATICE("Praktyka"); + LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"), CONSERVATORY("Konwersatorium"), + PRATICE("Praktyka"); public final String type; + private GroupType(String type) { this.type = type; } + /** + * @param type as string + * @return Enum converted from provided string + */ public final static GroupType getType(String type) { for (GroupType d : values()) { if (d.type.equals(type)) { return d; } } - return null; + return null; + } + + /** + * @param type group type to check + * @return general convertion to bring down tours to two generals LECTURE and + * CLASS. To class are included: CLASS, LAB, SEMINAR, CONSERVATORY, + * PRATICE. + */ + public final static GroupType isLectureOrClass(GroupType type) { + return type == GroupType.LECTURE ? GroupType.LECTURE : GroupType.CLASS; } } \ No newline at end of file diff --git a/buisnesslogic/src/test/java/com/plannaplan/types/GroupTypeTest.java b/buisnesslogic/src/test/java/com/plannaplan/types/GroupTypeTest.java new file mode 100755 index 0000000..7d9a14c --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/types/GroupTypeTest.java @@ -0,0 +1,68 @@ +package com.plannaplan.types; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class GroupTypeTest { + @Test + public void shouldBeLecture() { + assertTrue(GroupType.isLectureOrClass(GroupType.LECTURE) == GroupType.LECTURE); + } + + @Test + public void shouldBeClass1() { + assertTrue(GroupType.isLectureOrClass(GroupType.CLASS) == GroupType.CLASS); + } + + @Test + public void shouldBeClass2() { + assertTrue(GroupType.isLectureOrClass(GroupType.CONSERVATORY) == GroupType.CLASS); + } + + @Test + public void shouldBeClass3() { + assertTrue(GroupType.isLectureOrClass(GroupType.LAB) == GroupType.CLASS); + } + + @Test + public void shouldBeClass4() { + assertTrue(GroupType.isLectureOrClass(GroupType.PRATICE) == GroupType.CLASS); + } + + @Test + public void shouldBeClass5() { + assertTrue(GroupType.isLectureOrClass(GroupType.SEMINAR) == GroupType.CLASS); + } + + @Test + public void shouldCastFromString1() { + assertTrue(GroupType.getType("Ćwiczenia") == GroupType.CLASS); + } + + @Test + public void shouldCastFromString2() { + assertTrue(GroupType.getType("Wykład") == GroupType.LECTURE); + } + + @Test + public void shouldCastFromString3() { + assertTrue(GroupType.getType("Laboratorium") == GroupType.LAB); + } + + @Test + public void shouldCastFromString4() { + assertTrue(GroupType.getType("Seminarium") == GroupType.SEMINAR); + } + + @Test + public void shouldCastFromString5() { + assertTrue(GroupType.getType("Konwersatorium") == GroupType.CONSERVATORY); + } + + @Test + public void shouldCastFromString6() { + assertTrue(GroupType.getType("Praktyka") == GroupType.PRATICE); + } + +} diff --git a/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java b/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java index e20a9cc..17a0056 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/CoursesController.java @@ -68,7 +68,7 @@ public class CoursesController { final HashMap ammounts = this.groupService.getTakenPlaces(course.getGroups()); course.getGroups().stream().forEach(group -> { - if (group.getType() == GroupType.CLASS) { + if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) { classes.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId()))); } else { lectures.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId()))); diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java index 5302068..1434b65 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/AssignmentResponseMappers.java @@ -57,10 +57,10 @@ public class AssignmentResponseMappers { } } if (courseGroups.size() == 2) { - final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst() - .get(); - final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst() - .get(); + final Groups lecture = courseGroups.stream() + .filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.LECTURE).findFirst().get(); + final Groups classes = courseGroups.stream() + .filter(o -> GroupType.isLectureOrClass(o.getType()) == GroupType.CLASS).findFirst().get(); if (ammounts != null) { response.add(new AssignmentResponse(course, lecture, classes, ammounts)); diff --git a/restservice/src/main/java/com/plannaplan/responses/mappers/GroupsMappers.java b/restservice/src/main/java/com/plannaplan/responses/mappers/GroupsMappers.java index ddabacd..aa225e1 100755 --- a/restservice/src/main/java/com/plannaplan/responses/mappers/GroupsMappers.java +++ b/restservice/src/main/java/com/plannaplan/responses/mappers/GroupsMappers.java @@ -83,7 +83,7 @@ public class GroupsMappers { List classes = new ArrayList<>(); groups.stream().forEach(group -> { - if (group.getType() == GroupType.CLASS) { + if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) { if (taken != null) { classes.add(new GroupDefaultResponse(group, taken.get(group.getId()))); } else { @@ -122,7 +122,7 @@ public class GroupsMappers { List classes = new ArrayList<>(); groups.stream().forEach(group -> { - if (group.getType() == GroupType.CLASS) { + if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) { if (taken != null) { classes.add(new GroupWithCapacityResponse(group, taken.get(group.getId()))); } else { diff --git a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java index 75a4269..04078da 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/AssignmentResponse.java @@ -50,8 +50,8 @@ public class AssignmentResponse { * @param group class/lecture entity */ public AssignmentResponse(Course course, Groups group) { - this(course, group.getType() == GroupType.LECTURE ? group : null, - group.getType() == GroupType.CLASS ? group : null); + this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null, + GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null); } /** @@ -61,8 +61,8 @@ public class AssignmentResponse { * places */ public AssignmentResponse(Course course, Groups group, HashMap ammounts) { - this(course, group.getType() == GroupType.LECTURE ? group : null, - group.getType() == GroupType.CLASS ? group : null, ammounts); + this(course, GroupType.isLectureOrClass(group.getType()) == GroupType.LECTURE ? group : null, + GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS ? group : null, ammounts); } /** diff --git a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java index cf5eb17..8ef8c7e 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/CoursesWithGroupsResponse.java @@ -30,7 +30,7 @@ public class CoursesWithGroupsResponse extends CoursesResponse { public CoursesWithGroupsResponse(Course course) { super(course); course.getGroups().stream().forEach(group -> { - if (group.getType() == GroupType.CLASS) { + if (GroupType.isLectureOrClass(group.getType()) == GroupType.CLASS) { this.classes.add(new GroupWithCapacityResponse(group)); } else { this.lectures.add(new GroupWithCapacityResponse(group)); From d217536f2cc8db031268fbb303a8d5bfa41e9763 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 11:33:14 +0100 Subject: [PATCH 3/8] Tours endpoint --- .../controllers/ConfigController.java | 14 ++++ .../responses/models/ConfigTourResponse.java | 26 +++++++ .../controllers/ConfigControllerTest.java | 76 +++++++++++++------ 3 files changed, 92 insertions(+), 24 deletions(-) create mode 100755 restservice/src/main/java/com/plannaplan/responses/models/ConfigTourResponse.java diff --git a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java index b4769df..59a5bdd 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java @@ -10,6 +10,7 @@ import com.plannaplan.App; import com.plannaplan.entities.User; import com.plannaplan.models.ConfigData; import com.plannaplan.models.TourData; +import com.plannaplan.responses.models.ConfigTourResponse; import com.plannaplan.security.cas.CasUserIdentity; import com.plannaplan.security.cas.CasValidationExcepiton; import com.plannaplan.security.cas.CasValidator; @@ -34,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.springframework.web.bind.annotation.GetMapping; /** * Rest controller to Config related endpoints. More detailed api docs is @@ -167,4 +169,16 @@ public class ConfigController { return new ResponseEntity<>("Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR); } } + + /** + * @return api response entity + */ + @GetMapping(path = "/admin/tour") + @PreAuthorize("hasRole('ROLE_ADMIN')") + @ApiOperation("It will return what tour is currently on. You need to provide admin token.") + public ResponseEntity getTourDate() { + final ConfigTourResponse response = new ConfigTourResponse(this.contrl.getCurrentConfig().getCurrentState()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } \ No newline at end of file diff --git a/restservice/src/main/java/com/plannaplan/responses/models/ConfigTourResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/ConfigTourResponse.java new file mode 100755 index 0000000..78d97b4 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/responses/models/ConfigTourResponse.java @@ -0,0 +1,26 @@ +package com.plannaplan.responses.models; + +import com.plannaplan.types.AppState; + +/** + * Api response for config tours entpoint + */ +public class ConfigTourResponse { + + private String currentTour; + + /** + * @param appState to send as a response + */ + public ConfigTourResponse(AppState appState) { + this.currentTour = appState.toString(); + } + + /** + * @return current app state as string + */ + public String getCurrentTour() { + return currentTour; + } + +} diff --git a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java index 44275c9..c437a22 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/ConfigControllerTest.java @@ -40,6 +40,7 @@ public class ConfigControllerTest extends AbstractControllerTest { 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 TOUR_GET_ENDPOINT = "/api/v1/configurator/admin/tour"; private static final String FIRST_TOUR_START = "firstTourBegin"; private static final String FIRST_TOUR_END = "firstTourEnd"; private static final String SECOND_TOUR_START = "secondTourBegin"; @@ -230,19 +231,19 @@ public class ConfigControllerTest extends AbstractControllerTest { @Test @Ignore @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) - public void shouldCreateAdminBecouseOfEmptyDatabase() throws Exception{ + public void shouldCreateAdminBecouseOfEmptyDatabase() throws Exception { // have no idea how to make this test independent from user that run this final String ticket = ""; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); - mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk()); + mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk()); } @Test - public void shouldFailDueToExistingAdmin() throws Exception{ + public void shouldFailDueToExistingAdmin() throws Exception { this.service.save(new User(null, null, "shouldFailDueToExistingAdmin@ConfigController.Test", UserRoles.ADMIN)); final String ticket = "hfewlhfjlewhipfqwehipqwef"; MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); - mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError()); + mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError()); } @Test @@ -282,10 +283,9 @@ public class ConfigControllerTest extends AbstractControllerTest { 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()); + 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 @@ -295,10 +295,9 @@ public class ConfigControllerTest extends AbstractControllerTest { 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()); + 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()); } @@ -309,10 +308,9 @@ public class ConfigControllerTest extends AbstractControllerTest { 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()); + 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()); } @@ -323,10 +321,9 @@ public class ConfigControllerTest extends AbstractControllerTest { 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()); + 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()); } @@ -337,10 +334,41 @@ public class ConfigControllerTest extends AbstractControllerTest { 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)) + 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()); + + } + + @Test + public void shouldReturnOKAuthorizedForGetTours() throws Exception { + final String mail = "shouldReturnOKAuthorizedForGetTours@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(get(TOUR_GET_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + + } + + @Test + public void shouldDenyForGetTours() throws Exception { + final String mail = "shouldDenyForGetTours@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(get(TOUR_GET_ENDPOINT).header("Authorization", "Bearer " + token)) .andExpect(status().is4xxClientError()); - } + } + + @Test + public void shouldDenyWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(TOUR_GET_ENDPOINT)).andExpect(status().is4xxClientError()); + + } } \ No newline at end of file From 7b9e334328335bd174705a4fe6d7c5a8a19dcb92 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 11:35:47 +0100 Subject: [PATCH 4/8] Group response downgrade --- .../com/plannaplan/responses/models/GroupDefaultResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java index 3e16109..5dce6da 100755 --- a/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java +++ b/restservice/src/main/java/com/plannaplan/responses/models/GroupDefaultResponse.java @@ -51,7 +51,7 @@ public class GroupDefaultResponse { this.endTime = group.getEndTimeString() != null ? group.getEndTimeString() : ""; this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : ""; this.room = group.getRoom() != null ? group.getRoom() : ""; - this.type = group.getType() != null ? group.getType() : null; + this.type = group.getType() != null ? GroupType.isLectureOrClass(group.getType()) : null; } /** From 7f647f9b8af2b169fcccd1720f8ab087707d860c Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 12:05:31 +0100 Subject: [PATCH 5/8] Added call perform algorythm enpoint --- .../java/com/plannaplan/types/UserRoles.java | 6 +- .../controllers/DeveloperController.java | 39 ++++++++++++ .../plannaplan/security/AuthorityRoles.java | 5 +- .../controllers/DeveloperControllerTest.java | 60 +++++++++++++++++++ 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100755 restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java create mode 100755 restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java b/buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java index 402bc2d..e3a7ff6 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java +++ b/buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java @@ -1,9 +1,9 @@ package com.plannaplan.types; /** - * UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER + * UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER */ - + public enum UserRoles { - STUDENT, DEANERY, ADMIN, TEST_USER + STUDENT, DEANERY, ADMIN, TEST_USER, DEVELOPER } \ No newline at end of file diff --git a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java new file mode 100755 index 0000000..cced224 --- /dev/null +++ b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java @@ -0,0 +1,39 @@ +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.PostMapping; +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.services.AssignmentService; + +/** + * Rest controller to enpoint that help deveopler test the app + */ +@RestController +@CrossOrigin +@RequestMapping("/api/" + App.API_VERSION + "/developer") +@Api(tags = { + "DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing") +public class DeveloperController { + + @Autowired + private AssignmentService assignmentService; + + /** + * @return if accept algoythm was perfomed + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/algoythm/accept") + public ResponseEntity performAcceptAlgorythm() { + this.assignmentService.callAcceptAlgorythm(); + return new ResponseEntity<>("Success", HttpStatus.OK); + } +} diff --git a/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java b/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java index ead5811..8ea4849 100755 --- a/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java +++ b/restservice/src/main/java/com/plannaplan/security/AuthorityRoles.java @@ -10,7 +10,8 @@ import org.springframework.security.core.GrantedAuthority; * Users Roles for spring app */ public enum AuthorityRoles implements GrantedAuthority { - STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER"); + STUDENT("ROLE_STUDENT"), DEANERY("ROLE_DEANERY"), ADMIN("ROLE_ADMIN"), TEST_USER("ROLE_TESTUSER"), + DEVELOPER("ROLE_DEVELOPER"); private String role; @@ -39,6 +40,8 @@ public enum AuthorityRoles implements GrantedAuthority { return Optional.of(AuthorityRoles.STUDENT); case TEST_USER: return Optional.of(AuthorityRoles.TEST_USER); + case DEVELOPER: + return Optional.of(AuthorityRoles.DEVELOPER); default: return Optional.empty(); } diff --git a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java new file mode 100755 index 0000000..e47527e --- /dev/null +++ b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java @@ -0,0 +1,60 @@ +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.post; +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 DeveloperControllerTest extends AbstractControllerTest { + private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algoythm/accept"; + + @Autowired + private UserService userService; + + @Test + public void shouldFailWithWrongAcces() throws Exception { + final String mail = "shouldFailWithWrongAcces@ConfigController.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(post(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkPerformingAcceptAlgotyrhm() throws Exception { + final String mail = "shouldOkPerformingAcceptAlgotyrhm@ConfigController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(ACCEPT_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + + } + + @Test + public void shouldFailWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(ACCEPT_ENDPOINT)).andExpect(status().is4xxClientError()); + + } +} From d1a54a93d6de28a85dcc4c8780556bf96d456c7a Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 12:13:26 +0100 Subject: [PATCH 6/8] Developer exchange endpoint --- .../controllers/DeveloperController.java | 16 +++++++- .../controllers/DeveloperControllerTest.java | 40 +++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java index cced224..1f7535d 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java @@ -13,6 +13,7 @@ import io.swagger.annotations.Api; import com.plannaplan.App; import com.plannaplan.services.AssignmentService; +import com.plannaplan.services.ExchangeService; /** * Rest controller to enpoint that help deveopler test the app @@ -27,13 +28,26 @@ public class DeveloperController { @Autowired private AssignmentService assignmentService; + @Autowired + private ExchangeService exchangeService; + /** * @return if accept algoythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") - @PostMapping(path = "/algoythm/accept") + @PostMapping(path = "/algorythm/accept") public ResponseEntity performAcceptAlgorythm() { this.assignmentService.callAcceptAlgorythm(); return new ResponseEntity<>("Success", HttpStatus.OK); } + + /** + * @return if accept algoythm was perfomed + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/algorythm/exchange") + public ResponseEntity performExchangeAlgorythm() { + this.exchangeService.performExchange(); + return new ResponseEntity<>("Success", HttpStatus.OK); + } } diff --git a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java index e47527e..59deca5 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java @@ -21,14 +21,15 @@ import com.plannaplan.types.UserRoles; @SpringBootTest @ContextConfiguration public class DeveloperControllerTest extends AbstractControllerTest { - private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algoythm/accept"; + private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algorythm/accept"; + private static final String EXCHANGE_ENDPOINT = "/api/v1/developer/algorythm/exchange"; @Autowired private UserService userService; @Test public void shouldFailWithWrongAcces() throws Exception { - final String mail = "shouldFailWithWrongAcces@ConfigController.test"; + final String mail = "shouldFailWithWrongAcces@DeveloperController.test"; final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER)); final String token = this.userService.login(usr).getToken(); @@ -41,7 +42,7 @@ public class DeveloperControllerTest extends AbstractControllerTest { @Test public void shouldOkPerformingAcceptAlgotyrhm() throws Exception { - final String mail = "shouldOkPerformingAcceptAlgotyrhm@ConfigController.test"; + final String mail = "shouldOkPerformingAcceptAlgotyrhm@DeveloperController.test"; final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); final String token = this.userService.login(usr).getToken(); @@ -57,4 +58,37 @@ public class DeveloperControllerTest extends AbstractControllerTest { mockMvc.perform(post(ACCEPT_ENDPOINT)).andExpect(status().is4xxClientError()); } + + @Test + public void shouldFailExchangeWithWrongAcces() throws Exception { + final String mail = "shouldFailExchangeWithWrongAcces@DeveloperController.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(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkExchangeAlgotyrhm() throws Exception { + final String mail = "shouldOkExchangeAlgotyrhm@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(EXCHANGE_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + + } + + @Test + public void shouldFailExchaneWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(EXCHANGE_ENDPOINT)).andExpect(status().is4xxClientError()); + + } + } From 265315b8741ef429b7d0067606a0a23e48831301 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 12:47:14 +0100 Subject: [PATCH 7/8] All developers endpoints --- .../controllers/DeveloperController.java | 54 ++++++++- .../controllers/DeveloperControllerTest.java | 111 ++++++++++++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java index 1f7535d..6f4daa4 100755 --- a/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/DeveloperController.java @@ -11,8 +11,12 @@ import org.springframework.web.bind.annotation.RestController; import io.swagger.annotations.Api; +import java.util.Date; + import com.plannaplan.App; +import com.plannaplan.models.TourData; import com.plannaplan.services.AssignmentService; +import com.plannaplan.services.ConfiguratorService; import com.plannaplan.services.ExchangeService; /** @@ -25,14 +29,19 @@ import com.plannaplan.services.ExchangeService; "DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing") public class DeveloperController { + private static final long ONE_DAY = 86400000; + @Autowired private AssignmentService assignmentService; @Autowired private ExchangeService exchangeService; + @Autowired + private ConfiguratorService configurationController; + /** - * @return if accept algoythm was perfomed + * @return if accept algorythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") @PostMapping(path = "/algorythm/accept") @@ -42,7 +51,7 @@ public class DeveloperController { } /** - * @return if accept algoythm was perfomed + * @return if exchange algorythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") @PostMapping(path = "/algorythm/exchange") @@ -50,4 +59,45 @@ public class DeveloperController { this.exchangeService.performExchange(); return new ResponseEntity<>("Success", HttpStatus.OK); } + + /** + * @return if tour was set + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/tours/first") + public ResponseEntity setFirstTour() { + this.configurationController.saveTours( + new TourData(new Date(System.currentTimeMillis() - ONE_DAY), + new Date(System.currentTimeMillis() + ONE_DAY)), + new TourData(new Date(System.currentTimeMillis() + 2 * ONE_DAY), + new Date(System.currentTimeMillis() + 3 * ONE_DAY))); + return new ResponseEntity<>("Success", HttpStatus.OK); + } + + /** + * @return if tour was set + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/tours/second") + public ResponseEntity setSecondTour() { + this.configurationController.saveTours( + new TourData(new Date(System.currentTimeMillis() - 3 * ONE_DAY), + new Date(System.currentTimeMillis() - 2 * ONE_DAY)), + new TourData(new Date(System.currentTimeMillis() - ONE_DAY), + new Date(System.currentTimeMillis() + ONE_DAY))); + return new ResponseEntity<>("Success", HttpStatus.OK); + } + + /** + * @return if tour was set + */ + @PreAuthorize("hasRole('ROLE_DEVELOPER')") + @PostMapping(path = "/tours/no") + public ResponseEntity setNoTour() { + this.configurationController.saveTours( + new TourData(new Date(System.currentTimeMillis() - ONE_DAY), new Date(System.currentTimeMillis())), + new TourData(new Date(System.currentTimeMillis() + ONE_DAY), + new Date(System.currentTimeMillis() + 2 * ONE_DAY))); + return new ResponseEntity<>("Success", HttpStatus.OK); + } } diff --git a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java index 59deca5..f3ac015 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/DeveloperControllerTest.java @@ -23,10 +23,15 @@ import com.plannaplan.types.UserRoles; public class DeveloperControllerTest extends AbstractControllerTest { private static final String ACCEPT_ENDPOINT = "/api/v1/developer/algorythm/accept"; private static final String EXCHANGE_ENDPOINT = "/api/v1/developer/algorythm/exchange"; + private static final String FIRST_TOUR_ENDPOINT = "/api/v1/developer/tours/first"; + private static final String NO_TOUR_ENDPOINT = "/api/v1/developer/tours/no"; + private static final String SECOND_TOUR_ENDPOINT = "/api/v1/developer/tours/second"; @Autowired private UserService userService; + /* ACCEPT TESTS */ + @Test public void shouldFailWithWrongAcces() throws Exception { final String mail = "shouldFailWithWrongAcces@DeveloperController.test"; @@ -59,6 +64,8 @@ public class DeveloperControllerTest extends AbstractControllerTest { } + /* EXCHANGE TESTS */ + @Test public void shouldFailExchangeWithWrongAcces() throws Exception { final String mail = "shouldFailExchangeWithWrongAcces@DeveloperController.test"; @@ -91,4 +98,108 @@ public class DeveloperControllerTest extends AbstractControllerTest { } + /* FIRST TOUR */ + + @Test + public void shouldFailFirstTourWithWrongAcces() throws Exception { + final String mail = "shouldFailFirstTourWithWrongAcces@DeveloperController.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(post(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkFirstTourAlgotyrhm() throws Exception { + final String mail = "shouldOkFirstTourAlgotyrhm@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(FIRST_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().isOk()); + + } + + @Test + public void shouldFirstTourWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(FIRST_TOUR_ENDPOINT)).andExpect(status().is4xxClientError()); + + } + + /* SECOND TOUR */ + + @Test + public void shouldFailSecondTourWithWrongAcces() throws Exception { + final String mail = "shouldFailSecondTourWithWrongAcces@DeveloperController.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(post(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkSecondTourAlgotyrhm() throws Exception { + final String mail = "shouldOkSecondTourAlgotyrhm@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(SECOND_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().isOk()); + + } + + @Test + public void shouldFailSecondTourWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(SECOND_TOUR_ENDPOINT)).andExpect(status().is4xxClientError()); + + } + + /* NO TOUR */ + + @Test + public void shouldNoTourWithWrongAcces() throws Exception { + final String mail = "shouldNoTourWithWrongAcces@DeveloperController.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(post(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); + + } + + @Test + public void shouldOkNoAlgotyrhm() throws Exception { + final String mail = "shouldOkNoAlgotyrhm@DeveloperController.test"; + final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEVELOPER)); + + final String token = this.userService.login(usr).getToken(); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(NO_TOUR_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + + } + + @Test + public void shouldFailNoTourWithNoToken() throws Exception { + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(NO_TOUR_ENDPOINT)).andExpect(status().is4xxClientError()); + + } + } From 847dd76fc891be016ec60838e6e2df959ccc4cfa Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 19 Jan 2021 12:55:58 +0100 Subject: [PATCH 8/8] test fix --- .../src/main/java/com/plannaplan/entities/User.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java index d14411f..8758a24 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/User.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/User.java @@ -48,8 +48,9 @@ public class User { } public void removeGroup(Long id) { - final Groups groupToDelete = this.studentRegisteredGrups.stream().filter(e -> e.getId().equals(id)).findFirst().get(); - this.studentRegisteredGrups.remove(groupToDelete); + final Groups groupToDelete = this.studentRegisteredGrups.stream().filter(e -> e.getId().equals(id)).findFirst() + .get(); + this.studentRegisteredGrups.remove(groupToDelete); } public void claimGroup(Groups group) { @@ -236,6 +237,9 @@ public class User { * @return ranking points [100;500] */ public Integer getRanking() { + if (ranking == null) { + return 100; + } return ranking; }