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 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 RepositoryProgrammingExerciseParticipationJenkinsIntegrationTest method testGetLatestBuildLogsFails.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetLatestBuildLogsFails() throws Exception {
var programmingExercise = programmingExerciseRepository.findAllWithEagerParticipations().get(0);
database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
var submission = new ProgrammingSubmission();
submission.setSubmissionDate(ZonedDateTime.now().minusMinutes(4));
submission.setSubmitted(true);
submission.setCommitHash(TestConstants.COMMIT_HASH_STRING);
submission.setType(SubmissionType.MANUAL);
submission.setBuildFailed(true);
List<BuildLogEntry> buildLogEntries = new ArrayList<>();
buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry1", submission));
buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry2", submission));
buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry3", submission));
submission.setBuildLogEntries(buildLogEntries);
database.addProgrammingSubmission(programmingExercise, submission, "student1");
buildLogEntryRepository.deleteAll();
var participation = studentParticipationRepository.findAll().get(0);
ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) submission.getParticipation();
var jobWithDetails = mock(JobWithDetails.class);
jenkinsRequestMockProvider.mockGetJob(programmingExercise.getProjectKey(), programmingExerciseParticipation.getBuildPlanId(), jobWithDetails, false);
var lastBuild = mock(Build.class);
doReturn(lastBuild).when(jobWithDetails).getLastBuild();
doThrow(IOException.class).when(lastBuild).details();
var url = "/api/repository/" + participation.getId() + "/buildlogs";
request.getList(url, HttpStatus.INTERNAL_SERVER_ERROR, BuildLogEntry.class);
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project ArTEMiS by ls1intum.
the class AbstractContinuousIntegrationService method createFallbackSubmission.
/**
* There can be two reasons for the case that there is no programmingSubmission:
* 1) Manual build triggered from CI (e.g. by the instructor)
* 2) An unknown error that caused the programming submission not to be created when the code commits have been pushed.
* we can still get the commit hash from the payload of the CI build result and "reverse engineer" the programming submission object to be consistent
*/
@NotNull
protected ProgrammingSubmission createFallbackSubmission(ProgrammingExerciseParticipation participation, ZonedDateTime submissionDate, String commitHash) {
ProgrammingSubmission submission = new ProgrammingSubmission();
submission.setParticipation((Participation) participation);
submission.setSubmitted(true);
// We set this to manual because all programming submissions should correspond to a student commit in the git history.
// In case we cannot find the appropriate submission, it means something has not worked before, but there will still be a commit in the student repository
submission.setType(SubmissionType.MANUAL);
submission.setCommitHash(commitHash);
submission.setSubmissionDate(submissionDate);
return submission;
}
Aggregations