Search in sources :

Example 96 with Participation

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 97 with Participation

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);
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 98 with Participation

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");
}
Also used : BuildLogEntry(de.tum.in.www1.artemis.domain.BuildLogEntry) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ArrayList(java.util.ArrayList) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationJenkinsGitlabTest(de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with Participation

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) JSONParser(org.json.simple.parser.JSONParser)

Example 100 with Participation

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());
}
Also used : StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)181 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 Test (org.junit.jupiter.api.Test)124 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)70 Participation (de.tum.in.www1.artemis.domain.participation.Participation)54 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 ZonedDateTime (java.time.ZonedDateTime)47 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)44 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)42 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)38 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)38 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)34 Collectors (java.util.stream.Collectors)34 HttpHeaders (org.springframework.http.HttpHeaders)34 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)33 Result (de.tum.in.www1.artemis.domain.Result)33 Exam (de.tum.in.www1.artemis.domain.exam.Exam)32 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)32