From edf1c6d87d8145ebc48e60db2db22773b253958e Mon Sep 17 00:00:00 2001 From: entholzer Date: Mon, 11 Nov 2024 18:46:32 +0100 Subject: [PATCH 1/2] remove mocking of getCloneRepositoryUri, as it is not needed and breaks auxiliary repo tests. Added mock to the _1_ test which actually needs it --- ...grammingIntegrationLocalCILocalVCTest.java | 3 ++ ...rammingExerciseIntegrationTestService.java | 25 +++++-------- ...rammingExerciseLocalVCIntegrationTest.java | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/AbstractProgrammingIntegrationLocalCILocalVCTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/AbstractProgrammingIntegrationLocalCILocalVCTest.java index fcbdc0bdef78..56adec3eb361 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/AbstractProgrammingIntegrationLocalCILocalVCTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/AbstractProgrammingIntegrationLocalCILocalVCTest.java @@ -52,6 +52,9 @@ public abstract class AbstractProgrammingIntegrationLocalCILocalVCTest extends A // External Repositories // Services + @Autowired + protected ProgrammingExerciseIntegrationTestService programmingExerciseIntegrationTestService; + @Autowired protected AeolusRequestMockProvider aeolusRequestMockProvider; diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java index d35b974e32c7..c3c22b8b147e 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.reset; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -292,10 +293,6 @@ void setup(String userPrefix, MockDelegate mockDelegate, VersionControlService v GitService.commit(localGit).setMessage("empty").setAllowEmpty(true).setSign(false).setAuthor("test", "test@test.com").call(); localGit.push().call(); - // we use the temp repository as remote origin for all repositories that are created during the - // TODO: distinguish between template, test and solution - doReturn(new GitUtilService.MockFileRepositoryUri(remoteRepoFile)).when(versionControlService).getCloneRepositoryUri(anyString(), anyString()); - this.plagiarismChecksTestReposDir = Files.createTempDirectory("jplag-repos").toFile(); } @@ -1433,6 +1430,8 @@ void importProgrammingExercise_vcsProjectWithSameTitleAlreadyExists_badRequest() } void importProgrammingExercise_updatesTestCaseIds() throws Exception { + doReturn(new GitUtilService.MockFileRepositoryUri(remoteRepoFile)).when(versionControlService).getCloneRepositoryUri(anyString(), anyString()); + programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationAndAuxiliaryRepositoriesElseThrow(programmingExercise.getId()); var tests = programmingExerciseUtilService.addTestCasesToProgrammingExercise(programmingExercise); var test1 = tests.getFirst(); @@ -1464,6 +1463,8 @@ void importProgrammingExercise_updatesTestCaseIds() throws Exception { var savedProgrammingExercise = programmingExerciseRepository.findByIdElseThrow(response.getId()); assertThat(savedProgrammingExercise.getProblemStatement()).isEqualTo(newProblemStatement); + + reset(versionControlService); } void exportSubmissionsByStudentLogins_notInstructorForExercise_forbidden() throws Exception { @@ -1920,7 +1921,7 @@ void testGetPlagiarismResultWithoutExercise() throws Exception { void testValidateValidAuxiliaryRepository() throws Exception { AuxiliaryRepositoryBuilder auxRepoBuilder = AuxiliaryRepositoryBuilder.defaults(); - testAuxRepo(auxRepoBuilder, HttpStatus.CREATED); + testAuxRepo(auxRepoBuilder, HttpStatus.OK); } void testValidateAuxiliaryRepositoryIdSetOnRequest() throws Exception { @@ -2158,7 +2159,7 @@ public void addAuxiliaryRepositoryToExercise(ProgrammingExercise exercise) { } private String defaultAuxiliaryRepositoryEndpoint() { - return "/api/programming-exercises/setup"; + return "/api/programming-exercises"; } private String defaultResetEndpoint() { @@ -2191,17 +2192,7 @@ private void testAuxRepo(AuxiliaryRepositoryBuilder body, HttpStatus expectedSta private void testAuxRepo(List body, HttpStatus expectedStatus) throws Exception { programmingExercise.setAuxiliaryRepositories(body); - programmingExercise.setId(null); - programmingExercise.setSolutionParticipation(null); - programmingExercise.setTemplateParticipation(null); - programmingExercise.setChannelName("pe-test"); - programmingExercise.setShortName("ExerciseTitle"); - programmingExercise.setTitle("Title"); - if (expectedStatus == HttpStatus.CREATED) { - mockDelegate.mockConnectorRequestsForSetup(programmingExercise, false, false, false); - mockDelegate.mockGetProjectKeyFromAnyUrl(programmingExercise.getProjectKey()); - } - request.postWithResponseBody(defaultAuxiliaryRepositoryEndpoint(), programmingExercise, ProgrammingExercise.class, expectedStatus); + request.putWithResponseBody(defaultAuxiliaryRepositoryEndpoint(), programmingExercise, ProgrammingExercise.class, expectedStatus); } private static class AuxiliaryRepositoryBuilder { diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java new file mode 100644 index 000000000000..9e3f375db4f0 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java @@ -0,0 +1,35 @@ +package de.tum.cit.aet.artemis.programming; + +import java.io.IOException; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.security.test.context.support.WithMockUser; + +class ProgrammingExerciseLocalVCIntegrationTest extends AbstractProgrammingIntegrationLocalCILocalVCTest { + + private static final String TEST_PREFIX = "programmingexerciselocalvc"; + + @BeforeEach + void initTestCase() throws Exception { + programmingExerciseIntegrationTestService.setup(TEST_PREFIX, this, versionControlService, continuousIntegrationService); + } + + @AfterEach + void tearDown() throws IOException { + programmingExerciseIntegrationTestService.tearDown(); + } + + protected String getTestPrefix() { + return TEST_PREFIX; + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void firstTest() throws Exception { + programmingExerciseIntegrationTestService.testValidateValidAuxiliaryRepository(); + } + + // TODO add all other tests +} From 36aedef8ce515d0ad0d714b6e64e01367647f470 Mon Sep 17 00:00:00 2001 From: entholzer Date: Tue, 12 Nov 2024 15:16:06 +0100 Subject: [PATCH 2/2] re-added more tests --- ...gExerciseIntegrationJenkinsGitlabTest.java | 18 ++ ...rammingExerciseIntegrationTestService.java | 12 +- ...rammingExerciseLocalVCIntegrationTest.java | 170 +++++++++++++++++- 3 files changed, 193 insertions(+), 7 deletions(-) diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationJenkinsGitlabTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationJenkinsGitlabTest.java index 5812c2923e0e..4646464e8458 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationJenkinsGitlabTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationJenkinsGitlabTest.java @@ -74,6 +74,18 @@ void testExportSubmissionsByParticipationIds_includePracticeSubmissions() throws programmingExerciseIntegrationTestService.testExportSubmissionsByParticipationIds_includePracticeSubmissions(); } + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testExportSubmissionsByParticipationIds_addParticipantIdentifierToProjectNameError() throws Exception { + programmingExerciseIntegrationTestService.testExportSubmissionsByParticipationIds_addParticipantIdentifierToProjectNameError(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testExportSubmissionsByParticipationIds_addParticipantIdentifierToProjectName() throws Exception { + programmingExerciseIntegrationTestService.testExportSubmissionsByParticipationIds_addParticipantIdentifierToProjectName(); + } + @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") void testExportSubmissionsByParticipationIds() throws Exception { @@ -562,6 +574,12 @@ void createProgrammingExercise_projectTypeNotExpected_badRequest() throws Except programmingExerciseIntegrationTestService.createProgrammingExercise_projectTypeNotExpected_badRequest(); } + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void createProgrammingExercise_onlineCodeEditorNotExpected_badRequest() throws Exception { + programmingExerciseIntegrationTestService.createProgrammingExercise_onlineCodeEditorNotExpected_badRequest(); + } + private static Set generateSupportedLanguagesWithoutHaskell() { Set supportedLanguages = ArgumentSources.generateJenkinsSupportedLanguages(); supportedLanguages.remove(ProgrammingLanguage.HASKELL); diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java index c3c22b8b147e..6b716d45b5a9 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseIntegrationTestService.java @@ -1925,7 +1925,7 @@ void testValidateValidAuxiliaryRepository() throws Exception { } void testValidateAuxiliaryRepositoryIdSetOnRequest() throws Exception { - testAuxRepo(AuxiliaryRepositoryBuilder.defaults().withId(0L), HttpStatus.BAD_REQUEST); + testAuxRepo(AuxiliaryRepositoryBuilder.defaults().withId(0L), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -1954,12 +1954,12 @@ void testValidateAuxiliaryRepositoryWithInvalidCheckoutDirectory() throws Except void testValidateAuxiliaryRepositoryWithoutCheckoutDirectory() throws Exception { AuxiliaryRepositoryBuilder auxRepoBuilder = AuxiliaryRepositoryBuilder.defaults().withoutCheckoutDirectory(); - testAuxRepo(auxRepoBuilder, HttpStatus.CREATED); + testAuxRepo(auxRepoBuilder, HttpStatus.OK); } void testValidateAuxiliaryRepositoryWithBlankCheckoutDirectory() throws Exception { AuxiliaryRepositoryBuilder auxRepoBuilder = AuxiliaryRepositoryBuilder.defaults().withCheckoutDirectory(" "); - testAuxRepo(auxRepoBuilder, HttpStatus.CREATED); + testAuxRepo(auxRepoBuilder, HttpStatus.OK); } void testValidateAuxiliaryRepositoryWithTooLongCheckoutDirectory() throws Exception { @@ -1982,7 +1982,7 @@ void testValidateAuxiliaryRepositoryWithTooLongDescription() throws Exception { void testValidateAuxiliaryRepositoryWithoutDescription() throws Exception { AuxiliaryRepositoryBuilder auxRepoBuilder = AuxiliaryRepositoryBuilder.defaults().withoutDescription(); - testAuxRepo(auxRepoBuilder, HttpStatus.CREATED); + testAuxRepo(auxRepoBuilder, HttpStatus.OK); } void testGetAuxiliaryRepositoriesMissingExercise() throws Exception { @@ -2266,8 +2266,8 @@ AuxiliaryRepository get() { } } - void testReEvaluateAndUpdateProgrammingExercise_instructorNotInCourse_forbidden() throws Exception { - userUtilService.addInstructor("other-instructors", userPrefix + "instructoralt"); + void testReEvaluateAndUpdateProgrammingExercise_instructorNotInCourse_forbidden(String testPrefix) throws Exception { + userUtilService.addInstructor("other-instructors", testPrefix + "instructoralt"); programmingExerciseUtilService.addCourseWithOneProgrammingExercise(); ProgrammingExercise programmingExercise = programmingExerciseTestRepository.findAllWithEagerTemplateAndSolutionParticipations().getFirst(); request.put("/api/programming-exercises/" + programmingExercise.getId() + "/re-evaluate", programmingExercise, HttpStatus.FORBIDDEN); diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java index 9e3f375db4f0..0194806e6028 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/ProgrammingExerciseLocalVCIntegrationTest.java @@ -27,9 +27,177 @@ protected String getTestPrefix() { @Test @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") - void firstTest() throws Exception { + void testValidateValidAuxiliaryRepository() throws Exception { programmingExerciseIntegrationTestService.testValidateValidAuxiliaryRepository(); } + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryIdSetOnRequest() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryIdSetOnRequest(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithoutName() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithoutName(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithTooLongName() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithTooLongName(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithDuplicatedName() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithDuplicatedName(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithRestrictedName() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithRestrictedName(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithInvalidCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithInvalidCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithoutCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithoutCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithBlankCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithBlankCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithTooLongCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithTooLongCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithDuplicatedCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithDuplicatedCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithNullCheckoutDirectory() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithNullCheckoutDirectory(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithTooLongDescription() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithTooLongDescription(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testValidateAuxiliaryRepositoryWithoutDescription() throws Exception { + programmingExerciseIntegrationTestService.testValidateAuxiliaryRepositoryWithoutDescription(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testGetAuxiliaryRepositoriesMissingExercise() throws Exception { + programmingExerciseIntegrationTestService.testGetAuxiliaryRepositoriesMissingExercise(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testGetAuxiliaryRepositoriesOk() throws Exception { + programmingExerciseIntegrationTestService.testGetAuxiliaryRepositoriesOk(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testGetAuxiliaryRepositoriesEmptyOk() throws Exception { + programmingExerciseIntegrationTestService.testGetAuxiliaryRepositoriesEmptyOk(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") + void testGetAuxiliaryRepositoriesForbidden() throws Exception { + programmingExerciseIntegrationTestService.testGetAuxiliaryRepositoriesForbidden(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") + void testExportAuxiliaryRepositoryForbidden() throws Exception { + programmingExerciseIntegrationTestService.testExportAuxiliaryRepositoryForbidden(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testExportAuxiliaryRepositoryBadRequest() throws Exception { + programmingExerciseIntegrationTestService.testExportAuxiliaryRepositoryBadRequest(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testExportAuxiliaryRepositoryExerciseNotFound() throws Exception { + programmingExerciseIntegrationTestService.testExportAuxiliaryRepositoryExerciseNotFound(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testExportAuxiliaryRepositoryRepositoryNotFound() throws Exception { + programmingExerciseIntegrationTestService.testExportAuxiliaryRepositoryRepositoryNotFound(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructoralt1", roles = "INSTRUCTOR") + void testReEvaluateAndUpdateProgrammingExercise_instructorNotInCourse_forbidden() throws Exception { + programmingExerciseIntegrationTestService.testReEvaluateAndUpdateProgrammingExercise_instructorNotInCourse_forbidden(TEST_PREFIX); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testReEvaluateAndUpdateProgrammingExercise_notFound() throws Exception { + programmingExerciseIntegrationTestService.testReEvaluateAndUpdateProgrammingExercise_notFound(); + } + + @Test + @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + void testReEvaluateAndUpdateProgrammingExercise_isNotSameGivenExerciseIdInRequestBody_conflict() throws Exception { + programmingExerciseIntegrationTestService.testReEvaluateAndUpdateProgrammingExercise_isNotSameGivenExerciseIdInRequestBody_conflict(); + } + // + // @Test + // @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + // void test_redirectGetSolutionRepositoryFilesWithoutContent() throws Exception { + // programmingExerciseIntegrationTestService.test_redirectGetSolutionRepositoryFilesWithoutContent(); + // } + // + // @Test + // @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + // void test_redirectGetTemplateRepositoryFilesWithContent() throws Exception { + // programmingExerciseIntegrationTestService.test_redirectGetTemplateRepositoryFilesWithContent(); + // } + // + // @Test + // @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + // void testRedirectGetParticipationRepositoryFilesWithContentAtCommit() throws Exception { + // programmingExerciseIntegrationTestService.testRedirectGetParticipationRepositoryFilesWithContentAtCommit(); + // } + // + // @Test + // @WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR") + // void testRedirectGetParticipationRepositoryFilesWithContentAtCommitForbidden() throws Exception { + // programmingExerciseIntegrationTestService.testRedirectGetParticipationRepositoryFilesWithContentAtCommitForbidden(); + // } + // TODO add all other tests }