Skip to content

Commit

Permalink
some fixes in JenkinsServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
b-fein committed Jan 3, 2025
1 parent b8dc7d2 commit 427564c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<BuildPlan> targetBuildPlan = buildPlanRepository.findByProgrammingExercises_IdWithProgrammingExercises(targetExercise.getId());
assertThat(targetBuildPlan).isEmpty();
Expand Down

0 comments on commit 427564c

Please sign in to comment.