Search in sources :

Example 1 with ExerciseMode

use of de.tum.in.www1.artemis.domain.enumeration.ExerciseMode 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 2 with ExerciseMode

use of de.tum.in.www1.artemis.domain.enumeration.ExerciseMode in project Artemis by ls1intum.

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState(ExerciseMode exerciseMode) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockTriggerInstructorBuildAll(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.mockTriggerInstructorBuildAll(participation);
    mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
    // These will be updated triggering a failed build
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(null);
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    var url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build-all";
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    Awaitility.setDefaultTimeout(Duration.ofSeconds(20));
    await().until(() -> programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(exercise.getId()).isPresent());
    // 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 3 with ExerciseMode

use of de.tum.in.www1.artemis.domain.enumeration.ExerciseMode in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestService method createStudentParticipationWithSubmission.

private ProgrammingExerciseStudentParticipation createStudentParticipationWithSubmission(ExerciseMode exerciseMode) throws Exception {
    setupCourseWithProgrammingExercise(exerciseMode);
    User user = userRepo.findOneByLogin(ProgrammingExerciseTestService.studentLogin).orElseThrow();
    ProgrammingExerciseStudentParticipation participation;
    if (exerciseMode == TEAM) {
        var team = setupTeam(user);
        participation = database.addTeamParticipationForProgrammingExercise(exercise, team);
        // prepare for the mock scenario, so that the empty commit will work properly
        participation.setRepositoryUrl(ModelFactory.getMockFileRepositoryUrl(studentTeamRepo).getURI().toString());
    } else {
        participation = database.addStudentParticipationForProgrammingExercise(exercise, user.getParticipantIdentifier());
        // prepare for the mock scenario, so that the empty commit will work properly
        participation.setRepositoryUrl(ModelFactory.getMockFileRepositoryUrl(studentRepo).getURI().toString());
    }
    ProgrammingSubmission submission = new ProgrammingSubmission();
    submission.setSubmissionDate(ZonedDateTime.now().minusMinutes(4));
    submission.setSubmitted(true);
    submission.setCommitHash(TestConstants.COMMIT_HASH_STRING);
    submission.setType(SubmissionType.MANUAL);
    database.addSubmission(participation, submission);
    return participation;
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 4 with ExerciseMode

use of de.tum.in.www1.artemis.domain.enumeration.ExerciseMode in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState(ExerciseMode exerciseMode) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockTriggerInstructorBuildAll(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.mockTriggerInstructorBuildAll(participation);
    mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
    // These will be updated triggering a failed build
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(null);
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    var url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build-all";
    request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
    Awaitility.setDefaultTimeout(Duration.ofSeconds(20));
    await().until(() -> programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(exercise.getId()).isPresent());
    // 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 5 with ExerciseMode

use of de.tum.in.www1.artemis.domain.enumeration.ExerciseMode in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringBuild_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByTriggeringBuild_correctInitializationState(ExerciseMode exerciseMode, SubmissionType submissionType) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockTriggerParticipationBuild(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.mockTriggerParticipationBuild(participation);
    mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
    // These will be updated when triggering a build
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(null);
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    // Construct trigger-build url and execute request
    submissionType = submissionType == null ? SubmissionType.MANUAL : submissionType;
    String url = "/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=" + submissionType.name();
    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)

Aggregations

ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)10 HttpHeaders (org.springframework.http.HttpHeaders)8 Participant (de.tum.in.www1.artemis.domain.participation.Participant)2