use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildStudent.
@Test
@WithMockUser(username = "student1", roles = "USER")
void triggerBuildStudent() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-build";
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
ProgrammingSubmission submission = submissions.get(0);
var optionalSubmission = submissionRepository.findWithEagerResultsById(submission.getId());
assertThat(optionalSubmission).isPresent();
assertThat(optionalSubmission.get().getLatestResult()).isNull();
assertThat(submission.isSubmitted()).isTrue();
assertThat(submission.getType()).isEqualTo(SubmissionType.MANUAL);
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildInstructor.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildInstructor() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=INSTRUCTOR", null, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
ProgrammingSubmission submission = submissions.get(0);
var optionalSubmission = submissionRepository.findWithEagerResultsById(submission.getId());
assertThat(optionalSubmission).isPresent();
assertThat(optionalSubmission.get().getLatestResult()).isNull();
assertThat(submission.isSubmitted()).isTrue();
assertThat(submission.getType()).isEqualTo(SubmissionType.INSTRUCTOR);
// Trigger the call again and make sure that the submission shouldn't be recreated
request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=INSTRUCTOR", null, HttpStatus.OK, new HttpHeaders());
var updatedSubmissions = submissionRepository.findAll();
assertThat(updatedSubmissions).hasSize(1);
assertThat(updatedSubmissions.get(0).getId()).isEqualTo(submission.getId());
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildInstructor_cannotGetLastCommitHash.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildInstructor_cannotGetLastCommitHash() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doThrow(EntityNotFoundException.class).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=INSTRUCTOR", null, HttpStatus.NOT_FOUND, new HttpHeaders());
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project Artemis by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerFailedBuildEmptyLatestPendingSubmission.
@Test
@WithMockUser(username = "student1", roles = "USER")
void triggerFailedBuildEmptyLatestPendingSubmission() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
doReturn(Optional.empty()).when(programmingSubmissionService).getLatestPendingSubmission(anyLong(), anyBoolean());
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-failed-build";
request.postWithoutLocation(url, null, HttpStatus.NOT_FOUND, new HttpHeaders());
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project Artemis by ls1intum.
the class JenkinsService method getLatestBuildLogs.
@Override
public List<BuildLogEntry> getLatestBuildLogs(ProgrammingSubmission programmingSubmission) {
ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) programmingSubmission.getParticipation();
String projectKey = programmingExerciseParticipation.getProgrammingExercise().getProjectKey();
String buildPlanId = programmingExerciseParticipation.getBuildPlanId();
ProgrammingLanguage programmingLanguage = programmingExerciseParticipation.getProgrammingExercise().getProgrammingLanguage();
try {
final var build = jenkinsJobService.getJobInFolder(projectKey, buildPlanId).getLastBuild();
List<BuildLogEntry> buildLogEntries;
// Attempt to parse pipeline logs
final String pipelineLogs = build.details().getConsoleOutputText();
if (pipelineLogs != null && pipelineLogs.contains("[Pipeline] Start of Pipeline")) {
buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(List.of(pipelineLogs.split("\n")));
} else {
// Fallback to legacy logs
final var logHtml = Jsoup.parse(build.details().getConsoleOutputHtml()).body();
buildLogEntries = JenkinsBuildLogParseUtils.parseLogsLegacy(logHtml);
}
// Filter and save build logs
buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, programmingSubmission);
programmingSubmission.setBuildLogEntries(buildLogEntries);
programmingSubmissionRepository.save(programmingSubmission);
return buildLogEntries;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new JenkinsException(e.getMessage(), e);
}
}
Aggregations