From 881d5c09181703498f989c38c832e1f9584fdfcf Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 25 Apr 2024 18:02:36 +0200 Subject: [PATCH 01/10] adding course year to backend --- .../com/ugent/pidgeon/model/json/CourseJson.java | 13 ++++++++++++- .../pidgeon/postgre/models/CourseEntity.java | 16 ++++++++++++++++ .../com/ugent/pidgeon/util/CourseUtilTest.java | 2 +- backend/database/populate_database.sql | 12 ++++++------ backend/database/start_database.sql | 1 + 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java index d9e99c49..8352158b 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java @@ -8,10 +8,13 @@ public class CourseJson{ private Boolean isArchived; - public CourseJson(String name, String description, Boolean isArchived) { + private int courseYear; + + public CourseJson(String name, String description, Boolean isArchived, int courseYear) { this.name = name; this.description = description; this.isArchived = isArchived; + this.courseYear = courseYear; } public String getName() { @@ -37,5 +40,13 @@ public Boolean getArchived() { public void setArchived(Boolean isArchived) { this.isArchived = isArchived; } + + public int getCourseYear() { + return courseYear; + } + + public void setCourseYear(int courseYear) { + this.courseYear = courseYear; + } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index 5ae72f32..55b0b414 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -1,6 +1,7 @@ package com.ugent.pidgeon.postgre.models; import jakarta.persistence.*; +import jakarta.persistence.criteria.CriteriaBuilder; import java.time.OffsetDateTime; @@ -18,6 +19,10 @@ public class CourseEntity { @Column(name = "description", nullable=false) private String description; + @Column(name = "course_year", nullable = true) + private int courseYear; + + @Column(name = "created_at") private OffsetDateTime createdAt; @@ -71,6 +76,7 @@ public void setDescription(String description) { } + public OffsetDateTime getCreatedAt() { return createdAt; } @@ -86,4 +92,14 @@ public OffsetDateTime getArchivedAt() { public void setArchivedAt(OffsetDateTime archivedAt) { this.archivedAt = archivedAt; } + + public int getCourseYear() { + return courseYear; + } + public void setCourseYear(int courseYear){ + this.courseYear = courseYear; + } + + + } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java index c25c31f1..c6895598 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java @@ -141,7 +141,7 @@ public void testCheckJoinLink() throws Exception { @Test public void testCheckCourseJson() throws Exception { - CourseJson courseJson = new CourseJson("name", "description", null); + CourseJson courseJson = new CourseJson("name", "description", null,2023); CheckResult result = courseUtil.checkCourseJson(courseJson, user, null); assertEquals(HttpStatus.OK, result.getStatus()); diff --git a/backend/database/populate_database.sql b/backend/database/populate_database.sql index 28ff6cd6..ce61ab00 100644 --- a/backend/database/populate_database.sql +++ b/backend/database/populate_database.sql @@ -10,12 +10,12 @@ INSERT INTO users (name, surname, email, azure_id, role) VALUES ('Charlie', 'Davis', 'charlie.davis@example.com', 'token_5', 'teacher'); -- Inserting into `courses` -INSERT INTO courses (course_id,course_name, description) VALUES - (1,'Math 101', 'Introduction to Mathematics'), - (2,'Science 101', 'Basics of Scientific Method'), - (3,'History 101', 'World History Overview'), - (4,'Computer Science 101', 'Introduction to Computing'), - (5,'English 101', 'English Literature'); +INSERT INTO courses (course_id,course_name, description, coures_year) VALUES + (1,'Math 101', 'Introduction to Mathematics',2023), + (2,'Science 101', 'Basics of Scientific Method',2023), + (3,'History 101', 'World History Overview',2023), + (4,'Computer Science 101', 'Introduction to Computing',2023), + (5,'English 101', 'English Literature',2023); -- Inserting into `course_users` -- Assume course_id and user_id start from 1 and match accordingly diff --git a/backend/database/start_database.sql b/backend/database/start_database.sql index 80a9b0a5..7ebee241 100644 --- a/backend/database/start_database.sql +++ b/backend/database/start_database.sql @@ -17,6 +17,7 @@ CREATE TABLE courses ( course_id SERIAL PRIMARY KEY, course_name VARCHAR(100) NOT NULL, description TEXT, + integer coure_year, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, archived_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, join_key TEXT From 5317c3dab42d7e176e9813a8817c68d66f4da777 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Thu, 25 Apr 2024 18:06:35 +0200 Subject: [PATCH 02/10] switcheroo --- backend/database/start_database.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/database/start_database.sql b/backend/database/start_database.sql index 7ebee241..1e076839 100644 --- a/backend/database/start_database.sql +++ b/backend/database/start_database.sql @@ -17,7 +17,7 @@ CREATE TABLE courses ( course_id SERIAL PRIMARY KEY, course_name VARCHAR(100) NOT NULL, description TEXT, - integer coure_year, + course_year INTEGER, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, archived_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, join_key TEXT From a2aa9546023a94a531f53504b76ae11c957331f8 Mon Sep 17 00:00:00 2001 From: Arne Dierick Date: Fri, 26 Apr 2024 00:34:08 +0200 Subject: [PATCH 03/10] Fixed db-breaking typo in populate_database.sql and removed duplicate import --- .../java/com/ugent/pidgeon/postgre/models/CourseEntity.java | 1 - backend/database/populate_database.sql | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index 55b0b414..31f40da0 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -1,7 +1,6 @@ package com.ugent.pidgeon.postgre.models; import jakarta.persistence.*; -import jakarta.persistence.criteria.CriteriaBuilder; import java.time.OffsetDateTime; diff --git a/backend/database/populate_database.sql b/backend/database/populate_database.sql index ce61ab00..9adfb6e0 100644 --- a/backend/database/populate_database.sql +++ b/backend/database/populate_database.sql @@ -10,7 +10,7 @@ INSERT INTO users (name, surname, email, azure_id, role) VALUES ('Charlie', 'Davis', 'charlie.davis@example.com', 'token_5', 'teacher'); -- Inserting into `courses` -INSERT INTO courses (course_id,course_name, description, coures_year) VALUES +INSERT INTO courses (course_id,course_name, description, course_year) VALUES (1,'Math 101', 'Introduction to Mathematics',2023), (2,'Science 101', 'Basics of Scientific Method',2023), (3,'History 101', 'World History Overview',2023), From 7d609e395c8a4ec2f50feb25a95439a75e9ce570 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 26 Apr 2024 01:59:34 +0200 Subject: [PATCH 04/10] adding course years --- .../pidgeon/controllers/CourseController.java | 51 ++++++++++--------- .../ugent/pidgeon/model/json/CourseJson.java | 8 +-- .../pidgeon/postgre/models/CourseEntity.java | 3 +- .../com/ugent/pidgeon/util/CourseUtil.java | 4 +- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java index 6d1b4250..966dc29e 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java @@ -56,7 +56,7 @@ public class CourseController { */ @GetMapping(ApiRoutes.COURSE_BASE_PATH) @Roles({UserRole.teacher, UserRole.student}) - public ResponseEntity getUserCourses(Auth auth, @RequestParam(value="archived", required = false) Boolean archived) { + public ResponseEntity getUserCourses(Auth auth, @RequestParam(value = "archived", required = false) Boolean archived) { long userID = auth.getUserEntity().getId(); try { Logger.getGlobal().info("Archived: " + archived); @@ -111,7 +111,7 @@ public ResponseEntity createCourse(@RequestBody CourseJson courseJson, Auth a } // Create new course - CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription()); + CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription(), courseJson.getCourseYear()); // Get current time and convert to SQL Timestamp OffsetDateTime currentTimestamp = OffsetDateTime.now(); courseEntity.setCreatedAt(currentTimestamp); @@ -142,6 +142,7 @@ private ResponseEntity doCourseUpdate(CourseEntity courseEntity, CourseJson c } courseEntity.setName(courseJson.getName()); courseEntity.setDescription(courseJson.getDescription()); + courseEntity.setCourseYear(courseJson.getCourseYear()); if (courseJson.getArchived() != null) { courseEntity.setArchivedAt(courseJson.getArchived() ? OffsetDateTime.now() : null); } @@ -190,7 +191,7 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage()); } - if (courseJson.getName() == null && courseJson.getDescription() == null) { + if (courseJson.getName() == null && courseJson.getDescription() == null && courseJson.getCourseYear() == null) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name or description is required"); } @@ -201,6 +202,9 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa if (courseJson.getDescription() == null) { courseJson.setDescription(courseEntity.getDescription()); } + if (courseJson.getCourseYear() == null) { + courseJson.setCourseYear(courseEntity.getCourseYear()); + } return doCourseUpdate(courseEntity, courseJson, user); } catch (Exception e) { @@ -233,7 +237,6 @@ public ResponseEntity getCourseByCourseId(@PathVariable long courseId, Auth a } - /** * Function to delete a course by its ID * @@ -318,7 +321,7 @@ public ResponseEntity getProjectsByCourseId(@PathVariable Long courseId, Auth if (relation.equals(CourseRelation.enrolled)) { projects = projects.stream().filter(ProjectEntity::isVisible).toList(); } - List projectResponseJsons = projects.stream().map(projectEntity -> + List projectResponseJsons = projects.stream().map(projectEntity -> entityToJsonConverter.projectEntityToProjectResponseJson(projectEntity, course, user) ).toList(); @@ -339,7 +342,7 @@ private ResponseEntity getJoinLinkPostResponseEntity(long courseId, String co return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to add user to individual group, contact admin."); } courseUserRepository.save(new CourseUserEntity(courseId, user.getId(), CourseRelation.enrolled)); - return ResponseEntity.ok(entityToJsonConverter.courseEntityToCourseWithInfo(course, courseUtil.getJoinLink(course.getJoinKey(),"" + course.getId()), false)); + return ResponseEntity.ok(entityToJsonConverter.courseEntityToCourseWithInfo(course, courseUtil.getJoinLink(course.getJoinKey(), "" + course.getId()), false)); } private ResponseEntity getJoinLinkGetResponseEntity(long courseId, String courseKey, UserEntity user) { @@ -359,8 +362,8 @@ private ResponseEntity getJoinLinkGetResponseEntity(long courseId, String cou /** * Function to join course with key * - * @param auth authentication object of the requesting user - * @param courseId ID of the course to join + * @param auth authentication object of the requesting user + * @param courseId ID of the course to join * @param courseKey key of the course to join * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation @@ -377,8 +380,8 @@ public ResponseEntity joinCourse(Auth auth, @PathVariable Long courseId, @Pat /** * Function to get course information for joining course with key * - * @param auth authentication object of the requesting user - * @param courseId ID of the course to get the join key from + * @param auth authentication object of the requesting user + * @param courseId ID of the course to get the join key from * @param courseKey key of the course to get the join key from * @return ResponseEntity with a statuscode and a JSON object containing the course information * @ApiDog apiDog documentation @@ -395,7 +398,7 @@ public ResponseEntity getCourseJoinKey(Auth auth, @PathVariable Long courseId /** * Function to join course without key * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to join * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation @@ -412,7 +415,7 @@ public ResponseEntity joinCourse(Auth auth, @PathVariable Long courseId) { /** * Function to get course information for joining course without key * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the join key from * @return ResponseEntity with a statuscode and a JSON object containing the course information * @ApiDog apiDog documentation @@ -430,7 +433,7 @@ public ResponseEntity getCourseJoinKey(Auth auth, @PathVariable Long courseId * Function to leave a course * * @param courseId ID of the course to leave - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod DELETE @@ -465,9 +468,9 @@ public ResponseEntity leaveCourse(@PathVariable long courseId, Auth auth) { /** * Function to remove a different user from a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to leave - * @param userId JSON object containing the user id + * @param userId JSON object containing the user id * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod DELETE @@ -495,9 +498,9 @@ public ResponseEntity removeCourseMember(Auth auth, @PathVariable Long course /** * Function to add a different user to a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to add the user to - * @param request JSON object containing the user id and relation + * @param request JSON object containing the user id and relation * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod POST @@ -530,9 +533,9 @@ public ResponseEntity addCourseMember(Auth auth, @PathVariable Long courseId, /** * Function to update the relation of a user in a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to update the user in - * @param request JSON object containing the user id and relation + * @param request JSON object containing the user id and relation * @return ResponseEntity with a statuscode and no body * @ApiDog apiDog documentation * @HttpMethod PATCH @@ -570,7 +573,7 @@ public ResponseEntity updateCourseMember(Auth auth, @PathVariable Long course /** * Function to get all members of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the members from * @return ResponseEntity with a JSON object containing the members of the course * @ApiDog apiDog documentation @@ -603,7 +606,7 @@ public ResponseEntity getCourseMembers(Auth auth, @PathVariable Long courseId /** * Function to get the join link of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to get the join link from * @return ResponseEntity with the join link of the course * @ApiDog apiDog documentation @@ -622,10 +625,11 @@ public ResponseEntity getCourseKey(Auth auth, @PathVariable Long courseI } // Function for invalidating the previous key and generating a new one, can be useful when starting a new year. + /** * Function to generate a new join link for a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to generate the join link for * @return ResponseEntity with the new join link of the course * @ApiDog apiDog documentation @@ -651,7 +655,7 @@ public ResponseEntity getAndGenerateCourseKey(Auth auth, @PathVariable Long c /** * Function to remove the joinKey from the joinLink of a course * - * @param auth authentication object of the requesting user + * @param auth authentication object of the requesting user * @param courseId ID of the course to remove the join link from * @return ResponseEntity with the new join link of the course (without the key) * @ApiDog apiDog documentation @@ -672,4 +676,5 @@ public ResponseEntity deleteCourseKey(Auth auth, @PathVariable Long cour return ResponseEntity.ok(""); } + } \ No newline at end of file diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java index 8352158b..61b8806e 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java @@ -8,9 +8,9 @@ public class CourseJson{ private Boolean isArchived; - private int courseYear; + private Integer courseYear; - public CourseJson(String name, String description, Boolean isArchived, int courseYear) { + public CourseJson(String name, String description, Boolean isArchived, Integer courseYear) { this.name = name; this.description = description; this.isArchived = isArchived; @@ -41,11 +41,11 @@ public void setArchived(Boolean isArchived) { this.isArchived = isArchived; } - public int getCourseYear() { + public Integer getCourseYear() { return courseYear; } - public void setCourseYear(int courseYear) { + public void setCourseYear(Integer courseYear) { this.courseYear = courseYear; } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index 31f40da0..93a246e9 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -39,9 +39,10 @@ public void setJoinKey(String joinKey) { @Column(name = "join_key", nullable=true) private String joinKey; - public CourseEntity(String name, String description) { + public CourseEntity(String name, String description,Integer courseYear) { this.name = name; this.description = description; + this.courseYear = courseYear; } public CourseEntity() { diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java index 5ee912f2..bda7a51d 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java @@ -260,8 +260,8 @@ public CheckResult checkCourseJson(CourseJson courseJson, UserEntity user, } - if (courseJson.getName() == null || courseJson.getDescription() == null) { - return new CheckResult<>(HttpStatus.BAD_REQUEST, "name and description are required", null); + if (courseJson.getName() == null || courseJson.getDescription() == null || courseJson.getCourseYear() == null) { + return new CheckResult<>(HttpStatus.BAD_REQUEST, "name, description and year are required", null); } if (courseJson.getName().isBlank()) { From 746bbaa7a6ff7e8f7840ea93ac4356a3ed258277 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 26 Apr 2024 11:52:37 +0200 Subject: [PATCH 05/10] adding course year --- .../controllers/ClusterControllerTest.java | 2 +- .../controllers/CourseControllerTest.java | 22 +- .../model/DockerSubmissionTestTest.java | 222 +++++++++--------- .../postgre/models/CourseEntityTest.java | 2 +- .../ugent/pidgeon/util/CourseUtilTest.java | 4 +- 5 files changed, 126 insertions(+), 126 deletions(-) diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java index 90182e61..24446585 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/ClusterControllerTest.java @@ -63,7 +63,7 @@ public void setup() { })) .build(); - courseEntity = new CourseEntity("name", "description"); + courseEntity = new CourseEntity("name", "description",2024); groupClusterEntity = new GroupClusterEntity(1L, 20, "clustername", 5); groupEntity = new GroupEntity("groupName", 1L); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java index b2783174..06ac705e 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java @@ -112,7 +112,7 @@ public String getName() { @Test public void testCreateCourse() throws Exception { - String courseJson = "{\"name\": \"test\", \"description\": \"description\"}"; + String courseJson = "{\"name\": \"test\", \"description\": \"description\",\"courseYear\" : 2024}"; when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); when(courseRepository.save(any())).thenReturn(null); when(courseUserRepository.save(any())).thenReturn(null); @@ -144,7 +144,7 @@ public void testCreateCourse() throws Exception { // This function also tests all lines of doCourseUpdate @Test public void testUpdateCourse() throws Exception { - String courseJson = "{\"name\": \"test\", \"description\": \"description\"}"; + String courseJson = "{\"name\": \"test\", \"description\": \"description\",\"courseYear\" : 2024}"; when(courseUtil.getCourseIfAdmin(anyLong(), any())). thenReturn(new CheckResult<>(HttpStatus.OK, "", new CourseEntity())); when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); @@ -270,7 +270,7 @@ public void testDeleteCourse() throws Exception { @Test public void testGetProjectsByCourseId() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); List projects = Arrays.asList(new ProjectEntity(), new ProjectEntity()); when(courseUtil.getCourseIfUserInCourse(anyLong(), any())) @@ -300,7 +300,7 @@ public void testGetProjectsByCourseId() throws Exception { @Test public void testJoinCourse() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); when(commonDatabaseActions.createNewIndividualClusterGroup(anyLong(), any())).thenReturn(true); @@ -319,7 +319,7 @@ public void testJoinCourse() throws Exception { @Test public void testGetJoinKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/join/1908")) @@ -332,7 +332,7 @@ public void testGetJoinKey() throws Exception { @Test public void testJoinCourseNoKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); when(commonDatabaseActions.createNewIndividualClusterGroup(anyLong(), any())).thenReturn(true); @@ -346,7 +346,7 @@ public void testJoinCourseNoKey() throws Exception { @Test public void testGetCourseJoinKeyNoKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.checkJoinLink(anyLong(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/join")) @@ -454,7 +454,7 @@ public void testUpdateCourseMember() throws Exception { @Test public void testGetCourseMembers() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfUserInCourse(anyLong(), any())). thenReturn(new CheckResult<>(HttpStatus.OK, "", new Pair<>(course, CourseRelation.course_admin))); @@ -472,7 +472,7 @@ public void testGetCourseMembers() throws Exception { @Test public void testGetCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) @@ -485,7 +485,7 @@ public void testGetCourseKey() throws Exception { @Test public void testGetAndCreateCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.put(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) @@ -498,7 +498,7 @@ public void testGetAndCreateCourseKey() throws Exception { @Test public void testDeleteCourseKey() throws Exception { - CourseEntity course = new CourseEntity("name", "descripton"); + CourseEntity course = new CourseEntity("name", "descripton",2024); course.setId(1); when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", course)); mockMvc.perform(MockMvcRequestBuilders.delete(ApiRoutes.COURSE_BASE_PATH + "/1/joinKey")) diff --git a/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java b/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java index 3a6dd5ee..97c89e12 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java @@ -15,117 +15,117 @@ public class DockerSubmissionTestTest { -// File initTestFile(String text, String fileName) { -// String localFileLocation = System.getProperty("user.dir") + "/tmp/test/" + fileName; -// File file = new File(localFileLocation); -// try { -// file.getParentFile().mkdirs(); -// file.createNewFile(); -// FileUtils.writeStringToFile(file, text, "UTF-8"); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return file; -// } -// -// // Check if we can catch the console output of a script. -// @Test -// void scriptSucceeds() throws InterruptedException { -// DockerSubmissionTestModel.addDocker("fedora:latest"); -// // Load docker container -// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); -// // Run script -// DockerTestOutput to = stm.runSubmission("echo 'PUSH ALLOWED' > /shared//output/testOutput"); -// assertTrue(to.allowed); -// } -// -// @Test -// void scriptFails() throws InterruptedException { -// //make sure docker image is installed -// DockerSubmissionTestModel.addDocker("fedora:latest"); -// // Load docker container -// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); -// // Run script -// // Example for running a bash script correctly -// DockerTestOutput to = stm.runSubmission("echo 'PUSH DENIED' > /shared/output/testOutput"); -// assertFalse(to.allowed); -// } -// -// @Test -// void catchesConsoleLogs() throws InterruptedException { -// DockerSubmissionTestModel.addDocker("alpine:latest"); -// // Load docker container -// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); -// // Run script -// // Example for running a bash script correctly -// DockerTestOutput to = stm.runSubmission("echo 'Woopdie Woop Scoop! ~ KW'; echo 'PUSH ALLOWED' > /shared/output/testOutput"); -// -// assertTrue(to.allowed); -// assertEquals(to.logs.get(0), "Woopdie Woop Scoop! ~ KW\n"); -// } -// -// @Test -// void correctlyReceivesInputFiles() throws InterruptedException { -// DockerSubmissionTestModel.addDocker("alpine:latest"); -// // Load docker container -// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); -// -// // Create an input file in tmp/test/input -// File file = initTestFile("This is a test input file\n", "testInput"); -// -// // Run script -// // Example for running a bash script correctly -// DockerTestOutput to = stm.runSubmission("cat /shared/input/testInput; echo PUSH ALLOWED > /shared/output/testOutput", new File[]{file}); -// assertEquals(to.logs.get(0), "This is a test input file\n"); -// } -// -// @Test -// void templateTest() throws InterruptedException { -// String testOne = "@HelloWorld\n" + -// ">Description=\"Test for hello world!\"\n" + -// ">Required\n" + -// "HelloWorld!"; -// String testTwo = "@HelloWorld2\n" + -// ">Optional\n" + -// "HelloWorld2!\n"; -// String template = testOne + "\n" + testTwo; -// -// File[] files = new File[]{initTestFile("#!/bin/sh\necho 'HelloWorld!'", "HelloWorld.sh"), -// initTestFile("#!/bin/sh\necho 'HelloWorld2!'", "HelloWorld2.sh")}; -// -// String script = -// "chmod +x /shared/input/HelloWorld.sh;" + -// "chmod +x /shared/input/HelloWorld2.sh;" + -// "/shared/input/HelloWorld.sh > /shared/output/HelloWorld;" + -// "/shared/input/HelloWorld2.sh > /shared/output/HelloWorld2"; -// -// DockerSubmissionTestModel.addDocker("alpine:latest"); -// // Load docker container -// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); -// DockerTemplateTestResult result = stm.runSubmissionWithTemplate(script, template, files); -// -// // Extract subtests -// List results = result.getSubtestResults(); -// -// // Testing for the template parser capabilities -// assertEquals(results.size(), 2); -// -// assertTrue(results.get(0).isRequired()); -// assertFalse(results.get(1).isRequired()); -// -// assertEquals(results.get(0).getCorrect(), "HelloWorld!\n"); -// assertEquals(results.get(1).getCorrect(), "HelloWorld2!\n"); -// -// assertEquals(results.get(0).getTestDescription(), "Test for hello world!"); -// assertEquals(results.get(1).getTestDescription(), ""); -// -// // Test the docker output -// assertEquals(results.get(0).getOutput(), "HelloWorld!\n"); -// assertEquals(results.get(1).getOutput(), "HelloWorld2!\n"); -// -// assertTrue(result.isAllowed()); -// -// } + File initTestFile(String text, String fileName) { + String localFileLocation = System.getProperty("user.dir") + "/tmp/test/" + fileName; + File file = new File(localFileLocation); + try { + file.getParentFile().mkdirs(); + file.createNewFile(); + FileUtils.writeStringToFile(file, text, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } + return file; + } + + // Check if we can catch the console output of a script. + @Test + void scriptSucceeds() throws InterruptedException { + DockerSubmissionTestModel.addDocker("fedora:latest"); + // Load docker container + DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); + // Run script + DockerTestOutput to = stm.runSubmission("echo 'PUSH ALLOWED' > /shared//output/testOutput"); + assertTrue(to.allowed); + } + + @Test + void scriptFails() throws InterruptedException { + //make sure docker image is installed + DockerSubmissionTestModel.addDocker("fedora:latest"); + // Load docker container + DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); + // Run script + // Example for running a bash script correctly + DockerTestOutput to = stm.runSubmission("echo 'PUSH DENIED' > /shared/output/testOutput"); + assertFalse(to.allowed); + } + + @Test + void catchesConsoleLogs() throws InterruptedException { + DockerSubmissionTestModel.addDocker("alpine:latest"); + // Load docker container + DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); + // Run script + // Example for running a bash script correctly + DockerTestOutput to = stm.runSubmission("echo 'Woopdie Woop Scoop! ~ KW'; echo 'PUSH ALLOWED' > /shared/output/testOutput"); + + assertTrue(to.allowed); + assertEquals(to.logs.get(0), "Woopdie Woop Scoop! ~ KW\n"); + } + + @Test + void correctlyReceivesInputFiles() throws InterruptedException { + DockerSubmissionTestModel.addDocker("alpine:latest"); + // Load docker container + DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); + + // Create an input file in tmp/test/input + File file = initTestFile("This is a test input file\n", "testInput"); + + // Run script + // Example for running a bash script correctly + DockerTestOutput to = stm.runSubmission("cat /shared/input/testInput; echo PUSH ALLOWED > /shared/output/testOutput", new File[]{file}); + assertEquals(to.logs.get(0), "This is a test input file\n"); + } + + @Test + void templateTest() throws InterruptedException { + String testOne = "@HelloWorld\n" + + ">Description=\"Test for hello world!\"\n" + + ">Required\n" + + "HelloWorld!"; + String testTwo = "@HelloWorld2\n" + + ">Optional\n" + + "HelloWorld2!\n"; + String template = testOne + "\n" + testTwo; + + File[] files = new File[]{initTestFile("#!/bin/sh\necho 'HelloWorld!'", "HelloWorld.sh"), + initTestFile("#!/bin/sh\necho 'HelloWorld2!'", "HelloWorld2.sh")}; + + String script = + "chmod +x /shared/input/HelloWorld.sh;" + + "chmod +x /shared/input/HelloWorld2.sh;" + + "/shared/input/HelloWorld.sh > /shared/output/HelloWorld;" + + "/shared/input/HelloWorld2.sh > /shared/output/HelloWorld2"; + + DockerSubmissionTestModel.addDocker("alpine:latest"); + // Load docker container + DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); + DockerTemplateTestResult result = stm.runSubmissionWithTemplate(script, template, files); + + // Extract subtests + List results = result.getSubtestResults(); + + // Testing for the template parser capabilities + assertEquals(results.size(), 2); + + assertTrue(results.get(0).isRequired()); + assertFalse(results.get(1).isRequired()); + + assertEquals(results.get(0).getCorrect(), "HelloWorld!\n"); + assertEquals(results.get(1).getCorrect(), "HelloWorld2!\n"); + + assertEquals(results.get(0).getTestDescription(), "Test for hello world!"); + assertEquals(results.get(1).getTestDescription(), ""); + + // Test the docker output + assertEquals(results.get(0).getOutput(), "HelloWorld!\n"); + assertEquals(results.get(1).getOutput(), "HelloWorld2!\n"); + + assertTrue(result.isAllowed()); + + } } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java b/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java index 741bc9c5..c8a4c93f 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/postgre/models/CourseEntityTest.java @@ -55,7 +55,7 @@ public void testJoinKey() { public void testConstructor() { String name = "Test Course"; String description = "Test Description"; - CourseEntity course = new CourseEntity(name, description); + CourseEntity course = new CourseEntity(name, description,2024); assertEquals(name, course.getName()); assertEquals(description, course.getDescription()); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java index c6895598..b2f5ca09 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/util/CourseUtilTest.java @@ -48,7 +48,7 @@ public class CourseUtilTest { public void setUp() { user = new UserEntity("name", "surname", "email", UserRole.student, "azureid"); user.setId(1L); - course = new CourseEntity("name", "description"); + course = new CourseEntity("name", "description",2024); course.setId(1L); course.setJoinKey("key"); cuEnrolled = new CourseUserEntity(1L, 1L, CourseRelation.enrolled); @@ -148,7 +148,7 @@ public void testCheckCourseJson() throws Exception { courseJson.setDescription(null); result = courseUtil.checkCourseJson(courseJson, user, null); assertEquals(HttpStatus.BAD_REQUEST, result.getStatus()); - assertEquals("name and description are required", result.getMessage()); + assertEquals("name, description and year are required", result.getMessage()); courseJson.setDescription("description"); courseJson.setName(""); From c51cbb2c5849ae6a70bff083e2ed91d5af18100f Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 26 Apr 2024 11:56:33 +0200 Subject: [PATCH 06/10] testing github actions --- gha | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 gha diff --git a/gha b/gha new file mode 100644 index 00000000..e69de29b From 4a5c384761cb417bb7d078464b727a361dd228e9 Mon Sep 17 00:00:00 2001 From: Arthur Werbrouck Date: Fri, 26 Apr 2024 12:00:31 +0200 Subject: [PATCH 07/10] death to docker --- .../model/DockerSubmissionTestTest.java | 222 +++++++++--------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java b/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java index 97c89e12..3a6dd5ee 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/model/DockerSubmissionTestTest.java @@ -15,117 +15,117 @@ public class DockerSubmissionTestTest { - File initTestFile(String text, String fileName) { - String localFileLocation = System.getProperty("user.dir") + "/tmp/test/" + fileName; - File file = new File(localFileLocation); - try { - file.getParentFile().mkdirs(); - file.createNewFile(); - FileUtils.writeStringToFile(file, text, "UTF-8"); - } catch (Exception e) { - e.printStackTrace(); - } - return file; - } - - // Check if we can catch the console output of a script. - @Test - void scriptSucceeds() throws InterruptedException { - DockerSubmissionTestModel.addDocker("fedora:latest"); - // Load docker container - DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); - // Run script - DockerTestOutput to = stm.runSubmission("echo 'PUSH ALLOWED' > /shared//output/testOutput"); - assertTrue(to.allowed); - } - - @Test - void scriptFails() throws InterruptedException { - //make sure docker image is installed - DockerSubmissionTestModel.addDocker("fedora:latest"); - // Load docker container - DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); - // Run script - // Example for running a bash script correctly - DockerTestOutput to = stm.runSubmission("echo 'PUSH DENIED' > /shared/output/testOutput"); - assertFalse(to.allowed); - } - - @Test - void catchesConsoleLogs() throws InterruptedException { - DockerSubmissionTestModel.addDocker("alpine:latest"); - // Load docker container - DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); - // Run script - // Example for running a bash script correctly - DockerTestOutput to = stm.runSubmission("echo 'Woopdie Woop Scoop! ~ KW'; echo 'PUSH ALLOWED' > /shared/output/testOutput"); - - assertTrue(to.allowed); - assertEquals(to.logs.get(0), "Woopdie Woop Scoop! ~ KW\n"); - } - - @Test - void correctlyReceivesInputFiles() throws InterruptedException { - DockerSubmissionTestModel.addDocker("alpine:latest"); - // Load docker container - DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); - - // Create an input file in tmp/test/input - File file = initTestFile("This is a test input file\n", "testInput"); - - // Run script - // Example for running a bash script correctly - DockerTestOutput to = stm.runSubmission("cat /shared/input/testInput; echo PUSH ALLOWED > /shared/output/testOutput", new File[]{file}); - assertEquals(to.logs.get(0), "This is a test input file\n"); - } - - @Test - void templateTest() throws InterruptedException { - String testOne = "@HelloWorld\n" + - ">Description=\"Test for hello world!\"\n" + - ">Required\n" + - "HelloWorld!"; - String testTwo = "@HelloWorld2\n" + - ">Optional\n" + - "HelloWorld2!\n"; - String template = testOne + "\n" + testTwo; - - File[] files = new File[]{initTestFile("#!/bin/sh\necho 'HelloWorld!'", "HelloWorld.sh"), - initTestFile("#!/bin/sh\necho 'HelloWorld2!'", "HelloWorld2.sh")}; - - String script = - "chmod +x /shared/input/HelloWorld.sh;" + - "chmod +x /shared/input/HelloWorld2.sh;" + - "/shared/input/HelloWorld.sh > /shared/output/HelloWorld;" + - "/shared/input/HelloWorld2.sh > /shared/output/HelloWorld2"; - - DockerSubmissionTestModel.addDocker("alpine:latest"); - // Load docker container - DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); - DockerTemplateTestResult result = stm.runSubmissionWithTemplate(script, template, files); - - // Extract subtests - List results = result.getSubtestResults(); - - // Testing for the template parser capabilities - assertEquals(results.size(), 2); - - assertTrue(results.get(0).isRequired()); - assertFalse(results.get(1).isRequired()); - - assertEquals(results.get(0).getCorrect(), "HelloWorld!\n"); - assertEquals(results.get(1).getCorrect(), "HelloWorld2!\n"); - - assertEquals(results.get(0).getTestDescription(), "Test for hello world!"); - assertEquals(results.get(1).getTestDescription(), ""); - - // Test the docker output - assertEquals(results.get(0).getOutput(), "HelloWorld!\n"); - assertEquals(results.get(1).getOutput(), "HelloWorld2!\n"); - - assertTrue(result.isAllowed()); - - } +// File initTestFile(String text, String fileName) { +// String localFileLocation = System.getProperty("user.dir") + "/tmp/test/" + fileName; +// File file = new File(localFileLocation); +// try { +// file.getParentFile().mkdirs(); +// file.createNewFile(); +// FileUtils.writeStringToFile(file, text, "UTF-8"); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// return file; +// } +// +// // Check if we can catch the console output of a script. +// @Test +// void scriptSucceeds() throws InterruptedException { +// DockerSubmissionTestModel.addDocker("fedora:latest"); +// // Load docker container +// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); +// // Run script +// DockerTestOutput to = stm.runSubmission("echo 'PUSH ALLOWED' > /shared//output/testOutput"); +// assertTrue(to.allowed); +// } +// +// @Test +// void scriptFails() throws InterruptedException { +// //make sure docker image is installed +// DockerSubmissionTestModel.addDocker("fedora:latest"); +// // Load docker container +// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("fedora"); +// // Run script +// // Example for running a bash script correctly +// DockerTestOutput to = stm.runSubmission("echo 'PUSH DENIED' > /shared/output/testOutput"); +// assertFalse(to.allowed); +// } +// +// @Test +// void catchesConsoleLogs() throws InterruptedException { +// DockerSubmissionTestModel.addDocker("alpine:latest"); +// // Load docker container +// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); +// // Run script +// // Example for running a bash script correctly +// DockerTestOutput to = stm.runSubmission("echo 'Woopdie Woop Scoop! ~ KW'; echo 'PUSH ALLOWED' > /shared/output/testOutput"); +// +// assertTrue(to.allowed); +// assertEquals(to.logs.get(0), "Woopdie Woop Scoop! ~ KW\n"); +// } +// +// @Test +// void correctlyReceivesInputFiles() throws InterruptedException { +// DockerSubmissionTestModel.addDocker("alpine:latest"); +// // Load docker container +// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); +// +// // Create an input file in tmp/test/input +// File file = initTestFile("This is a test input file\n", "testInput"); +// +// // Run script +// // Example for running a bash script correctly +// DockerTestOutput to = stm.runSubmission("cat /shared/input/testInput; echo PUSH ALLOWED > /shared/output/testOutput", new File[]{file}); +// assertEquals(to.logs.get(0), "This is a test input file\n"); +// } +// +// @Test +// void templateTest() throws InterruptedException { +// String testOne = "@HelloWorld\n" + +// ">Description=\"Test for hello world!\"\n" + +// ">Required\n" + +// "HelloWorld!"; +// String testTwo = "@HelloWorld2\n" + +// ">Optional\n" + +// "HelloWorld2!\n"; +// String template = testOne + "\n" + testTwo; +// +// File[] files = new File[]{initTestFile("#!/bin/sh\necho 'HelloWorld!'", "HelloWorld.sh"), +// initTestFile("#!/bin/sh\necho 'HelloWorld2!'", "HelloWorld2.sh")}; +// +// String script = +// "chmod +x /shared/input/HelloWorld.sh;" + +// "chmod +x /shared/input/HelloWorld2.sh;" + +// "/shared/input/HelloWorld.sh > /shared/output/HelloWorld;" + +// "/shared/input/HelloWorld2.sh > /shared/output/HelloWorld2"; +// +// DockerSubmissionTestModel.addDocker("alpine:latest"); +// // Load docker container +// DockerSubmissionTestModel stm = new DockerSubmissionTestModel("alpine"); +// DockerTemplateTestResult result = stm.runSubmissionWithTemplate(script, template, files); +// +// // Extract subtests +// List results = result.getSubtestResults(); +// +// // Testing for the template parser capabilities +// assertEquals(results.size(), 2); +// +// assertTrue(results.get(0).isRequired()); +// assertFalse(results.get(1).isRequired()); +// +// assertEquals(results.get(0).getCorrect(), "HelloWorld!\n"); +// assertEquals(results.get(1).getCorrect(), "HelloWorld2!\n"); +// +// assertEquals(results.get(0).getTestDescription(), "Test for hello world!"); +// assertEquals(results.get(1).getTestDescription(), ""); +// +// // Test the docker output +// assertEquals(results.get(0).getOutput(), "HelloWorld!\n"); +// assertEquals(results.get(1).getOutput(), "HelloWorld2!\n"); +// +// assertTrue(result.isAllowed()); +// +// } } From 738303e7883ba7369293d331df48223cd609d87d Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:29:16 +0200 Subject: [PATCH 08/10] Add year to return body,change json parameter name --- .../ugent/pidgeon/controllers/CourseController.java | 12 ++++++------ .../com/ugent/pidgeon/model/json/CourseJson.java | 12 ++++++------ .../ugent/pidgeon/model/json/CourseWithInfoJson.java | 3 ++- .../main/java/com/ugent/pidgeon/util/CourseUtil.java | 4 +++- .../ugent/pidgeon/util/EntityToJsonConverter.java | 3 ++- .../pidgeon/controllers/CourseControllerTest.java | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java index 63382a60..15218a66 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/CourseController.java @@ -111,7 +111,7 @@ public ResponseEntity createCourse(@RequestBody CourseJson courseJson, Auth a } // Create new course - CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription(), courseJson.getCourseYear()); + CourseEntity courseEntity = new CourseEntity(courseJson.getName(), courseJson.getDescription(), courseJson.getYear()); // Get current time and convert to SQL Timestamp OffsetDateTime currentTimestamp = OffsetDateTime.now(); courseEntity.setCreatedAt(currentTimestamp); @@ -143,7 +143,7 @@ private ResponseEntity doCourseUpdate(CourseEntity courseEntity, CourseJson c } courseEntity.setName(courseJson.getName()); courseEntity.setDescription(courseJson.getDescription()); - courseEntity.setCourseYear(courseJson.getCourseYear()); + courseEntity.setCourseYear(courseJson.getYear()); if (courseJson.getArchived() != null) { courseEntity.setArchivedAt(courseJson.getArchived() ? OffsetDateTime.now() : null); } @@ -192,8 +192,8 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage()); } - if (courseJson.getName() == null && courseJson.getDescription() == null && courseJson.getCourseYear() == null) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name or description is required"); + if (courseJson.getName() == null && courseJson.getDescription() == null && courseJson.getYear() == null) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Name, description or year is required"); } CourseEntity courseEntity = checkResult.getData(); @@ -203,8 +203,8 @@ public ResponseEntity patchCourse(@RequestBody CourseJson courseJson, @PathVa if (courseJson.getDescription() == null) { courseJson.setDescription(courseEntity.getDescription()); } - if (courseJson.getCourseYear() == null) { - courseJson.setCourseYear(courseEntity.getCourseYear()); + if (courseJson.getYear() == null) { + courseJson.setYear(courseEntity.getCourseYear()); } return doCourseUpdate(courseEntity, courseJson, user); diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java index 61b8806e..ad7674f8 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseJson.java @@ -8,13 +8,13 @@ public class CourseJson{ private Boolean isArchived; - private Integer courseYear; + private Integer year; public CourseJson(String name, String description, Boolean isArchived, Integer courseYear) { this.name = name; this.description = description; this.isArchived = isArchived; - this.courseYear = courseYear; + this.year = courseYear; } public String getName() { @@ -41,12 +41,12 @@ public void setArchived(Boolean isArchived) { this.isArchived = isArchived; } - public Integer getCourseYear() { - return courseYear; + public Integer getYear() { + return year; } - public void setCourseYear(Integer courseYear) { - this.courseYear = courseYear; + public void setYear(Integer courseYear) { + this.year = courseYear; } } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java index 0ba3cef9..d7464a18 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithInfoJson.java @@ -13,6 +13,7 @@ public record CourseWithInfoJson ( String joinUrl, String joinKey, OffsetDateTime archivedAt, - OffsetDateTime createdAt + OffsetDateTime createdAt, + Integer year ) {} diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java index bda7a51d..c73c16a1 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/CourseUtil.java @@ -6,6 +6,7 @@ import com.ugent.pidgeon.postgre.models.types.CourseRelation; import com.ugent.pidgeon.postgre.models.types.UserRole; import com.ugent.pidgeon.postgre.repository.*; +import java.util.logging.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -260,7 +261,8 @@ public CheckResult checkCourseJson(CourseJson courseJson, UserEntity user, } - if (courseJson.getName() == null || courseJson.getDescription() == null || courseJson.getCourseYear() == null) { + if (courseJson.getName() == null || courseJson.getDescription() == null || courseJson.getYear() == null) { + Logger.getGlobal().info(""+ courseJson.getYear()); return new CheckResult<>(HttpStatus.BAD_REQUEST, "name, description and year are required", null); } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java index 604a3f7d..8111abd2 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java @@ -96,7 +96,8 @@ public CourseWithInfoJson courseEntityToCourseWithInfo(CourseEntity course, Stri hideKey ? null : joinLink, hideKey ? null : course.getJoinKey(), course.getArchivedAt(), - course.getCreatedAt() + course.getCreatedAt(), + course.getCourseYear() ); } diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java index 639dcf87..5433924f 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java @@ -120,7 +120,7 @@ public void testCreateCourse() throws Exception { when(courseUtil.getJoinLink(any(), any())).thenReturn(""); when(entityToJsonConverter.courseEntityToCourseWithInfo(any(), any(), anyBoolean())). thenReturn(new CourseWithInfoJson(0L, "", "", new UserReferenceJson("", "", 0L), - new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now())); + new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now(), 2013)); mockMvc.perform(MockMvcRequestBuilders.post(ApiRoutes.COURSE_BASE_PATH) .contentType(MediaType.APPLICATION_JSON) @@ -217,7 +217,7 @@ public void testGetCourseByCourseId() throws Exception { when(courseUtil.getJoinLink(any(), any())).thenReturn(""); when(entityToJsonConverter.courseEntityToCourseWithInfo(any(), any(), anyBoolean())). thenReturn(new CourseWithInfoJson(0L, "", "", new UserReferenceJson("", "", 0L), - new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now())); + new ArrayList<>(), "", "", "", OffsetDateTime.now(), OffsetDateTime.now(), 2023)); when(courseUtil.getCourseIfUserInCourse(anyLong(), any(UserEntity.class))). thenReturn(new CheckResult<>(HttpStatus.OK, "", new Pair<>(new CourseEntity(), CourseRelation.course_admin))); mockMvc.perform(MockMvcRequestBuilders.get(ApiRoutes.COURSE_BASE_PATH + "/1")) From ead08ae6a0543c809d239792dc61b92830b814f8 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 27 Apr 2024 08:41:46 +0200 Subject: [PATCH 09/10] Added year to `/courses` response --- .../com/ugent/pidgeon/model/json/CourseWithRelationJson.java | 2 +- .../java/com/ugent/pidgeon/postgre/models/CourseEntity.java | 2 +- .../java/com/ugent/pidgeon/util/EntityToJsonConverter.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java index 4882e9e5..9f52dca6 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/json/CourseWithRelationJson.java @@ -4,5 +4,5 @@ import java.time.OffsetDateTime; public record CourseWithRelationJson (String url, CourseRelation relation, String name, Long courseId, - OffsetDateTime archivedAt, Integer memberCount, OffsetDateTime createdAt) { } + OffsetDateTime archivedAt, Integer memberCount, OffsetDateTime createdAt, Integer year) { } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java index 93a246e9..042f9d6d 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/postgre/models/CourseEntity.java @@ -19,7 +19,7 @@ public class CourseEntity { private String description; @Column(name = "course_year", nullable = true) - private int courseYear; + private Integer courseYear; @Column(name = "created_at") diff --git a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java index 8111abd2..9056821a 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/util/EntityToJsonConverter.java @@ -110,7 +110,8 @@ public CourseWithRelationJson courseEntityToCourseWithRelation(CourseEntity cour course.getId(), course.getArchivedAt(), memberCount, - course.getCreatedAt() + course.getCreatedAt(), + course.getCourseYear() ); } From c71e4cde9d1db91add2d562ed21c802be2244b23 Mon Sep 17 00:00:00 2001 From: Aqua-sc <108478185+Aqua-sc@users.noreply.github.com> Date: Sat, 27 Apr 2024 08:49:08 +0200 Subject: [PATCH 10/10] fixed tests --- .../com/ugent/pidgeon/controllers/CourseControllerTest.java | 3 ++- .../java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java index 5433924f..9e1e05d5 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/controllers/CourseControllerTest.java @@ -176,7 +176,8 @@ public void testUpdateCourse() throws Exception { @Test public void testPatchCourse() throws Exception { String courseJson = "{\"name\": null, \"description\": \"description\"}"; - when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", new CourseEntity())); + CourseEntity courseEntity = new CourseEntity("name", "description",2024); + when(courseUtil.getCourseIfAdmin(anyLong(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", courseEntity)); when(courseUtil.checkCourseJson(any(), any(), any())).thenReturn(new CheckResult<>(HttpStatus.OK, "", null)); when(courseRepository.save(any())).thenReturn(null); diff --git a/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java b/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java index 3b5b9897..b199d564 100644 --- a/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java +++ b/backend/app/src/test/java/com/ugent/pidgeon/util/EntityToJsonConverterTest.java @@ -76,6 +76,7 @@ public void setUp() { courseEntity = new CourseEntity(); courseEntity.setId(1L); courseEntity.setName("Test Course"); + courseEntity.setCourseYear(2024); projectEntity = new ProjectEntity(); projectEntity.setId(1L);