Skip to content

Commit

Permalink
fix student exam integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b-fein committed Jan 3, 2025
1 parent 2654d12 commit 81ce8ed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Document getJobConfig(String folderName, String jobName) {
try {
var folder = getFolderJob(folderName);
if (folder == null) {
throw new JenkinsException("The folder " + folderName + "does not exist.");
throw new JenkinsException("The folder " + folderName + " does not exist.");
}

URI uri = JenkinsEndpoints.PLAN_CONFIG.buildEndpoint(serverUri, folderName, jobName).build(true).toUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ public void mockCreateCustomBuildPlan(String projectKey, String planKey) throws
mockCreateBuildPlan(projectKey, job, false);
}

private void mockCreateJobInExistingFolder(String jobFolder, String job) throws IOException {
mockGetFolderJob(jobFolder);
if (false) {
var jobWithDetails = new JenkinsJobService.JobWithDetails(job, "description", false);
// NOTE: this method also invokes mockGetFolderJob(...)
mockGetJob(jobFolder, job, jobWithDetails, false);
}
else {
mockGetJob(jobFolder, job, null, false);
mockCreateJob(jobFolder, job);
}
}

public void mockCreateJobInFolder(String jobFolder, String job, boolean jobAlreadyExists) throws IOException {
var folderJob = jobAlreadyExists ? new JenkinsJobService.FolderJob(jobFolder, "description", "url") : null;
mockGetFolderJob(jobFolder, folderJob);
Expand Down Expand Up @@ -229,24 +242,33 @@ public void mockCheckIfProjectExistsJobUrlEmptyOrNull(ProgrammingExercise exerci
}

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

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

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

private void mockCopyBuildPlanFromPlanType(String sourceProjectKey, String targetProjectKey, String planKey, BuildPlanType planType) throws IOException {
private void mockCopyBuildPlanFromPlanType(String sourceProjectKey, String targetProjectKey, String planKey, BuildPlanType planType, boolean folderExists) throws IOException {
// the plan key has the form EXERCISE_ID-PARTICIPATION_ID
final String sourcePlanKey = sourceProjectKey + "-" + planType.getName();
mockGetJobXmlForBuildPlanWith(sourceProjectKey, sourcePlanKey, "<xml></xml>");
mockSaveJobXml(targetProjectKey, planKey);
mockSaveJobXml(targetProjectKey, planKey, folderExists);
}

private void mockSaveJobXml(String targetProjectKey, String planKey) throws IOException {
private void mockSaveJobXml(String targetProjectKey, String planKey, boolean folderExists) throws IOException {
mockGetFolderJob(targetProjectKey);
mockGetJob(targetProjectKey, planKey, null, false);
mockCreateBuildPlan(targetProjectKey, planKey, false);
if (folderExists) {
mockCreateJobInExistingFolder(targetProjectKey, planKey);
}
else {
mockCreateBuildPlan(targetProjectKey, planKey, false);
}
}

public void mockConfigureBuildPlan(ProgrammingExercise exercise, String username) throws IOException {
Expand Down Expand Up @@ -305,7 +327,7 @@ public void mockEnablePlan(String projectKey, String planKey, boolean planExists
public void mockCopyBuildPlanForParticipation(ProgrammingExercise exercise, String username) throws IOException {
final var projectKey = exercise.getProjectKey();
final var planKey = projectKey + "-" + getCleanPlanName(username.toUpperCase());
mockCopyBuildPlanFromTemplate(projectKey, projectKey, planKey);
mockCopyBuildPlanFromTemplateIntoExistingTargetFolder(projectKey, projectKey, planKey);
}

public void mockGetJob(String projectKey, String jobName, JenkinsJobService.JobWithDetails jobToReturn, boolean shouldFail) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1995,8 +1995,8 @@ public List<StudentExam> prepareStudentExamsForConduction(String testPrefix, Zon
Set<Long> peIds = exam.getExerciseGroups().get(6).getExercises().stream().map(Exercise::getId).collect(Collectors.toSet());
List<ProgrammingExercise> programmingExercises = programmingExerciseTestRepository.findAllWithTemplateAndSolutionParticipationByIdIn(peIds);
exam.getExerciseGroups().get(6).setExercises(new HashSet<>(programmingExercises));
for (var exercise : programmingExercises) {

for (var exercise : programmingExercises) {
setupRepositoryMocks(exercise);
for (var examUser : exam.getExamUsers()) {
var repo = new LocalRepository(defaultBranch);
Expand All @@ -2013,7 +2013,8 @@ public List<StudentExam> prepareStudentExamsForConduction(String testPrefix, Zon
}

int noGeneratedParticipations = ExamPrepareExercisesTestUtil.prepareExerciseStart(request, exam, course);
assertThat(noGeneratedParticipations).isEqualTo(registeredStudents.size() * exam.getExerciseGroups().size());
assertThat(noGeneratedParticipations).as("for each of the %d students there should be %d exercises", registeredStudents.size(), exam.getExerciseGroups().size())
.isEqualTo(registeredStudents.size() * exam.getExerciseGroups().size());

mockDelegate.resetMockProvider();

Expand Down

0 comments on commit 81ce8ed

Please sign in to comment.