use of de.tum.in.www1.artemis.domain.participation.Participation in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringFailedBuild_correctInitializationState.
// TEST
public void resumeProgrammingExerciseByTriggeringFailedBuild_correctInitializationState(ExerciseMode exerciseMode, boolean buildPlanExists) throws Exception {
var participation = createStudentParticipationWithSubmission(exerciseMode);
var participant = participation.getParticipant();
mockDelegate.mockTriggerFailedBuild(participation);
// We need to mock the call again because we are triggering the build twice in order to verify that the submission isn't re-created
mockDelegate.mockTriggerFailedBuild(participation);
mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
// These will be updated triggering a failed build
participation.setInitializationState(InitializationState.INACTIVE);
participation.setBuildPlanId(!buildPlanExists ? null : participation.getBuildPlanId());
programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
if (!buildPlanExists) {
mockDelegate.mockConnectorRequestsForResumeParticipation(exercise, participant.getParticipantIdentifier(), participant.getParticipants(), true);
participation = request.putWithResponseBody("/api/exercises/" + exercise.getId() + "/resume-programming-participation", null, ProgrammingExerciseStudentParticipation.class, HttpStatus.OK);
}
// Construct trigger-build url and execute request
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-failed-build";
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
// Fetch updated participation and assert
ProgrammingExerciseStudentParticipation updatedParticipation = (ProgrammingExerciseStudentParticipation) participationRepository.findByIdElseThrow(participation.getId());
assertThat(updatedParticipation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
assertThat(updatedParticipation.getBuildPlanId()).as("Build Plan Id should be set").isEqualTo(exercise.getProjectKey().toUpperCase() + "-" + participant.getParticipantIdentifier().toUpperCase());
// Trigger the build again and make sure no new submission is created
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
var submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
}
use of de.tum.in.www1.artemis.domain.participation.Participation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionAndResultGitlabJenkinsIntegrationTest method shouldNotReceiveBuildLogsOnStudentParticipationWithoutResult.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@MethodSource("shouldSaveBuildLogsOnStudentParticipationArguments")
@WithMockUser(username = "student1", roles = "USER")
void shouldNotReceiveBuildLogsOnStudentParticipationWithoutResult(ProgrammingLanguage programmingLanguage, boolean enableStaticCodeAnalysis) throws Exception {
// Precondition: Database has participation and a programming submission.
String userLogin = "student1";
database.addCourseWithOneProgrammingExercise(enableStaticCodeAnalysis, false, programmingLanguage);
ProgrammingExercise exercise = programmingExerciseRepository.findAllWithEagerParticipationsAndLegalSubmissions().get(1);
var participation = database.addStudentParticipationForProgrammingExercise(exercise, userLogin);
var submission = database.createProgrammingSubmission(participation, false);
// Call programming-exercises/new-result which do not include build log entries yet
var notification = createJenkinsNewResultNotification(exercise.getProjectKey(), userLogin, programmingLanguage, List.of());
postResult(notification, HttpStatus.OK);
var result = assertBuildError(participation.getId(), userLogin, false);
assertThat(result.getSubmission().getId()).isEqualTo(submission.getId());
// Call again and assert that no new submissions have been created
postResult(notification, HttpStatus.OK);
assertNoNewSubmissions(submission);
}
use of de.tum.in.www1.artemis.domain.participation.Participation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionAndResultGitlabJenkinsIntegrationTest method shouldReceiveBuildLogsOnNewStudentParticipationResult.
@Test
@WithMockUser(username = "student1", roles = "USER")
void shouldReceiveBuildLogsOnNewStudentParticipationResult() throws Exception {
// Precondition: Database has participation and a programming submission.
String userLogin = "student1";
database.addCourseWithOneProgrammingExercise(false, false, ProgrammingLanguage.JAVA);
ProgrammingExercise exercise = programmingExerciseRepository.findAllWithEagerParticipationsAndLegalSubmissions().get(1);
var participation = database.addStudentParticipationForProgrammingExercise(exercise, userLogin);
var submission = database.createProgrammingSubmission(participation, false);
List<String> logs = new ArrayList<>();
logs.add("[2021-05-10T15:19:49.740Z] [ERROR] BubbleSort.java:[15,9] not a statement");
logs.add("[2021-05-10T15:19:49.740Z] [ERROR] BubbleSort.java:[15,10] ';' expected");
var notification = createJenkinsNewResultNotification(exercise.getProjectKey(), userLogin, ProgrammingLanguage.JAVA, List.of());
notification.setLogs(logs);
postResult(notification, HttpStatus.OK);
var submissionWithLogsOptional = submissionRepository.findWithEagerBuildLogEntriesById(submission.getId());
assertThat(submissionWithLogsOptional).isPresent();
// Assert that the submission contains build log entries
ProgrammingSubmission submissionWithLogs = submissionWithLogsOptional.get();
List<BuildLogEntry> buildLogEntries = submissionWithLogs.getBuildLogEntries();
assertThat(buildLogEntries).hasSize(2);
assertThat(buildLogEntries.get(0).getLog()).isEqualTo("[ERROR] BubbleSort.java:[15,9] not a statement");
assertThat(buildLogEntries.get(1).getLog()).isEqualTo("[ERROR] BubbleSort.java:[15,10] ';' expected");
}
use of de.tum.in.www1.artemis.domain.participation.Participation in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionAndResultIntegrationTestService method postSubmission.
/**
* This is the simulated request from the VCS to Artemis on a new commit.
* @return The submission that was created
*/
public ProgrammingSubmission postSubmission(Long participationId, HttpStatus expectedStatus, String jsonRequest) throws Exception {
JSONParser jsonParser = new JSONParser();
Object obj = jsonParser.parse(jsonRequest);
// Api should return ok.
request.postWithoutLocation(PROGRAMMING_SUBMISSION_RESOURCE_API_PATH + participationId, obj, expectedStatus, new HttpHeaders());
List<ProgrammingSubmission> submissions = programmingSubmissionRepository.findAll();
// Submission should have been created for the participation.
assertThat(submissions).hasSize(1);
// Make sure that both the submission and participation are correctly linked with each other.
return submissions.get(0);
}
use of de.tum.in.www1.artemis.domain.participation.Participation in project ArTEMiS by ls1intum.
the class ParticipationTeamWebsocketServiceTest method testUnsubscribeFromParticipationTeamWebsocketTopic.
@Test
@WithMockUser(username = "student1", roles = "USER")
void testUnsubscribeFromParticipationTeamWebsocketTopic() {
StompHeaderAccessor stompHeaderAccessor1 = getStompHeaderAccessorMock();
StompHeaderAccessor stompHeaderAccessor2 = getStompHeaderAccessorMock();
participationTeamWebsocketService.subscribe(participation.getId(), stompHeaderAccessor1);
participationTeamWebsocketService.subscribe(participation.getId(), stompHeaderAccessor2);
participationTeamWebsocketService.unsubscribe(stompHeaderAccessor1.getSessionId());
verify(messagingTemplate, times(3)).convertAndSend(websocketTopic(participation), List.of());
assertThat(participationTeamWebsocketService.getDestinationTracker()).as("Session was removed from destination tracker.").hasSize(1);
assertThat(participationTeamWebsocketService.getDestinationTracker()).as("Correct session was removed.").containsKey(stompHeaderAccessor2.getSessionId());
}
Aggregations