Search in sources :

Example 31 with ParticipantScore

use of de.tum.in.www1.artemis.domain.scores.ParticipantScore 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 32 with ParticipantScore

use of de.tum.in.www1.artemis.domain.scores.ParticipantScore in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method saveUnratedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveUnratedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(false, isTeamTest);
    Result persistedResult = originalParticipantScore.getLastResult();
    // removing the result should trigger the entity listener and remove the associated student score
    resultRepository.deleteById(persistedResult.getId());
    List<StudentScore> savedStudentScores = studentScoreRepository.findAll();
    List<Result> savedResults = resultRepository.findAll();
    assertThat(savedStudentScores).isEmpty();
    assertThat(savedResults).isEmpty();
    verify(scoreService, times(1)).removeOrUpdateAssociatedParticipantScore(any(Result.class));
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with ParticipantScore

use of de.tum.in.www1.artemis.domain.scores.ParticipantScore in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method saveUnratedResult_then_saveAnotherRatedResult_thenRemoveSecondResult_ShouldUpdateStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveUnratedResult_then_saveAnotherRatedResult_thenRemoveSecondResult_ShouldUpdateStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(false, isTeamTest);
    Result originalResult = originalParticipantScore.getLastResult();
    // creating a new rated result should trigger the entity listener and update the student score BUT only the not rated part
    Result newResult = createNewResult(isTeamTest, true);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, newResult.getId(), newResult.getScore(), newResult.getId(), newResult.getScore());
    resultRepository.deleteById(newResult.getId());
    List<Result> savedResults = resultRepository.findAll();
    assertThat(savedResults).hasSize(1);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, originalResult.getId(), originalResult.getScore(), null, null);
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with ParticipantScore

use of de.tum.in.www1.artemis.domain.scores.ParticipantScore in project ArTEMiS by ls1intum.

the class ResultListenerIntegrationTest method saveUnratedResult_then_saveAnotherUnratedResult_thenRemoveSecondResult_ShouldUpdateStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveUnratedResult_then_saveAnotherUnratedResult_thenRemoveSecondResult_ShouldUpdateStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(false, isTeamTest);
    Result originalResult = originalParticipantScore.getLastResult();
    // creating a new rated result should trigger the entity listener and update the student score BUT only the not rated part
    Result newResult = createNewResult(isTeamTest, false);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, newResult.getId(), newResult.getScore(), null, null);
    resultRepository.deleteById(newResult.getId());
    List<Result> savedResults = resultRepository.findAll();
    assertThat(savedResults).hasSize(1);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, originalResult.getId(), originalResult.getScore(), null, null);
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with ParticipantScore

use of de.tum.in.www1.artemis.domain.scores.ParticipantScore 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)

Aggregations

ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)40 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 ValueSource (org.junit.jupiter.params.provider.ValueSource)28 WithMockUser (org.springframework.security.test.context.support.WithMockUser)28 StudentScore (de.tum.in.www1.artemis.domain.scores.StudentScore)14 TeamScore (de.tum.in.www1.artemis.domain.scores.TeamScore)10 Participant (de.tum.in.www1.artemis.domain.participation.Participant)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)2 ExerciseScoresAggregatedInformation (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation)2 ExerciseScoresDTO (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)2 Authentication (org.springframework.security.core.Authentication)2