diff --git a/src/test/java/de/tum/cit/aet/artemis/core/connector/JenkinsRequestMockProvider.java b/src/test/java/de/tum/cit/aet/artemis/core/connector/JenkinsRequestMockProvider.java index c0f686cac851..dfcf83718a84 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/connector/JenkinsRequestMockProvider.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/connector/JenkinsRequestMockProvider.java @@ -7,10 +7,8 @@ import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; @@ -545,11 +543,11 @@ public void mockGetBuildStatus(String projectKey, String planName, boolean planE return; } - var jobWithDetails = mock(JenkinsJobService.JobWithDetails.class); + boolean isQueued = planIsActive && !planIsBuilding; + var jobWithDetails = new JenkinsJobService.JobWithDetails(planName, "", isQueued); mockGetJob(projectKey, planName, jobWithDetails, false); - if (planIsActive && !planIsBuilding) { - doReturn(true).when(jobWithDetails).inQueue(); + if (isQueued) { return; } diff --git a/src/test/java/de/tum/cit/aet/artemis/programming/service/JenkinsServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/programming/service/JenkinsServiceTest.java index 6f1abb9600e3..4f6e8a81ae9e 100644 --- a/src/test/java/de/tum/cit/aet/artemis/programming/service/JenkinsServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/programming/service/JenkinsServiceTest.java @@ -11,7 +11,6 @@ import java.io.IOException; import java.io.InputStream; -import java.net.URISyntaxException; import java.util.Optional; import org.junit.jupiter.api.AfterEach; @@ -228,7 +227,7 @@ void testFailToUpdatePlanRepositoryInternalError() throws Exception { testFailToUpdatePlanRepositoryRestClientException(HttpStatus.INTERNAL_SERVER_ERROR); } - private void testFailToUpdatePlanRepositoryRestClientException(HttpStatus expectedStatus) throws IOException, URISyntaxException { + private void testFailToUpdatePlanRepositoryRestClientException(HttpStatus expectedStatus) throws IOException { var programmingExercise = continuousIntegrationTestService.programmingExercise; programmingExerciseUtilService.addTemplateParticipationForProgrammingExercise(programmingExercise); programmingExerciseUtilService.addSolutionParticipationForProgrammingExercise(programmingExercise); @@ -312,6 +311,8 @@ void testCopyLegacyBuildPlan() throws IOException { ProgrammingExercise sourceExercise = new ProgrammingExercise(); course.addExercises(sourceExercise); + sourceExercise.setShortName("source"); + sourceExercise.generateAndSetProjectKey(); var buildConfig = new ProgrammingExerciseBuildConfig(); sourceExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(buildConfig)); sourceExercise = programmingExerciseRepository.save(sourceExercise); @@ -321,13 +322,15 @@ void testCopyLegacyBuildPlan() throws IOException { ProgrammingExercise targetExercise = new ProgrammingExercise(); course.addExercises(targetExercise); + targetExercise.setShortName("target"); targetExercise.generateAndSetProjectKey(); var buildConfigTarget = new ProgrammingExerciseBuildConfig(); targetExercise.setBuildConfig(programmingExerciseBuildConfigRepository.save(buildConfigTarget)); targetExercise = programmingExerciseRepository.save(targetExercise); - jenkinsRequestMockProvider.mockCopyBuildPlanFromTemplate(sourceExercise.getProjectKey(), targetExercise.getProjectKey(), ""); + String targetPlanName = targetExercise.getProjectKey() + "-" + TEMPLATE.getName(); + jenkinsRequestMockProvider.mockCopyBuildPlanFromTemplate(sourceExercise.getProjectKey(), targetExercise.getProjectKey(), targetPlanName); - continuousIntegrationService.copyBuildPlan(sourceExercise, "", targetExercise, "", "", true); + continuousIntegrationService.copyBuildPlan(sourceExercise, TEMPLATE.getName(), targetExercise, targetExercise.getProjectName(), TEMPLATE.getName(), true); Optional targetBuildPlan = buildPlanRepository.findByProgrammingExercises_IdWithProgrammingExercises(targetExercise.getId()); assertThat(targetBuildPlan).isEmpty();