Skip to content

Commit

Permalink
fix mocks on exercise import
Browse files Browse the repository at this point in the history
  • Loading branch information
b-fein committed Jan 3, 2025
1 parent a450417 commit 9ca831b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_JENKINS;
import static de.tum.cit.aet.artemis.core.util.TestResourceUtils.loadFileFromResources;
import static de.tum.cit.aet.artemis.programming.domain.build.BuildPlanType.SOLUTION;
import static de.tum.cit.aet.artemis.programming.domain.build.BuildPlanType.TEMPLATE;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
Expand Down Expand Up @@ -43,6 +44,7 @@
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.programming.domain.ProgrammingExercise;
import de.tum.cit.aet.artemis.programming.domain.build.BuildPlanType;
import de.tum.cit.aet.artemis.programming.service.jenkins.JenkinsEndpoints;
import de.tum.cit.aet.artemis.programming.service.jenkins.dto.JenkinsUserDTO;
import de.tum.cit.aet.artemis.programming.service.jenkins.jobs.JenkinsJobPermissionsService;
Expand Down Expand Up @@ -227,8 +229,16 @@ public void mockCheckIfProjectExistsJobUrlEmptyOrNull(ProgrammingExercise exerci
}

public void mockCopyBuildPlanFromTemplate(String sourceProjectKey, String targetProjectKey, String planKey) throws IOException {
mockCopyBuildPlanFromPlanType(sourceProjectKey, targetProjectKey, planKey, TEMPLATE);
}

public void mockCopyBuildPlanFromSolution(String sourceProjectKey, String targetProjectKey, String planKey) throws IOException {
mockCopyBuildPlanFromPlanType(sourceProjectKey, targetProjectKey, planKey, SOLUTION);
}

private void mockCopyBuildPlanFromPlanType(String sourceProjectKey, String targetProjectKey, String planKey, BuildPlanType planType) throws IOException {
// the plan key has the form EXERCISE_ID-PARTICIPATION_ID
final String sourcePlanKey = planKey.replaceAll("-.*$", "-" + TEMPLATE.getName());
final String sourcePlanKey = sourceProjectKey + "-" + planType.getName();
mockGetJobXmlForBuildPlanWith(sourceProjectKey, sourcePlanKey, "<xml></xml>");
mockSaveJobXml(targetProjectKey, planKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ private void mockCloneAndEnableAllBuildPlans(ProgrammingExercise sourceExercise,
String templateBuildPlanId = targetProjectKey + "-" + TEMPLATE.getName();
String solutionBuildPlanId = targetProjectKey + "-" + SOLUTION.getName();

jenkinsRequestMockProvider.mockGetFolderJob(targetProjectKey, null);
jenkinsRequestMockProvider.mockCreateProjectForExercise(exerciseToBeImported, false);
jenkinsRequestMockProvider.mockGetFolderJob(targetProjectKey);
jenkinsRequestMockProvider.mockCopyBuildPlanFromTemplate(sourceExercise.getProjectKey(), targetProjectKey, templateBuildPlanId);
jenkinsRequestMockProvider.mockCopyBuildPlanFromTemplate(sourceExercise.getProjectKey(), targetProjectKey, solutionBuildPlanId);
jenkinsRequestMockProvider.mockCopyBuildPlanFromSolution(sourceExercise.getProjectKey(), targetProjectKey, solutionBuildPlanId);
jenkinsRequestMockProvider.mockGivePlanPermissions(targetProjectKey, templateBuildPlanId);
jenkinsRequestMockProvider.mockGivePlanPermissions(targetProjectKey, solutionBuildPlanId);
jenkinsRequestMockProvider.mockEnablePlan(targetProjectKey, templateBuildPlanId, planExistsInCi, shouldPlanEnableFail);
Expand Down

0 comments on commit 9ca831b

Please sign in to comment.