Search in sources :

Example 46 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestService method startProgrammingExercise_correctInitializationState.

// TEST
public void startProgrammingExercise_correctInitializationState(ExerciseMode exerciseMode) throws Exception {
    final Course course = setupCourseWithProgrammingExercise(exerciseMode);
    var user = userRepo.findOneByLogin(studentLogin).orElseThrow();
    Participant participant = user;
    if (exerciseMode == TEAM) {
        participant = setupTeam(user);
    }
    mockDelegate.mockConnectorRequestsForStartParticipation(exercise, participant.getParticipantIdentifier(), participant.getParticipants(), true, HttpStatus.CREATED);
    final var path = ParticipationResource.Endpoints.ROOT + ParticipationResource.Endpoints.START_PARTICIPATION.replace("{courseId}", String.valueOf(course.getId())).replace("{exerciseId}", String.valueOf(exercise.getId()));
    final var participation = request.postWithResponseBody(path, null, ProgrammingExerciseStudentParticipation.class, HttpStatus.CREATED);
    assertThat(participation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant)

Example 47 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTestService method resumeProgrammingExerciseByPushingIntoRepo_correctInitializationState.

// TEST
public void resumeProgrammingExerciseByPushingIntoRepo_correctInitializationState(ExerciseMode exerciseMode, Object body) throws Exception {
    var participation = createStudentParticipationWithSubmission(exerciseMode);
    var participant = participation.getParticipant();
    mockDelegate.mockConnectorRequestsForResumeParticipation(exercise, participant.getParticipantIdentifier(), participant.getParticipants(), true);
    mockDelegate.mockNotifyPush(participation);
    // These will be updated when pushing a commit
    participation.setInitializationState(InitializationState.INACTIVE);
    participation.setBuildPlanId(null);
    programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
    // Mock REST Call from the VCS for a new programming submission (happens as part of the webhook after pushing code to git)
    request.postWithoutLocation(PROGRAMMING_SUBMISSION_RESOURCE_API_PATH + participation.getId(), body, 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());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Example 48 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method setupTestScenarioWithOneResultSaved.

public ParticipantScore setupTestScenarioWithOneResultSaved(boolean isRatedResult, boolean isTeam) {
    List<ParticipantScore> savedParticipantScores = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScores).isEmpty();
    Long idOfExercise;
    Participant participant;
    if (isTeam) {
        participant = teamRepository.findById(idOfTeam1).get();
        idOfExercise = idOfTeamTextExercise;
    } else {
        participant = userRepository.findOneByLogin("student1").get();
        idOfExercise = idOfIndividualTextExercise;
    }
    Result persistedResult = database.createParticipationSubmissionAndResult(idOfExercise, participant, 10.0, 10.0, 200, isRatedResult);
    savedParticipantScores = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScores).isNotEmpty();
    assertThat(savedParticipantScores).hasSize(1);
    ParticipantScore savedParticipantScore = savedParticipantScores.get(0);
    Double pointsAchieved = round(persistedResult.getScore() * 0.01 * 10.0);
    if (isRatedResult) {
        assertParticipantScoreStructure(savedParticipantScore, idOfExercise, participant.getId(), persistedResult.getId(), persistedResult.getScore(), persistedResult.getId(), persistedResult.getScore(), pointsAchieved, pointsAchieved);
    } else {
        assertParticipantScoreStructure(savedParticipantScore, idOfExercise, participant.getId(), persistedResult.getId(), persistedResult.getScore(), null, null, pointsAchieved, null);
    }
    verify(this.scoreService, times(1)).updateOrCreateParticipantScore(any());
    return savedParticipantScore;
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) Participant(de.tum.in.www1.artemis.domain.participation.Participant)

Example 49 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method verifyStructureOfParticipantScoreInDatabase.

private void verifyStructureOfParticipantScoreInDatabase(boolean isTeamTest, Long expectedLastResultId, Double expectedLastScore, Long expectedLastRatedResultId, Double expectedLastRatedScore) {
    Long idOfExercise;
    Participant participant;
    if (isTeamTest) {
        participant = teamRepository.findById(idOfTeam1).get();
        idOfExercise = idOfTeamTextExercise;
    } else {
        participant = userRepository.findOneByLogin("student1").get();
        idOfExercise = idOfIndividualTextExercise;
    }
    SecurityUtils.setAuthorizationObject();
    List<ParticipantScore> savedParticipantScore = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScore).isNotEmpty();
    assertThat(savedParticipantScore).hasSize(1);
    ParticipantScore updatedParticipantScore = savedParticipantScore.get(0);
    Double lastPoints = null;
    Double lastRatedPoints = null;
    if (expectedLastScore != null) {
        lastPoints = round(expectedLastScore * 0.01 * 10.0);
    }
    if (expectedLastRatedScore != null) {
        lastRatedPoints = round(expectedLastRatedScore * 0.01 * 10.0);
    }
    assertParticipantScoreStructure(updatedParticipantScore, idOfExercise, participant.getId(), expectedLastResultId, expectedLastScore, expectedLastRatedResultId, expectedLastRatedScore, lastPoints, lastRatedPoints);
    verify(this.scoreService, times(2)).updateOrCreateParticipantScore(any(Result.class));
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore)

Example 50 with Participant

use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.

the class ProgrammingSubmissionResultSimulationService method createParticipation.

/**
 * This method creates a new participation for the provided user
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 * @param programmingExercise the used programmingExercise
 * @param participant the participant object of the user
 * @param user the user who wants to participate
 * @return the newly created and stored participation
 */
public ProgrammingExerciseStudentParticipation createParticipation(ProgrammingExercise programmingExercise, Participant participant, User user) {
    ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = new ProgrammingExerciseStudentParticipation();
    programmingExerciseStudentParticipation.setBuildPlanId(programmingExercise.getProjectKey() + "-" + user.getLogin().toUpperCase());
    programmingExerciseStudentParticipation.setParticipant(participant);
    programmingExerciseStudentParticipation.setInitializationState(InitializationState.INITIALIZED);
    programmingExerciseStudentParticipation.setRepositoryUrl("http://" + user.getLogin() + "@" + programmingExerciseSimulationService.domain + programmingExercise.getProjectKey() + "/" + programmingExercise.getProjectKey().toLowerCase() + "-" + user.getLogin() + ".git");
    programmingExerciseStudentParticipation.setInitializationDate(ZonedDateTime.now());
    programmingExerciseStudentParticipation.setProgrammingExercise(programmingExercise);
    participationRepository.save(programmingExerciseStudentParticipation);
    return programmingExerciseStudentParticipation;
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)21 Participant (de.tum.in.www1.artemis.domain.participation.Participant)15 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)14 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ParticipantScoreDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO)12 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)10 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Exercise (de.tum.in.www1.artemis.domain.Exercise)8 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)8 ParticipantScoreAverageDTO (de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreAverageDTO)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)7 QuizSubmission (de.tum.in.www1.artemis.domain.quiz.QuizSubmission)7 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)6