Search in sources :

Example 26 with ProgrammingExerciseStudentParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation 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 27 with ProgrammingExerciseStudentParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.

the class ProgrammingSubmissionIntegrationTest method triggerBuildForParticipationsInstructorEmpty.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildForParticipationsInstructorEmpty() throws Exception {
    bambooRequestMockProvider.enableMockingOfRequests();
    String login1 = "student1";
    String login2 = "student2";
    String login3 = "student3";
    ProgrammingExerciseStudentParticipation participation1 = database.addStudentParticipationForProgrammingExercise(exercise, login1);
    database.addStudentParticipationForProgrammingExercise(exercise, login2);
    ProgrammingExerciseStudentParticipation participation3 = database.addStudentParticipationForProgrammingExercise(exercise, login3);
    // We only trigger two participations here: 1 and 3.
    bambooRequestMockProvider.mockTriggerBuild(participation1);
    bambooRequestMockProvider.mockTriggerBuild(participation3);
    // Mock again because we call the trigger request two times
    bambooRequestMockProvider.mockTriggerBuild(participation1);
    bambooRequestMockProvider.mockTriggerBuild(participation3);
    List<Long> participationsToTrigger = new ArrayList<>(Arrays.asList(participation1.getId(), participation3.getId()));
    doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
    // Perform a call to trigger-instructor-build-all twice. We want to check that the submissions
    // aren't being re-created.
    String url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build";
    request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
    request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
    List<ProgrammingSubmission> submissions = submissionRepository.findAll();
    // Note: the participations above have no submissions, so the builds will not be triggered
    assertThat(submissions).isEmpty();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ArrayList(java.util.ArrayList) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with ProgrammingExerciseStudentParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.

the class ProgrammingExerciseGradingServiceTest method setUp.

@BeforeEach
public void setUp() {
    database.addUsers(5, 1, 0, 1);
    database.addCourseWithOneProgrammingExerciseAndTestCases();
    programmingExercise = generateDefaultProgrammingExercise();
    database.addTestCasesToProgrammingExercise(programmingExercise);
    programmingExerciseSCAEnabled = generateScaProgrammingExercise();
    database.addTestCasesToProgrammingExercise(programmingExerciseSCAEnabled);
    ProgrammingExerciseStudentParticipation participation = database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
    result = new Result();
    result.setParticipation(participation);
    bambooRequestMockProvider.enableMockingOfRequests();
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with ProgrammingExerciseStudentParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.

the class ExerciseDeletionService method cleanup.

/**
 * Delete student build plans (except BASE/SOLUTION) and optionally git repositories of all exercise student participations.
 *
 * @param exerciseId         programming exercise for which build plans in respective student participations are deleted
 * @param deleteRepositories if true, the repositories gets deleted
 */
public void cleanup(Long exerciseId, boolean deleteRepositories) {
    Exercise exercise = exerciseRepository.findByIdWithStudentParticipationsElseThrow(exerciseId);
    log.info("Request to cleanup all participations for Exercise : {}", exercise.getTitle());
    if (exercise instanceof ProgrammingExercise) {
        for (StudentParticipation participation : exercise.getStudentParticipations()) {
            participationService.cleanupBuildPlan((ProgrammingExerciseStudentParticipation) participation);
        }
        if (!deleteRepositories) {
            // in this case, we are done
            return;
        }
        for (StudentParticipation participation : exercise.getStudentParticipations()) {
            participationService.cleanupRepository((ProgrammingExerciseStudentParticipation) participation);
        }
    } else {
        log.warn("Exercise with exerciseId {} is not an instance of ProgrammingExercise. Ignoring the request to cleanup repositories and build plan", exerciseId);
    }
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) TextExercise(de.tum.in.www1.artemis.domain.TextExercise) Exercise(de.tum.in.www1.artemis.domain.Exercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 30 with ProgrammingExerciseStudentParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.

the class ProgrammingExerciseParticipation method isLocked.

/**
 * Check if the participation is locked.
 * This is the case when the participation is a ProgrammingExerciseStudentParticipation,
 * the buildAndTestAfterDueDate of the exercise is set and the due date has passed,
 * or if manual correction is involved and the due date has passed.
 *
 * Locked means that the student can't make any changes to their repository anymore.
 * While we can control this easily in the remote VCS, we need to check this manually
 * for the local repository on the Artemis server.
 *
 * @return true if repository is locked, false if not.
 */
@JsonIgnore
default boolean isLocked() {
    if (!(this instanceof ProgrammingExerciseStudentParticipation)) {
        return false;
    }
    final ProgrammingExercise programmingExercise = getProgrammingExercise();
    final ZonedDateTime now = ZonedDateTime.now();
    boolean isAfterDueDate = false;
    if (getIndividualDueDate() != null) {
        isAfterDueDate = now.isAfter(getIndividualDueDate());
    } else if (programmingExercise.getDueDate() != null) {
        isAfterDueDate = now.isAfter(programmingExercise.getDueDate());
    }
    // Editing is allowed if build and test after due date is not set and no manual correction is involved
    // (this should match CodeEditorStudentContainerComponent.repositoryIsLocked on the client-side)
    boolean isEditingAfterDueAllowed = programmingExercise.getBuildAndTestStudentSubmissionsAfterDueDate() == null && programmingExercise.getAssessmentType() != AssessmentType.MANUAL && programmingExercise.getAssessmentType() != AssessmentType.SEMI_AUTOMATIC && !programmingExercise.areManualResultsAllowed();
    return isAfterDueDate && !isEditingAfterDueAllowed;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Aggregations

ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)58 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)24 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)20 Test (org.junit.jupiter.api.Test)20 Result (de.tum.in.www1.artemis.domain.Result)18 BeforeEach (org.junit.jupiter.api.BeforeEach)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ZonedDateTime (java.time.ZonedDateTime)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Feedback (de.tum.in.www1.artemis.domain.Feedback)14 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)14 ModelFactory (de.tum.in.www1.artemis.util.ModelFactory)14 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)14 List (java.util.List)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AfterEach (org.junit.jupiter.api.AfterEach)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)12