diff --git a/src/test/java/de/tum/in/www1/artemis/LtiIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/LtiIntegrationTest.java index e4871e7c5211..53b9fbb18b0f 100644 --- a/src/test/java/de/tum/in/www1/artemis/LtiIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/LtiIntegrationTest.java @@ -8,7 +8,6 @@ import java.time.temporal.ChronoUnit; import java.util.Set; -import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -139,8 +138,8 @@ void init() { jiraRequestMockProvider.enableMockingOfRequests(); } - private String generateRandomEmail() { - return RandomStringUtils.random(12, true, true) + "@email.com"; + private String generateEmail(String username) { + return username + "@email.com"; } private String replaceEmail(String requestBody, String email) { @@ -163,7 +162,7 @@ private void addJiraMocks(String email, String existingUser) throws Exception { @ValueSource(strings = { EDX_REQUEST_BODY, MOODLE_REQUEST_BODY }) @WithAnonymousUser void launchAsAnonymousUser_noOnlineCourseConfigurationException(String requestBody) throws Exception { - requestBody = replaceEmail(requestBody, generateRandomEmail()); + requestBody = replaceEmail(requestBody, generateEmail("launchAsAnonymousUser_noOnlineCourseConfigurationException")); course.setOnlineCourseConfiguration(null); courseRepository.save(course); @@ -176,7 +175,7 @@ void launchAsAnonymousUser_noOnlineCourseConfigurationException(String requestBo @ValueSource(strings = { EDX_REQUEST_BODY }) // To be readded when LtiUserId is removed, MOODLE_REQUEST_BODY }) @WithAnonymousUser void launchAsAnonymousUser_WithoutExistingEmail(String requestBody) throws Exception { - String email = generateRandomEmail(); + String email = generateEmail("launchAsAnonymousUser_WithoutExistingEmail"); requestBody = replaceEmail(requestBody, email); addJiraMocks(email, null); @@ -193,7 +192,7 @@ void launchAsAnonymousUser_WithoutExistingEmail(String requestBody) throws Excep @ValueSource(strings = { EDX_REQUEST_BODY, MOODLE_REQUEST_BODY }) @WithAnonymousUser void launchAsAnonymousUser_WithExistingEmail(String requestBody) throws Exception { - String email = generateRandomEmail(); + String email = generateEmail("launchAsAnonymousUser_WithExistingEmail"); requestBody = replaceEmail(requestBody, email); addJiraMocks(email, TEST_PREFIX + "student1"); @@ -210,7 +209,7 @@ void launchAsAnonymousUser_WithExistingEmail(String requestBody) throws Exceptio @ValueSource(strings = { EDX_REQUEST_BODY }) // To be readded when LtiUserId is removed, MOODLE_REQUEST_BODY }) @WithAnonymousUser void launchAsAnonymousUser_RequireExistingUser(String requestBody) throws Exception { - String email = generateRandomEmail(); + String email = generateEmail("launchAsAnonymousUser_RequireExistingUser"); requestBody = replaceEmail(requestBody, email); course = courseRepository.findByIdWithEagerOnlineCourseConfigurationElseThrow(course.getId()); @@ -228,7 +227,7 @@ void launchAsAnonymousUser_RequireExistingUser(String requestBody) throws Except @ValueSource(strings = { EDX_REQUEST_BODY, MOODLE_REQUEST_BODY }) @WithAnonymousUser void launchAsAnonymousUser_checkExceptions(String requestBody) throws Exception { - requestBody = replaceEmail(requestBody, generateRandomEmail()); + requestBody = replaceEmail(requestBody, generateEmail("launchAsAnonymousUser_checkExceptions")); request.postWithoutLocation("/api/lti/launch/" + programmingExercise.getId() + 1, requestBody.getBytes(), HttpStatus.NOT_FOUND, new HttpHeaders(), MediaType.APPLICATION_FORM_URLENCODED_VALUE); diff --git a/src/test/java/de/tum/in/www1/artemis/OrganizationIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/OrganizationIntegrationTest.java index 2ef8e750d84c..549344ef60e9 100644 --- a/src/test/java/de/tum/in/www1/artemis/OrganizationIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/OrganizationIntegrationTest.java @@ -186,7 +186,7 @@ void testAddUserToOrganization() throws Exception { Organization organization = database.createOrganization(); organization = organizationRepo.save(organization); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testAddUserToOrganization"); request.postWithoutLocation("/api/admin/organizations/" + organization.getId() + "/users/" + student.getLogin(), null, HttpStatus.OK, null); Organization updatedOrganization = request.get("/api/admin/organizations/" + organization.getId() + "/full", HttpStatus.OK, Organization.class); @@ -198,11 +198,11 @@ void testAddUserToOrganization() throws Exception { */ @Test @WithMockUser(username = "admin", roles = "ADMIN") - void testRemoveUserToOrganization() throws Exception { + void testRemoveUserFromOrganization() throws Exception { jiraRequestMockProvider.enableMockingOfRequests(); Organization organization = database.createOrganization(); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testRemoveUser_"); organization.getUsers().add(student); organization = organizationRepo.save(organization); @@ -268,7 +268,7 @@ void testUpdateOrganization_idInBodyNull() throws Exception { } /** - * Test updating an existing organization when the Id in the path doesn't match the one in the Body + * Test updating an existing organization when the id in the path doesn't match the one in the Body */ @Test @WithMockUser(username = "admin", roles = "ADMIN") @@ -279,9 +279,9 @@ void testUpdateOrganization_IdInPathWrong() throws Exception { organizationRepo.save(organization); String initialName = organization.getName(); organization.setName("UpdatedName"); - long randomId = 1337420; + long wrongId = 1337420; - Organization updatedOrganization = request.putWithResponseBody("/api/admin/organizations/" + randomId, organization, Organization.class, HttpStatus.BAD_REQUEST); + Organization updatedOrganization = request.putWithResponseBody("/api/admin/organizations/" + wrongId, organization, Organization.class, HttpStatus.BAD_REQUEST); organization.setName(initialName); assertThat(updatedOrganization).isNull(); } @@ -332,7 +332,7 @@ void testGetNumberOfUsersAndCoursesOfAllOrganizations() throws Exception { organization = organizationRepo.save(organization); courseRepo.addOrganizationToCourse(course1.getId(), organization); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testGetNumberOfUsersOfAll_"); userRepo.addOrganizationToUser(student.getId(), organization); @@ -357,7 +357,7 @@ void testGetNumberOfUsersAndCoursesOfOrganization() throws Exception { organization = organizationRepo.save(organization); courseRepo.addOrganizationToCourse(course1.getId(), organization); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testGetNumberOfUsers_"); userRepo.addOrganizationToUser(student.getId(), organization); @@ -382,7 +382,7 @@ void testGetOrganizationById() throws Exception { course1 = courseRepo.save(course1); courseRepo.addOrganizationToCourse(course1.getId(), organization); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testGetOrganizationById"); userRepo.addOrganizationToUser(student.getId(), organization); // invoked remove to make sure it works correctly @@ -430,7 +430,7 @@ void testGetAllOrganizationByUser() throws Exception { Organization organization = database.createOrganization(); organization = organizationRepo.save(organization); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testGetAllOrganizationByUser"); userRepo.addOrganizationToUser(student.getId(), organization); @@ -448,7 +448,7 @@ void testOrganizationIndexing() throws Exception { jiraRequestMockProvider.enableMockingOfRequests(); Organization organization = database.createOrganization(); - User student = database.createAndSaveUser(UUID.randomUUID().toString().replace("-", "")); + User student = database.createAndSaveUser(TEST_PREFIX + "testOrganizationIndexing"); organization.getUsers().add(student); organization = organizationRepo.save(organization); diff --git a/src/test/java/de/tum/in/www1/artemis/ParticipationIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/ParticipationIntegrationTest.java index 57f9c61a72a6..6782bf2dcf20 100644 --- a/src/test/java/de/tum/in/www1/artemis/ParticipationIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/ParticipationIntegrationTest.java @@ -1114,7 +1114,7 @@ private Exercise createTextExerciseForTeam() { private Team createTeamForExercise(User student, Exercise exercise) { var team = new Team(); - team.setShortName("t" + UUID.randomUUID().toString().substring(0, 3)); + team.setShortName(TEST_PREFIX + "createTeamForExercise"); team.addStudents(student); team.setExercise(exercise); return teamRepository.save(team); diff --git a/src/test/java/de/tum/in/www1/artemis/fileupload/FileUploadExerciseIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/fileupload/FileUploadExerciseIntegrationTest.java index d4e297ae6626..f8e60bdec587 100644 --- a/src/test/java/de/tum/in/www1/artemis/fileupload/FileUploadExerciseIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/fileupload/FileUploadExerciseIntegrationTest.java @@ -5,7 +5,6 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import java.util.function.Function; import org.junit.jupiter.api.BeforeEach; @@ -664,7 +663,7 @@ void testGetAllExercisesOnPageAsEditorSuccess() throws Exception { final Course course = database.addEmptyCourse(); final var now = ZonedDateTime.now(); FileUploadExercise exercise = ModelFactory.generateFileUploadExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), "pdf", course); - String title = "LoremIpsum" + UUID.randomUUID(); + String title = TEST_PREFIX + "testGetAllExercisesOnPageAsEditorSuccess"; exercise.setTitle(title); exercise = fileUploadExerciseRepository.save(exercise); final var searchTerm = database.configureSearch(exercise.getTitle()); diff --git a/src/test/java/de/tum/in/www1/artemis/hestia/CodeHintServiceTest.java b/src/test/java/de/tum/in/www1/artemis/hestia/CodeHintServiceTest.java index 35792aa293c0..665d0657a393 100644 --- a/src/test/java/de/tum/in/www1/artemis/hestia/CodeHintServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/hestia/CodeHintServiceTest.java @@ -67,7 +67,7 @@ private ProgrammingExerciseSolutionEntry addSolutionEntryToTestCase(ProgrammingE var solutionEntry = new ProgrammingExerciseSolutionEntry(); solutionEntry.setTestCase(testCase); solutionEntry.setLine(1); - solutionEntry.setCode(UUID.randomUUID().toString()); + solutionEntry.setCode("code"); return solutionEntryRepository.save(solutionEntry); } diff --git a/src/test/java/de/tum/in/www1/artemis/lecture/CompetencyIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/lecture/CompetencyIntegrationTest.java index f0b5c4d2ecfa..a41a3dbcde87 100644 --- a/src/test/java/de/tum/in/www1/artemis/lecture/CompetencyIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/lecture/CompetencyIntegrationTest.java @@ -8,7 +8,6 @@ import java.time.temporal.ChronoUnit; import java.util.HashSet; import java.util.List; -import java.util.Random; import java.util.Set; import java.util.stream.Collectors; @@ -171,7 +170,7 @@ void setupTestScenario() { private void createCompetency() { Course course = courseRepository.findWithEagerCompetenciesById(idOfCourse).get(); Competency competency = new Competency(); - competency.setTitle("Competency" + new Random().nextInt()); + competency.setTitle("Competency" + idOfCourse); competency.setDescription("This is an example competency"); competency.setTaxonomy(CompetencyTaxonomy.UNDERSTAND); competency.setCourse(course); diff --git a/src/test/java/de/tum/in/www1/artemis/lecture/LectureIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/lecture/LectureIntegrationTest.java index 9fd8bd8be27a..1031c3fbb894 100644 --- a/src/test/java/de/tum/in/www1/artemis/lecture/LectureIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/lecture/LectureIntegrationTest.java @@ -50,7 +50,7 @@ void initTestCase() throws Exception { List courses = this.database.createCoursesWithExercisesAndLectures(TEST_PREFIX, true, true, numberOfTutors); this.course1 = this.courseRepository.findByIdWithExercisesAndLecturesElseThrow(courses.get(0).getId()); var lecture = this.course1.getLectures().stream().findFirst().get(); - lecture.setTitle("Lecture " + new Random().nextInt()); // needed for search by title + lecture.setTitle("Lecture " + lecture.getId()); // needed for search by title this.lecture1 = lectureRepository.save(lecture); this.textExercise = textExerciseRepository.findByCourseIdWithCategories(course1.getId()).stream().findFirst().get(); // Add users that are not in the course diff --git a/src/test/java/de/tum/in/www1/artemis/metis/AbstractConversationTest.java b/src/test/java/de/tum/in/www1/artemis/metis/AbstractConversationTest.java index 0944ecd57166..674ae8015ada 100644 --- a/src/test/java/de/tum/in/www1/artemis/metis/AbstractConversationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/metis/AbstractConversationTest.java @@ -4,7 +4,6 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import java.security.SecureRandom; import java.util.Arrays; import java.util.Set; @@ -170,10 +169,6 @@ Course setCourseInformationSharingConfiguration(CourseInformationSharingConfigur return persistedCourse; } - ChannelDTO createChannel(boolean isPublicChannel) throws Exception { - return createChannel(isPublicChannel, RandomConversationNameGenerator.generateRandomConversationName()); - } - ChannelDTO createChannel(boolean isPublicChannel, String name) throws Exception { var channelDTO = new ChannelDTO(); channelDTO.setName(name); @@ -278,23 +273,4 @@ void resetWebsocketMock() { reset(this.messagingTemplate); } - public static class RandomConversationNameGenerator { - - private static final String LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz"; - - private static final String NUMBERS = "0123456789"; - - private static final String ALL_CHARS = LOWERCASE_LETTERS + NUMBERS; - - private static final SecureRandom RANDOM = new SecureRandom(); - - public static String generateRandomConversationName() { - var stringBuilder = new StringBuilder(); - for (int i = 0; i < 10; i++) { - stringBuilder.append(ALL_CHARS.charAt(RANDOM.nextInt(ALL_CHARS.length()))); - } - return stringBuilder.toString(); - } - } - } diff --git a/src/test/java/de/tum/in/www1/artemis/metis/ChannelIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/metis/ChannelIntegrationTest.java index ccf794d50238..431db676d285 100644 --- a/src/test/java/de/tum/in/www1/artemis/metis/ChannelIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/metis/ChannelIntegrationTest.java @@ -86,7 +86,7 @@ void createChannel_asEditor_shouldCreateChannel(boolean isPublicChannel) throws private void isAllowedToCreateChannelTest(boolean isPublicChannel, String loginNameWithoutPrefix) throws Exception { // given var channelDTO = new ChannelDTO(); - channelDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + channelDTO.setName(TEST_PREFIX); channelDTO.setIsPublic(isPublicChannel); channelDTO.setIsAnnouncementChannel(false); channelDTO.setDescription("general channel"); @@ -119,7 +119,7 @@ void createTest_messagingDeactivated(CourseInformationSharingConfiguration cours var channelDTO = new ChannelDTO(); channelDTO.setIsPublic(true); channelDTO.setIsAnnouncementChannel(false); - channelDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + channelDTO.setName(TEST_PREFIX); channelDTO.setDescription("general channel"); expectCreateForbidden(channelDTO); @@ -142,7 +142,7 @@ void update_messagingDeactivated(CourseInformationSharingConfiguration courseInf var channelDTO = new ChannelDTO(); channelDTO.setIsPublic(true); channelDTO.setIsAnnouncementChannel(false); - channelDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + channelDTO.setName(TEST_PREFIX); channelDTO.setDescription("general channel"); expectUpdateForbidden(1L, channelDTO); @@ -172,16 +172,11 @@ void deleteTest_messagingDeactivated(CourseInformationSharingConfiguration cours @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void createChannel_descriptionInvalid_shouldReturnBadRequest(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); - - var channelDTO = new ChannelDTO(); - channelDTO.setIsPublic(isPublicChannel); - channelDTO.setIsAnnouncementChannel(false); - channelDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); - channelDTO.setDescription("a".repeat(251)); + var channel = createChannel(isPublicChannel, TEST_PREFIX); + channel.setDescription("a".repeat(251)); // when - expectCreateBadRequest(channelDTO); + expectCreateBadRequest(channel); // then verifyNoParticipantTopicWebsocketSent(); @@ -195,7 +190,7 @@ void createChannel_descriptionInvalid_shouldReturnBadRequest(boolean isPublicCha void createChannel_asNonCourseInstructorOrTutorOrEditor_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given var channelDTO = new ChannelDTO(); - channelDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + channelDTO.setName(TEST_PREFIX); channelDTO.setIsPublic(isPublicChannel); channelDTO.setIsAnnouncementChannel(false); channelDTO.setDescription("general channel"); @@ -217,7 +212,7 @@ void createChannel_asNonCourseInstructorOrTutorOrEditor_shouldReturnForbidden(bo @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void deleteChannel_asInstructor_shouldDeleteChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // when database.changeUser(testPrefix + "instructor2"); request.delete("/api/courses/" + exampleCourseId + "/channels/" + channel.getId(), HttpStatus.OK); @@ -232,7 +227,7 @@ void deleteChannel_asInstructor_shouldDeleteChannel(boolean isPublicChannel) thr @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void deleteTutorialGroupChannel_asInstructor_shouldReturnBadRequest(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); var tutorialGroup = database.createTutorialGroup(exampleCourseId, "tg-channel-test", "LoremIpsum", 10, false, "Garching", Language.ENGLISH.name(), userRepository.findOneByLogin(testPrefix + "tutor1").get(), Set.of()); var channelFromDatabase = channelRepository.findById(channel.getId()).get(); @@ -257,7 +252,7 @@ void deleteTutorialGroupChannel_asInstructor_shouldReturnBadRequest(boolean isPu @WithMockUser(username = TEST_PREFIX + "tutor1", roles = "TA") void deleteChannel_asCreator_shouldDeleteChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // when request.delete("/api/courses/" + exampleCourseId + "/channels/" + channel.getId(), HttpStatus.OK); // then @@ -271,7 +266,7 @@ void deleteChannel_asCreator_shouldDeleteChannel(boolean isPublicChannel) throws @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void deleteChannel_asNonCourseInstructor_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); addUserAsChannelModerators(channel, "tutor2"); // then @@ -297,9 +292,9 @@ void deleteChannel_asNonCourseInstructor_shouldReturnForbidden(boolean isPublicC @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void updateChannel_asUserWithChannelModerationRights_shouldUpdateChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX + "1"); var updateDTO = new ChannelDTO(); - updateDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + updateDTO.setName(TEST_PREFIX + "2"); updateDTO.setDescription("new description"); updateDTO.setTopic("new topic"); addUserAsChannelModerators(channel, "tutor1"); @@ -314,7 +309,7 @@ void updateChannel_asUserWithChannelModerationRights_shouldUpdateChannel(boolean resetWebsocketMock(); // channel moderators can also update the channel - updateDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + updateDTO.setName(TEST_PREFIX + "3"); updateDTO.setDescription("new description2"); updateDTO.setTopic("new topic2"); database.changeUser(testPrefix + "tutor1"); @@ -332,11 +327,11 @@ void updateChannel_asUserWithChannelModerationRights_shouldUpdateChannel(boolean @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void updateChannel_onArchivedChannel_shouldReturnOk(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX + "1"); archiveChannel(channel.getId()); var updateDTO = new ChannelDTO(); - updateDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + updateDTO.setName(TEST_PREFIX + "2"); updateDTO.setDescription("new description"); updateDTO.setTopic("new topic"); addUserAsChannelModerators(channel, "tutor1"); @@ -357,9 +352,9 @@ void updateChannel_onArchivedChannel_shouldReturnOk(boolean isPublicChannel) thr @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void updateChannel_asUserWithoutChannelModerationRights_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX + "1"); var updateDTO = new ChannelDTO(); - updateDTO.setName(RandomConversationNameGenerator.generateRandomConversationName()); + updateDTO.setName(TEST_PREFIX + "2"); updateDTO.setDescription("new description"); updateDTO.setTopic("new topic"); @@ -384,7 +379,7 @@ void updateChannel_asUserWithoutChannelModerationRights_shouldReturnForbidden(bo @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void archiveAndUnarchiveChannel_asUserWithoutChannelModerationRights_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // then database.changeUser(testPrefix + "student1"); @@ -411,12 +406,7 @@ void archiveAndUnarchiveChannel_asUserWithoutChannelModerationRights_shouldRetur @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void archiveAndUnarchiveChannel_messagingFeatureDeactivated_shouldReturnForbidden(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { - archival_messagingDeactivated(courseInformationSharingConfiguration); - - } - - void archival_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { - var channel = createChannel(true); + var channel = createChannel(true, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); // given @@ -432,7 +422,7 @@ void archival_messagingDeactivated(CourseInformationSharingConfiguration courseI @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void archiveAndUnarchiveChannel_asUserWithChannelModerationRights_shouldArchiveChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); addUserAsChannelModerators(channel, "tutor1"); // then @@ -455,12 +445,7 @@ void archiveAndUnarchiveChannel_asUserWithChannelModerationRights_shouldArchiveC @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void grantRevokeChannelModeratorRole_messagingFeatureDeactivated_shouldReturnForbidden(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { - grantRevokeChannelModeratorRole_messagingDeactivated(courseInformationSharingConfiguration); - - } - - void grantRevokeChannelModeratorRole_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { - var channel = createChannel(true); + var channel = createChannel(true, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); @@ -477,7 +462,7 @@ void grantRevokeChannelModeratorRole_messagingDeactivated(CourseInformationShari @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void grantRevokeChannelModeratorRole_asUserWithChannelModerationRights_shouldGrantRevokeChannelModeratorRole(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); addUserAsChannelModerators(channel, "tutor1"); addUsersToConversation(channel.getId(), "student1"); addUsersToConversation(channel.getId(), "student2"); @@ -507,7 +492,7 @@ void grantRevokeChannelModeratorRole_asUserWithChannelModerationRights_shouldGra @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void grantRevokeChannelModeratorRole_asUserWithoutChannelModerationRights_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // then database.changeUser(testPrefix + "student1"); @@ -538,7 +523,7 @@ void registerDeregisterUsersToChannel_messagingFeatureDeactivated_shouldReturnFo } void registerUsersToChannel_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { - var channel = createChannel(true); + var channel = createChannel(true, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); // given expectRegisterDeregisterForbidden(channel, true); @@ -553,7 +538,7 @@ void registerUsersToChannel_messagingDeactivated(CourseInformationSharingConfigu @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void registerUsersToChannel_asUserWithChannelModerationRights_shouldRegisterUsersToChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); addUserAsChannelModerators(channel, "tutor1"); // then @@ -600,7 +585,7 @@ void registerUsersToChannel_asUserWithChannelModerationRights_shouldRegisterUser @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void registerUsersToChannel_asUserWithoutChannelModerationRights_shouldReturnForbidden(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // then database.changeUser(testPrefix + "student1"); @@ -626,7 +611,7 @@ void registerUsersToChannel_asUserWithoutChannelModerationRights_shouldReturnFor @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void leaveChannel_asNormalUser_canLeaveChannel(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); addUsersToConversation(channel.getId(), "student1"); // then @@ -646,7 +631,7 @@ void leaveChannel_asNormalUser_canLeaveChannel(boolean isPublicChannel) throws E @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void leaveChannel_asCreator_shouldReturnBadRequest(boolean isPublicChannel) throws Exception { // given - var channel = createChannel(isPublicChannel); + var channel = createChannel(isPublicChannel, TEST_PREFIX); // then request.postWithoutResponseBody("/api/courses/" + exampleCourseId + "/channels/" + channel.getId() + "/deregister", List.of(testPrefix + "instructor1"), HttpStatus.BAD_REQUEST); @@ -661,7 +646,7 @@ void leaveChannel_asCreator_shouldReturnBadRequest(boolean isPublicChannel) thro @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void joinPublicChannel_asNormalUser_canJoinPublicChannel() throws Exception { // given - var channel = createChannel(true); + var channel = createChannel(true, TEST_PREFIX); // then database.changeUser(testPrefix + "student1"); @@ -679,7 +664,7 @@ void joinPublicChannel_asNormalUser_canJoinPublicChannel() throws Exception { @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void joinPrivateChannel_asNormalUser_canNotJoinPrivateChannel() throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); // then database.changeUser(testPrefix + "student1"); @@ -694,7 +679,7 @@ void joinPrivateChannel_asNormalUser_canNotJoinPrivateChannel() throws Exception @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void joinPrivateChannel_asInstructor_canJoinPrivateChannel() throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); // then database.changeUser(testPrefix + "instructor2"); @@ -709,12 +694,12 @@ void joinPrivateChannel_asInstructor_canJoinPrivateChannel() throws Exception { @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void getCourseChannelsOverview_asNormalUser_canSeeAllPublicChannelsAndPrivateChannelsWhereMember() throws Exception { // given - var publicChannelWhereMember = createChannel(true, RandomConversationNameGenerator.generateRandomConversationName()); + var publicChannelWhereMember = createChannel(true, TEST_PREFIX + "1"); addUsersToConversation(publicChannelWhereMember.getId(), "student1"); - var publicChannelWhereNotMember = createChannel(true, RandomConversationNameGenerator.generateRandomConversationName()); - var privateChannelWhereMember = createChannel(false, RandomConversationNameGenerator.generateRandomConversationName()); + var publicChannelWhereNotMember = createChannel(true, TEST_PREFIX + "2"); + var privateChannelWhereMember = createChannel(false, TEST_PREFIX + "3"); addUsersToConversation(privateChannelWhereMember.getId(), "student1"); - var privateChannelWhereNotMember = createChannel(false, RandomConversationNameGenerator.generateRandomConversationName()); + var privateChannelWhereNotMember = createChannel(false, TEST_PREFIX + "4"); // then database.changeUser(testPrefix + "student1"); @@ -733,12 +718,12 @@ void getCourseChannelsOverview_asNormalUser_canSeeAllPublicChannelsAndPrivateCha @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void getCourseChannelsOverview_asCourseInstructor_canSeeAllPublicChannelsAndAllPrivateChannels() throws Exception { // given - var publicChannelWhereMember = createChannel(true, RandomConversationNameGenerator.generateRandomConversationName()); + var publicChannelWhereMember = createChannel(true, TEST_PREFIX + "1"); addUsersToConversation(publicChannelWhereMember.getId(), "student1"); - var publicChannelWhereNotMember = createChannel(true, RandomConversationNameGenerator.generateRandomConversationName()); - var privateChannelWhereMember = createChannel(false, RandomConversationNameGenerator.generateRandomConversationName()); + var publicChannelWhereNotMember = createChannel(true, TEST_PREFIX + "2"); + var privateChannelWhereMember = createChannel(false, TEST_PREFIX + "3"); addUsersToConversation(privateChannelWhereMember.getId(), "student1"); - var privateChannelWhereNotMember = createChannel(false, RandomConversationNameGenerator.generateRandomConversationName()); + var privateChannelWhereNotMember = createChannel(false, TEST_PREFIX + "4"); // then database.changeUser(testPrefix + "instructor2"); diff --git a/src/test/java/de/tum/in/www1/artemis/metis/ConversationIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/metis/ConversationIntegrationTest.java index 8f06463a719b..b0bad9d8decc 100644 --- a/src/test/java/de/tum/in/www1/artemis/metis/ConversationIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/metis/ConversationIntegrationTest.java @@ -55,7 +55,7 @@ void getConversationsOfUser_messagingDeactivated(CourseInformationSharingConfigu @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void getConversationsOfUser_shouldReturnConversationsWhereMember() throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX + "1"); addUsersToConversation(channel.getId(), "tutor1"); var groupChat = createGroupChat("tutor1"); hideConversation(groupChat.getId(), "tutor1"); @@ -64,7 +64,7 @@ void getConversationsOfUser_shouldReturnConversationsWhereMember() throws Except var post = this.postInConversation(oneToOneChat.getId(), "instructor1"); this.resetWebsocketMock(); favoriteConversation(oneToOneChat.getId(), "tutor1"); - var channel2 = createChannel(false, RandomConversationNameGenerator.generateRandomConversationName()); + var channel2 = createChannel(false, TEST_PREFIX + "2"); // then database.changeUser(testPrefix + "tutor1"); @@ -113,7 +113,7 @@ else if (conv.getId().equals(oneToOneChat.getId())) { @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void switchFavoriteStatus_shouldSwitchFavoriteStatus() throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); addUsersToConversation(channel.getId(), "tutor1"); // then database.changeUser(testPrefix + "tutor1"); @@ -140,7 +140,7 @@ void switchFavoriteStatus_messagingFeatureDeactivated_shouldReturnForbidden(Cour void switchFavoriteStatus_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); @@ -158,7 +158,7 @@ void switchFavoriteStatus_messagingDeactivated(CourseInformationSharingConfigura @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void switchHiddenStatus_shouldSwitchHiddenStatus() throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); addUsersToConversation(channel.getId(), "tutor1"); // then database.changeUser(testPrefix + "tutor1"); @@ -185,7 +185,7 @@ void switchHiddenStatus_messagingFeatureDeactivated_shouldReturnForbidden(Course void switchHiddenStatus_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); @@ -209,7 +209,7 @@ void searchConversationMembers_messagingFeatureDeactivated_shouldReturnForbidden void searchConversationMembers_messagingDeactivated(CourseInformationSharingConfiguration courseInformationSharingConfiguration) throws Exception { // given - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); setCourseInformationSharingConfiguration(courseInformationSharingConfiguration); @@ -230,7 +230,7 @@ void searchConversationMembers_messagingDeactivated(CourseInformationSharingConf @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void searchMembersOfConversation_shouldFindMembersWhereLoginOrNameMatches() throws Exception { - var channel = createChannel(false); + var channel = createChannel(false, TEST_PREFIX); addUsersToConversation(channel.getId(), "student1"); addUsersToConversation(channel.getId(), "editor1"); addUsersToConversation(channel.getId(), "tutor1"); diff --git a/src/test/java/de/tum/in/www1/artemis/modeling/ModelingExerciseIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/modeling/ModelingExerciseIntegrationTest.java index 1d8195cda5fb..25a2d602370f 100644 --- a/src/test/java/de/tum/in/www1/artemis/modeling/ModelingExerciseIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/modeling/ModelingExerciseIntegrationTest.java @@ -566,22 +566,21 @@ void testInstructorGetsOnlyResultsFromOwningCourses() throws Exception { @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testInstructorSearchTermMatchesTitle() throws Exception { database.addUsers(TEST_PREFIX, 1, 1, 0, 1); - testSearchTermMatchesTitle(); + testSearchTermMatchesTitle(TEST_PREFIX + "testInstructorSearchTermMatchesTitle"); } @Test @WithMockUser(username = "admin", roles = "ADMIN") void testAdminSearchTermMatchesTitle() throws Exception { database.addUsers(TEST_PREFIX, 1, 1, 0, 1); - testSearchTermMatchesTitle(); + testSearchTermMatchesTitle(TEST_PREFIX + "testAdminSearchTermMatchesTitle"); } - private void testSearchTermMatchesTitle() throws Exception { + private void testSearchTermMatchesTitle(String exerciseTitle) throws Exception { final Course course = database.addEmptyCourse(); final var now = ZonedDateTime.now(); ModelingExercise exercise = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course); - String title = "LoremIpsum" + UUID.randomUUID(); - exercise.setTitle(title); + exercise.setTitle(exerciseTitle); exercise = modelingExerciseRepository.save(exercise); final var searchTerm = database.configureSearch(exercise.getTitle()); @@ -592,14 +591,14 @@ private void testSearchTermMatchesTitle() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testInstructorGetsResultsFromOwningCoursesNotEmpty() throws Exception { - final String uuid = UUID.randomUUID().toString(); - database.addCourseWithOneModelingExercise("ClassDiagram" + uuid); - database.addCourseWithOneModelingExercise("Activity Diagram" + uuid); - final var searchClassDiagram = database.configureSearch("ClassDiagram" + uuid); + final String titleExtension = "testInstructorGetsResultsFromOwningCoursesNotEmpty"; + database.addCourseWithOneModelingExercise("ClassDiagram" + titleExtension); + database.addCourseWithOneModelingExercise("Activity Diagram" + titleExtension); + final var searchClassDiagram = database.configureSearch("ClassDiagram" + titleExtension); final var resultClassDiagram = request.getSearchResult("/api/modeling-exercises/", HttpStatus.OK, ModelingExercise.class, database.searchMapping(searchClassDiagram)); assertThat(resultClassDiagram.getResultsOnPage()).hasSize(1); - final var searchActivityDiagram = database.configureSearch("Activity Diagram" + uuid); + final var searchActivityDiagram = database.configureSearch("Activity Diagram" + titleExtension); final var resultActivityDiagram = request.getSearchResult("/api/modeling-exercises/", HttpStatus.OK, ModelingExercise.class, database.searchMapping(searchActivityDiagram)); assertThat(resultActivityDiagram.getResultsOnPage()).hasSize(1); } @@ -607,8 +606,7 @@ void testInstructorGetsResultsFromOwningCoursesNotEmpty() throws Exception { @Test @WithMockUser(username = "admin", roles = "ADMIN") void testAdminGetsResultsFromAllCourses() throws Exception { - final String uuid = UUID.randomUUID().toString(); - String searchTerm = "ClassDiagram" + uuid; + String searchTerm = "ClassDiagram testAdminGetsResultsFromAllCourses"; final var search = database.configureSearch(searchTerm); final var oldResult = request.getSearchResult("/api/modeling-exercises/", HttpStatus.OK, ModelingExercise.class, database.searchMapping(search)); database.addCourseInOtherInstructionGroupAndExercise(searchTerm); @@ -619,20 +617,19 @@ void testAdminGetsResultsFromAllCourses() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testCourseAndExamFiltersAsInstructor() throws Exception { - testCourseAndExamFilters(); + testCourseAndExamFilters("testCourseAndExamFiltersAsInstructor"); } @Test @WithMockUser(username = "admin", roles = "ADMIN") void testCourseAndExamFiltersAsAdmin() throws Exception { - testCourseAndExamFilters(); + testCourseAndExamFilters("testCourseAndExamFiltersAsAdmin"); } - private void testCourseAndExamFilters() throws Exception { - String randomString = UUID.randomUUID().toString(); - database.addCourseWithOneReleasedModelExerciseWithKnowledge(randomString); - database.addCourseExamExerciseGroupWithOneModelingExercise(randomString + "-Morpork"); - exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/modeling-exercises/", randomString); + private void testCourseAndExamFilters(String title) throws Exception { + database.addCourseWithOneReleasedModelExerciseWithKnowledge(title); + database.addCourseExamExerciseGroupWithOneModelingExercise(title + "-Morpork"); + exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/modeling-exercises/", title); } @Test @@ -687,7 +684,7 @@ void testImport_individual_modeChange() throws Exception { sourceExercise = modelingExerciseRepository.save(sourceExercise); var team = new Team(); - team.setShortName("t" + UUID.randomUUID().toString().substring(0, 3)); + team.setShortName(TEST_PREFIX + "testImport_individual_modeChange"); teamRepository.save(sourceExercise, team); var exerciseToBeImported = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course2); diff --git a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseIntegrationTestService.java b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseIntegrationTestService.java index b0495e4c58d9..6f9a10611ac4 100644 --- a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseIntegrationTestService.java +++ b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseIntegrationTestService.java @@ -17,7 +17,6 @@ import java.nio.file.Path; import java.time.ZonedDateTime; import java.util.*; -import java.util.concurrent.ThreadLocalRandom; import java.util.function.BiFunction; import java.util.stream.IntStream; import java.util.zip.ZipFile; @@ -2042,13 +2041,12 @@ private void testAuxRepo(AuxiliaryRepositoryBuilder body, HttpStatus expectedSta } private void testAuxRepo(List body, HttpStatus expectedStatus) throws Exception { - String uniqueExerciseTitle = String.format("Title%d%d", System.nanoTime(), ThreadLocalRandom.current().nextInt(100)); programmingExercise.setAuxiliaryRepositories(body); programmingExercise.setId(null); programmingExercise.setSolutionParticipation(null); programmingExercise.setTemplateParticipation(null); - programmingExercise.setShortName(uniqueExerciseTitle); - programmingExercise.setTitle(uniqueExerciseTitle); + programmingExercise.setShortName("ExerciseTitle"); + programmingExercise.setTitle("Title"); if (expectedStatus == HttpStatus.CREATED) { mockDelegate.mockConnectorRequestsForSetup(programmingExercise, false); mockDelegate.mockGetProjectKeyFromAnyUrl(programmingExercise.getProjectKey()); diff --git a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseServiceIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseServiceIntegrationTest.java index 1e886bef267e..1d552910a348 100644 --- a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseServiceIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseServiceIntegrationTest.java @@ -6,7 +6,6 @@ import java.time.ZonedDateTime; import java.util.Objects; -import java.util.UUID; import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; @@ -191,22 +190,21 @@ private void testSearchTermMatchesId() throws Exception { @ValueSource(booleans = { false, true }) @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testCourseAndExamFiltersAsInstructor(boolean withSCA) throws Exception { - testCourseAndExamFilters(withSCA); + testCourseAndExamFilters(withSCA, "testCourseAndExamFiltersAsInstructor" + withSCA); } @ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}") @ValueSource(booleans = { false, true }) @WithMockUser(username = "admin", roles = "ADMIN") void testCourseAndExamFiltersAsAdmin(boolean withSCA) throws Exception { - testCourseAndExamFilters(withSCA); + testCourseAndExamFilters(withSCA, "testCourseAndExamFiltersAsAdmin" + withSCA); } - private void testCourseAndExamFilters(boolean withSCA) throws Exception { - String randomString = UUID.randomUUID().toString(); - database.addCourseWithNamedProgrammingExerciseAndTestCases(randomString, withSCA); - database.addCourseExamExerciseGroupWithOneProgrammingExercise(randomString + "-Morpork", randomString + "Morpork"); - exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/programming-exercises/", randomString); - testSCAFilter(randomString, withSCA); + private void testCourseAndExamFilters(boolean withSCA, String programmingExerciseTitle) throws Exception { + database.addCourseWithNamedProgrammingExerciseAndTestCases(programmingExerciseTitle, withSCA); + database.addCourseExamExerciseGroupWithOneProgrammingExercise(programmingExerciseTitle + "-Morpork", programmingExerciseTitle + "Morpork"); + exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/programming-exercises/", programmingExerciseTitle); + testSCAFilter(programmingExerciseTitle, withSCA); } private void testSCAFilter(String searchTerm, boolean expectSca) throws Exception { diff --git a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseTestService.java b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseTestService.java index 0fa919f50ea3..f97da564808f 100644 --- a/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseTestService.java +++ b/src/test/java/de/tum/in/www1/artemis/programmingexercise/ProgrammingExerciseTestService.java @@ -787,7 +787,7 @@ void testImportProgrammingExercise_individual_modeChange() throws Exception { sourceExercise.setCourse(sourceExercise.getCourseViaExerciseGroupOrCourseMember()); programmingExerciseRepository.save(sourceExercise); var team = new Team(); - team.setShortName("t" + UUID.randomUUID().toString().substring(0, 3)); + team.setShortName("testImportProgrammingExercise_individual_modeChange"); teamRepository.save(sourceExercise, team); database.loadProgrammingExerciseWithEagerReferences(sourceExercise); diff --git a/src/test/java/de/tum/in/www1/artemis/programmingexercise/StaticCodeAnalysisIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/programmingexercise/StaticCodeAnalysisIntegrationTest.java index 04050875236a..36dc6655138c 100644 --- a/src/test/java/de/tum/in/www1/artemis/programmingexercise/StaticCodeAnalysisIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/programmingexercise/StaticCodeAnalysisIntegrationTest.java @@ -5,7 +5,6 @@ import java.time.ZonedDateTime; import java.util.List; import java.util.Set; -import java.util.concurrent.ThreadLocalRandom; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -329,10 +328,8 @@ void testImportCategories() throws Exception { var categories = staticCodeAnalysisCategoryRepository.findByExerciseId(sourceExercise.getId()); for (var category : categories) { category.setState(CategoryState.GRADED); - double rand1 = ThreadLocalRandom.current().nextDouble(10); - double rand2 = ThreadLocalRandom.current().nextDouble(10); - category.setMaxPenalty(Math.max(rand1, rand2)); - category.setPenalty(Math.min(rand1, rand2)); + category.setMaxPenalty(10.0); + category.setPenalty(5.0); } staticCodeAnalysisCategoryRepository.saveAll(categories); diff --git a/src/test/java/de/tum/in/www1/artemis/quiz/QuizExerciseIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/quiz/QuizExerciseIntegrationTest.java index 2250f27be5c6..94cd18b89639 100644 --- a/src/test/java/de/tum/in/www1/artemis/quiz/QuizExerciseIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/quiz/QuizExerciseIntegrationTest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.byLessThan; -import static org.junit.jupiter.api.Assertions.*; import java.security.Principal; import java.time.ZonedDateTime; @@ -834,30 +833,29 @@ private void testSearchTermMatchesId() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testCourseAndExamFiltersAsInstructor() throws Exception { - String randomString = setupFilterTestCase(); - exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/quiz-exercises/", randomString); + String exerciseTitle = setupFilterTestCase(TEST_PREFIX + "testCourseAndExamFiltersAsInstructor"); + exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/quiz-exercises/", exerciseTitle); } @Test @WithMockUser(username = "admin", roles = "ADMIN") void testCourseAndExamFiltersAsAdmin() throws Exception { - String randomString = setupFilterTestCase(); - exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/quiz-exercises/", randomString); + String exerciseTitle = setupFilterTestCase(TEST_PREFIX + "testCourseAndExamFiltersAsAdmin"); + exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/quiz-exercises/", exerciseTitle); } - private String setupFilterTestCase() { - String randomString = UUID.randomUUID().toString(); + private String setupFilterTestCase(String exerciseTitle) { ExerciseGroup exerciseGroup = database.addExerciseGroupWithExamAndCourse(true); quizExercise = database.createQuizForExam(exerciseGroup); - quizExercise.setTitle(randomString + "-Morpork"); + quizExercise.setTitle(exerciseTitle + "-Morpork"); quizExerciseRepository.save(quizExercise); final Course course = database.addEmptyCourse(); final var now = ZonedDateTime.now(); QuizExercise exercise = ModelFactory.generateQuizExercise(now.minusDays(1), now.minusHours(2), QuizMode.INDIVIDUAL, course); - exercise.setTitle(randomString); + exercise.setTitle(exerciseTitle); quizExerciseRepository.save(exercise); - return randomString; + return exerciseTitle; } @Test @@ -1683,7 +1681,7 @@ void testImportQuizExercise_individual_modeChange() throws Exception { quizExercise = quizExerciseService.save(quizExercise); var team = new Team(); - team.setShortName("t" + UUID.randomUUID().toString().substring(0, 3)); + team.setShortName(TEST_PREFIX + "testImportQuizExercise_individual_modeChange"); teamRepository.save(quizExercise, team); QuizExercise changedQuiz = quizExerciseRepository.findOneWithQuestionsAndStatistics(quizExercise.getId()); diff --git a/src/test/java/de/tum/in/www1/artemis/service/ParticipationTeamWebsocketServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/ParticipationTeamWebsocketServiceTest.java index 67ca143807f0..390782ff7f84 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/ParticipationTeamWebsocketServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/ParticipationTeamWebsocketServiceTest.java @@ -4,7 +4,6 @@ import static org.mockito.Mockito.*; import java.util.List; -import java.util.UUID; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -57,7 +56,7 @@ void tearDown() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") void testSubscribeToParticipationTeamWebsocketTopic() { - participationTeamWebsocketService.subscribe(participation.getId(), getStompHeaderAccessorMock()); + participationTeamWebsocketService.subscribe(participation.getId(), getStompHeaderAccessorMock("fakeSessionId")); verify(messagingTemplate, times(1)).convertAndSend(websocketTopic(participation), List.of()); assertThat(participationTeamWebsocketService.getDestinationTracker()).as("Session was added to destination tracker.").hasSize(1); assertThat(participationTeamWebsocketService.getDestinationTracker()).as("Destination in tracker is correct.").containsValue(websocketTopic(participation)); @@ -73,8 +72,8 @@ void testTriggerSendOnlineTeamMembers() { @Test @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") void testUnsubscribeFromParticipationTeamWebsocketTopic() { - StompHeaderAccessor stompHeaderAccessor1 = getStompHeaderAccessorMock(); - StompHeaderAccessor stompHeaderAccessor2 = getStompHeaderAccessorMock(); + StompHeaderAccessor stompHeaderAccessor1 = getStompHeaderAccessorMock("fakeSessionId1"); + StompHeaderAccessor stompHeaderAccessor2 = getStompHeaderAccessorMock("fakeSessionId2"); participationTeamWebsocketService.subscribe(participation.getId(), stompHeaderAccessor1); participationTeamWebsocketService.subscribe(participation.getId(), stompHeaderAccessor2); @@ -85,8 +84,7 @@ void testUnsubscribeFromParticipationTeamWebsocketTopic() { assertThat(participationTeamWebsocketService.getDestinationTracker()).as("Correct session was removed.").containsKey(stompHeaderAccessor2.getSessionId()); } - private StompHeaderAccessor getStompHeaderAccessorMock() { - String fakeSessionId = UUID.randomUUID().toString(); + private StompHeaderAccessor getStompHeaderAccessorMock(String fakeSessionId) { StompHeaderAccessor stompHeaderAccessor = mock(StompHeaderAccessor.class, RETURNS_MOCKS); when(stompHeaderAccessor.getSessionId()).thenReturn(fakeSessionId); return stompHeaderAccessor; diff --git a/src/test/java/de/tum/in/www1/artemis/service/TextAssessmentQueueServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/TextAssessmentQueueServiceTest.java index 62a3f4f9c0cf..d9a7d9cadc14 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/TextAssessmentQueueServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/TextAssessmentQueueServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.*; -import java.util.concurrent.ThreadLocalRandom; import org.assertj.core.data.Percentage; import org.junit.jupiter.api.BeforeEach; @@ -55,7 +54,7 @@ void init() { @Test void calculateAddedDistancesTest() { var textBlocks = new ArrayList<>(textExerciseUtilService.generateTextBlocks(4)); - TextCluster textCluster = addTextBlocksToRandomCluster(textBlocks, 1).get(0); + TextCluster textCluster = addTextBlocksToCluster(textBlocks).get(0); double[][] distanceMatrix = new double[][] { { 0, 0.1, 0.2, 0.3 }, { 0.1, 0, 0.4, 0.5 }, { 0.2, 0.4, 0, 0.6 }, { 0.3, 0.5, 0.6, 0 } }; textCluster.setDistanceMatrix(distanceMatrix); textAssessmentQueueService.setAddedDistances(textBlocks, textCluster); @@ -68,7 +67,7 @@ void calculateAddedDistancesTest() { @Test void testTextBlockProbabilities() { var textBlocks = new ArrayList<>(textExerciseUtilService.generateTextBlocks(4)); - TextCluster textCluster = addTextBlocksToRandomCluster(textBlocks, 1).get(0); + TextCluster textCluster = addTextBlocksToCluster(textBlocks).get(0); var probabilities = new double[] { 1.0d, 2.0d }; textCluster.setProbabilities(probabilities); assertThat(textCluster.getProbabilities()).isEqualTo(probabilities); @@ -120,13 +119,12 @@ else if (textBlock.getCluster() == clusters.get(3)) { }); } - private List addTextBlocksToRandomCluster(List textBlocks, int clusterCount) { + private List addTextBlocksToCluster(List textBlocks) { + var textCluster = new TextCluster(); ArrayList clusters = new ArrayList<>(); - for (int i = 0; i < clusterCount; i++) { - clusters.add(new TextCluster()); - } - // Add all text blocks to a random cluster - textBlocks.forEach(textBlock -> clusters.get(ThreadLocalRandom.current().nextInt(clusterCount)).addBlocks(textBlock)); + clusters.add(textCluster); + + textBlocks.forEach(textCluster::addBlocks); return clusters; } diff --git a/src/test/java/de/tum/in/www1/artemis/service/TitleCacheEvictionServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/TitleCacheEvictionServiceTest.java index 96a38b69889f..b385bebff2ae 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/TitleCacheEvictionServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/TitleCacheEvictionServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import java.util.UUID; import java.util.function.Supplier; import org.junit.jupiter.api.Test; @@ -57,13 +56,13 @@ void testEvictsTitleOnUpdateTitleOrDeleteCourse() { testCacheEvicted("courseTitle", () -> new Tuple<>(course.getId(), course.getTitle()), List.of( // Should evict as we change the title () -> { - course.setTitle(UUID.randomUUID().toString()); + course.setTitle("testEvictsTitleOnUpdateTitleOrDeleteCourse"); courseRepository.save(course); return true; }, // Should not evict as title remains the same () -> { - course.setDescription(UUID.randomUUID().toString()); // Change some other values + course.setDescription("testEvictsTitleOnUpdateTitleOrDeleteCourse"); // Change some other values courseRepository.save(course); return false; }, @@ -81,13 +80,13 @@ void testEvictsTitleOnUpdateTitleOrDeleteExercise() { testCacheEvicted("exerciseTitle", () -> new Tuple<>(exercise.getId(), exercise.getTitle()), List.of( // Should evict as we change the title () -> { - exercise.setTitle(UUID.randomUUID().toString()); + exercise.setTitle("testEvictsTitleOnUpdateTitleOrDeleteExercise"); exerciseRepository.save(exercise); return true; }, // Should not evict as title remains the same () -> { - exercise.setProblemStatement(UUID.randomUUID().toString()); // Change some other values + exercise.setProblemStatement("testEvictsTitleOnUpdateTitleOrDeleteExercise"); // Change some other values exerciseRepository.save(exercise); return false; }, @@ -104,13 +103,13 @@ void testEvictsTitleOnUpdateTitleOrDeleteLecture() { testCacheEvicted("lectureTitle", () -> new Tuple<>(lecture.getId(), lecture.getTitle()), List.of( // Should evict as we change the title () -> { - lecture.setTitle(UUID.randomUUID().toString()); + lecture.setTitle("testEvictsTitleOnUpdateTitleOrDeleteLecture"); lectureRepository.save(lecture); return true; }, // Should not evict as title remains the same () -> { - lecture.setDescription(UUID.randomUUID().toString()); // Change some other values + lecture.setDescription("testEvictsTitleOnUpdateTitleOrDeleteLecture"); // Change some other values lectureRepository.save(lecture); return false; }, @@ -127,13 +126,13 @@ void testEvictsTitleOnUpdateNameOrDeleteOrganization() { testCacheEvicted("organizationTitle", () -> new Tuple<>(org.getId(), org.getName()), List.of( // Should evict as we change the name () -> { - org.setName(UUID.randomUUID().toString()); + org.setName("testEvictsTitleOnUpdateNameOrDeleteOrganization"); organizationRepository.save(org); return true; }, // Should not evict as name remains the same () -> { - org.setDescription(UUID.randomUUID().toString()); // Change some other values + org.setDescription("testEvictsTitleOnUpdateNameOrDeleteOrganization"); // Change some other values organizationRepository.save(org); return false; }, @@ -150,7 +149,7 @@ void testEvictsTitleOnUpdateTitleOrDeleteApollonDiagram() { testCacheEvicted("diagramTitle", () -> new Tuple<>(apollonDiagram.getId(), apollonDiagram.getTitle()), List.of( // Should evict as we change the title () -> { - apollonDiagram.setTitle(UUID.randomUUID().toString()); + apollonDiagram.setTitle("testEvictsTitleOnUpdateTitleOrDeleteApollonDiagram"); apollonDiagramRepository.save(apollonDiagram); return true; }, @@ -174,13 +173,13 @@ void testEvictsTitleOnUpdateTitleOrDeleteExam() { testCacheEvicted("examTitle", () -> new Tuple<>(exam.getId(), exam.getTitle()), List.of( // Should evict as we change the title () -> { - exam.setTitle(UUID.randomUUID().toString()); + exam.setTitle("testEvictsTitleOnUpdateTitleOrDeleteExam"); examRepository.save(exam); return true; }, // Should not evict as title remains the same () -> { - exam.setConfirmationEndText(UUID.randomUUID().toString()); // Change some other values + exam.setConfirmationEndText("testEvictsTitleOnUpdateTitleOrDeleteExam"); // Change some other values examRepository.save(exam); return false; }, @@ -200,20 +199,20 @@ void testEvictsTitleOnUpdateTitleOrDeleteExerciseHint() { testCacheEvicted("exerciseHintTitle", () -> new Tuple<>(exercise.getId() + "-" + hint.getId(), hint.getTitle()), List.of( // Should evict as we change the title () -> { - hint.setTitle(UUID.randomUUID().toString()); + hint.setTitle("testEvictsTitleOnUpdateTitleOrDeleteExerciseHint"); exerciseHintRepository.save(hint); return true; }, // Should not evict as title remains the same () -> { - hint.setDescription(UUID.randomUUID().toString()); // Change some other values + hint.setDescription("testEvictsTitleOnUpdateTitleOrDeleteExerciseHint"); // Change some other values exerciseHintRepository.save(hint); return false; }, // Should not do something if the exercise is missing () -> { hint.setExercise(null); - hint.setTitle(UUID.randomUUID().toString()); + hint.setTitle("testEvictsTitleOnUpdateTitleOrDeleteExerciseHint"); exerciseHintRepository.save(hint); return false; }, diff --git a/src/test/java/de/tum/in/www1/artemis/service/notifications/TutorialGroupNotificationServiceTest.java b/src/test/java/de/tum/in/www1/artemis/service/notifications/TutorialGroupNotificationServiceTest.java index 74b2a92c4a4a..551a66583f67 100644 --- a/src/test/java/de/tum/in/www1/artemis/service/notifications/TutorialGroupNotificationServiceTest.java +++ b/src/test/java/de/tum/in/www1/artemis/service/notifications/TutorialGroupNotificationServiceTest.java @@ -5,7 +5,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; -import java.security.SecureRandom; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -68,7 +67,7 @@ void setUp() { Course course = this.database.createCourse(); student1 = userRepository.findOneByLogin(TEST_PREFIX + "student1").get(); tutor1 = userRepository.findOneByLogin(TEST_PREFIX + "tutor1").get(); - tutorialGroup = createAndSaveTutorialGroup(course.getId(), new SecureRandom().nextInt(1000000000) + "", "LoremIpsum1", 10, false, "LoremIpsum1", Language.ENGLISH, + tutorialGroup = createAndSaveTutorialGroup(course.getId(), "title" + course.getId(), "LoremIpsum1", 10, false, "LoremIpsum1", Language.ENGLISH, userRepository.findOneByLogin(TEST_PREFIX + "tutor1").get(), Set.of(userRepository.findOneByLogin(TEST_PREFIX + "student1").get(), userRepository.findOneByLogin(TEST_PREFIX + "student2").get(), userRepository.findOneByLogin(TEST_PREFIX + "student3").get(), userRepository.findOneByLogin(TEST_PREFIX + "student4").get(), diff --git a/src/test/java/de/tum/in/www1/artemis/text/TextExerciseIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/text/TextExerciseIntegrationTest.java index e585583dd705..afc9c4e3eafb 100644 --- a/src/test/java/de/tum/in/www1/artemis/text/TextExerciseIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/text/TextExerciseIntegrationTest.java @@ -769,23 +769,22 @@ void testInstructorGetsOnlyResultsFromOwningCourses() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testInstructorGetResultsFromOwningCoursesNotEmpty() throws Exception { - String randomString = UUID.randomUUID().toString(); - String randomString2 = UUID.randomUUID().toString(); + String courseBaseTitle1 = "testInstructorGetResultsFromOwningCoursesNotEmpty 1"; + String courseBaseTitle2 = "testInstructorGetResultsFromOwningCoursesNotEmpty 2"; - database.addCourseWithOneReleasedTextExercise(randomString); - database.addCourseWithOneReleasedTextExercise(randomString2 + " Bachelor"); - database.addCourseWithOneReleasedTextExercise(randomString2 + "Master"); + database.addCourseWithOneReleasedTextExercise(courseBaseTitle1); + database.addCourseWithOneReleasedTextExercise(courseBaseTitle2 + "Bachelor"); + database.addCourseWithOneReleasedTextExercise(courseBaseTitle2 + "Master"); - final var searchText = database.configureSearch(randomString); + final var searchText = database.configureSearch(courseBaseTitle1); final var resultText = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchText)); assertThat(resultText.getResultsOnPage()).hasSize(1); - final var searchEssay = database.configureSearch(randomString2); + final var searchEssay = database.configureSearch(courseBaseTitle2); final var resultEssay = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchEssay)); assertThat(resultEssay.getResultsOnPage()).hasSize(2); - String randomString3 = UUID.randomUUID().toString(); - final var searchNon = database.configureSearch(randomString3); + final var searchNon = database.configureSearch("No course has this name"); final var resultNon = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchNon)); assertThat(resultNon.getResultsOnPage()).isNullOrEmpty(); } @@ -793,20 +792,19 @@ void testInstructorGetResultsFromOwningCoursesNotEmpty() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testCourseAndExamFiltersAsInstructor() throws Exception { - testCourseAndExamFilters(); + testCourseAndExamFilters("testCourseAndExamFiltersAsInstructor"); } @Test @WithMockUser(username = "admin", roles = "ADMIN") void testCourseAndExamFiltersAsAdmin() throws Exception { - testCourseAndExamFilters(); + testCourseAndExamFilters("testCourseAndExamFiltersAsAdmin"); } - private void testCourseAndExamFilters() throws Exception { - String randomString = UUID.randomUUID().toString(); - database.addCourseWithOneReleasedTextExercise(randomString); - database.addCourseExamExerciseGroupWithOneTextExercise(randomString + "-Morpork"); - exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/text-exercises", randomString); + private void testCourseAndExamFilters(String courseTitle) throws Exception { + database.addCourseWithOneReleasedTextExercise(courseTitle); + database.addCourseExamExerciseGroupWithOneTextExercise(courseTitle + "-Morpork"); + exerciseIntegrationTestUtils.testCourseAndExamFilters("/api/text-exercises", courseTitle); } @Test @@ -848,23 +846,22 @@ void testInstructorGetsOnlyResultsFromOwningExams() throws Exception { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testInstructorGetResultsFromOwningExamsNotEmpty() throws Exception { - String randomString = UUID.randomUUID().toString(); - String randomString2 = UUID.randomUUID().toString(); + String exerciseBaseTitle1 = "testInstructorGetResultsFromOwningExamsNotEmpty 1"; + String exerciseBaseTitle2 = "testInstructorGetResultsFromOwningExamsNotEmpty 2"; - database.addCourseExamExerciseGroupWithOneTextExercise(randomString); - database.addCourseExamExerciseGroupWithOneTextExercise(randomString2 + "Bachelor"); - database.addCourseExamExerciseGroupWithOneTextExercise(randomString2 + "Master"); + database.addCourseExamExerciseGroupWithOneTextExercise(exerciseBaseTitle1); + database.addCourseExamExerciseGroupWithOneTextExercise(exerciseBaseTitle2 + "Bachelor"); + database.addCourseExamExerciseGroupWithOneTextExercise(exerciseBaseTitle2 + "Master"); - final var searchText = database.configureSearch(randomString); + final var searchText = database.configureSearch(exerciseBaseTitle1); final var resultText = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchText)); assertThat(resultText.getResultsOnPage()).hasSize(1); - final var searchEssay = database.configureSearch(randomString2); + final var searchEssay = database.configureSearch(exerciseBaseTitle2); final var resultEssay = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchEssay)); assertThat(resultEssay.getResultsOnPage()).hasSize(2); - String randomString3 = UUID.randomUUID().toString(); - final var searchNon = database.configureSearch(randomString3); + final var searchNon = database.configureSearch("No exam has this name"); final var resultNon = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(searchNon)); assertThat(resultNon.getResultsOnPage()).isNullOrEmpty(); } @@ -872,14 +869,14 @@ void testInstructorGetResultsFromOwningExamsNotEmpty() throws Exception { @Test @WithMockUser(username = "admin", roles = "ADMIN") void testAdminGetsResultsFromAllCourses() throws Exception { - String randomString = UUID.randomUUID().toString(); + String courseTitle = "testAdminGetsResultsFromAllCourses"; - database.addCourseWithOneReleasedTextExercise(randomString); - Course otherInstructorsCourse = database.addCourseWithOneReleasedTextExercise(randomString); + database.addCourseWithOneReleasedTextExercise(courseTitle); + Course otherInstructorsCourse = database.addCourseWithOneReleasedTextExercise(courseTitle); otherInstructorsCourse.setInstructorGroupName("other-instructors"); courseRepository.save(otherInstructorsCourse); - final var search = database.configureSearch(randomString); + final var search = database.configureSearch(courseTitle); final var result = request.getSearchResult("/api/text-exercises", HttpStatus.OK, TextExercise.class, database.searchMapping(search)); assertThat(result.getResultsOnPage()).hasSize(2); } @@ -936,7 +933,7 @@ void testImportTextExercise_individual_modeChange() throws Exception { sourceExercise = textExerciseRepository.save(sourceExercise); var team = new Team(); - team.setShortName("t" + UUID.randomUUID().toString().substring(0, 3)); + team.setShortName("testImportTextExercise_individual_modeChange"); teamRepository.save(sourceExercise, team); var exerciseToBeImported = new TextExercise(); diff --git a/src/test/java/de/tum/in/www1/artemis/tutorialgroups/AbstractTutorialGroupIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/tutorialgroups/AbstractTutorialGroupIntegrationTest.java index a7ddffbc169a..ae7c670e6e3e 100644 --- a/src/test/java/de/tum/in/www1/artemis/tutorialgroups/AbstractTutorialGroupIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/tutorialgroups/AbstractTutorialGroupIntegrationTest.java @@ -3,7 +3,6 @@ import static de.tum.in.www1.artemis.tutorialgroups.AbstractTutorialGroupIntegrationTest.RandomTutorialGroupGenerator.generateRandomTitle; import static org.assertj.core.api.Assertions.assertThat; -import java.security.SecureRandom; import java.time.LocalDate; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -333,7 +332,7 @@ public static class RandomTutorialGroupGenerator { private static final String ALL_CHARS = LOWERCASE_LETTERS + NUMBERS; - private static final SecureRandom RANDOM = new SecureRandom(); + private static final Random RANDOM = new Random(1042001L); public static String generateRandomTitle() { StringBuilder sb = new StringBuilder(); diff --git a/src/test/java/de/tum/in/www1/artemis/tutorialgroups/TutorialGroupIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/tutorialgroups/TutorialGroupIntegrationTest.java index 9beba226158b..05668315c7d9 100644 --- a/src/test/java/de/tum/in/www1/artemis/tutorialgroups/TutorialGroupIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/tutorialgroups/TutorialGroupIntegrationTest.java @@ -6,7 +6,6 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.security.SecureRandom; import java.time.LocalDate; import java.util.*; @@ -50,14 +49,12 @@ void setupTestScenario() { } // Add registration number to student 3 User student3 = userRepository.findOneByLogin(testPrefix + "student3").get(); - // random number with maximal 20 digits - student3.setRegistrationNumber(new SecureRandom().nextInt(1000000000) + ""); + student3.setRegistrationNumber("3"); userRepository.save(student3); // Add registration number to student 4 User student4 = userRepository.findOneByLogin(testPrefix + "student4").get(); - // random number with maximal 20 digits - student4.setRegistrationNumber(new SecureRandom().nextInt(1000000000) + ""); + student4.setRegistrationNumber("4"); userRepository.save(student4); var course = this.database.createCourse(); diff --git a/src/test/java/de/tum/in/www1/artemis/util/CourseTestService.java b/src/test/java/de/tum/in/www1/artemis/util/CourseTestService.java index f0ff63f665f0..577165abcc4a 100644 --- a/src/test/java/de/tum/in/www1/artemis/util/CourseTestService.java +++ b/src/test/java/de/tum/in/www1/artemis/util/CourseTestService.java @@ -508,7 +508,7 @@ public void testCreateCourseWithDefaultChannels() throws Exception { // Test public void testUpdateCourseIsEmpty() throws Exception { - Course course = ModelFactory.generateCourse(UUID.randomUUID().getLeastSignificantBits(), null, null, new HashSet<>()); + Course course = ModelFactory.generateCourse(1042001L, null, null, new HashSet<>()); request.getMvc().perform(buildCreateCourse(course)).andExpect(status().isBadRequest()); } diff --git a/src/test/java/de/tum/in/www1/artemis/util/TextExerciseUtilService.java b/src/test/java/de/tum/in/www1/artemis/util/TextExerciseUtilService.java index d70e505b7e73..4d030882b687 100644 --- a/src/test/java/de/tum/in/www1/artemis/util/TextExerciseUtilService.java +++ b/src/test/java/de/tum/in/www1/artemis/util/TextExerciseUtilService.java @@ -32,8 +32,6 @@ public class TextExerciseUtilService { @Autowired private UserRepository userRepository; - private final Random random = new Random(); - /** * Generate a set of specified size containing TextBlocks with dummy Text * @@ -60,7 +58,7 @@ public Set generateTextBlocks(int count) { public Set generateTextBlocksWithIdenticalTexts(int count) { Set textBlocks = new HashSet<>(); TextBlock textBlock; - String text = "TextBlock" + random.nextInt(); + String text = "TextBlock"; for (int i = 0; i < count; i++) { String blockId = sha1Hex("id" + i + text); @@ -74,7 +72,7 @@ public Set generateTextBlocksWithIdenticalTexts(int count) { } /** - * Create n TextClusters and randomly assign TextBlocks to new clusters. + * Create n TextClusters and assign TextBlocks to new clusters. * * @param textBlocks TextBlocks to fake cluster * @param clusterSizes Number of new clusters @@ -88,18 +86,19 @@ public List addTextBlocksToCluster(Set textBlocks, int[] List clusters = createClustersForExercise(clusterSizes, textExercise); - // Add all textblocks to a random cluster - textBlocks.forEach(textBlock -> { - int clusterIndex; + // Add all textblocks to a cluster + int clusterIndex = 0; + for (var textBlock : textBlocks) { // as long as cluster is full select another cluster do { - clusterIndex = random.nextInt(clusterSizes.length); + clusterIndex = (clusterIndex + 1) % clusterSizes.length; } while (clusterSizes[clusterIndex] == 0); clusterSizes[clusterIndex]--; clusters.get(clusterIndex).addBlocks(textBlock); - }); + } + return clusters; }