Search in sources :

Example 16 with ParticipantScore

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

the class ParticipantScoreDTO method generateFromParticipantScore.

/**
 * Generates a {@link ParticipantScoreDTO} from a {@link ParticipantScore}
 *
 * @param participantScore ParticipantScore input
 * @return {@link ParticipantScoreDTO}
 */
public static ParticipantScoreDTO generateFromParticipantScore(ParticipantScore participantScore) {
    String userName = null;
    Long userId = null;
    String teamName = null;
    Long teamId = null;
    if (participantScore.getClass().equals(StudentScore.class)) {
        StudentScore studentScore = (StudentScore) participantScore;
        if (studentScore.getUser() != null) {
            userName = studentScore.getUser().getLogin();
            userId = studentScore.getUser().getId();
        }
    } else {
        TeamScore teamScore = (TeamScore) participantScore;
        if (teamScore.getTeam() != null) {
            teamName = teamScore.getTeam().getName();
            teamId = teamScore.getTeam().getId();
        }
    }
    Long id = participantScore.getId();
    String exerciseTitle = participantScore.getExercise() != null && participantScore.getExercise().getTitle() != null ? participantScore.getExercise().getTitle() : null;
    Long exerciseId = participantScore.getExercise() != null ? participantScore.getExercise().getId() : null;
    Long lastResultId = participantScore.getLastResult() != null ? participantScore.getLastResult().getId() : null;
    Double lastResultScore = participantScore.getLastScore();
    Long lastRatedResultId = participantScore.getLastRatedResult() != null ? participantScore.getLastRatedResult().getId() : null;
    Double lastRatedResultScore = participantScore.getLastRatedScore();
    Double lastPoints = participantScore.getLastPoints();
    Double lastRatedPoints = participantScore.getLastRatedPoints();
    return new ParticipantScoreDTO(id, userId, userName, teamId, teamName, exerciseId, exerciseTitle, lastResultId, lastResultScore, lastRatedResultId, lastRatedResultScore, lastPoints, lastRatedPoints);
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 17 with ParticipantScore

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

the class ResultListenerIntegrationTest method saveRatedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_removeSavedResult_ShouldRemoveAssociatedStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(true, 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 18 with ParticipantScore

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

the class ResultListenerIntegrationTest method saveRatedResult_then_changeScoreOfResult_ShouldUpdateOriginalStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_changeScoreOfResult_ShouldUpdateOriginalStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(true, isTeamTest);
    Result originalResult = originalParticipantScore.getLastResult();
    // update the associated student score should trigger the entity listener and update the student score
    originalResult.setScore(0D);
    Result updatedResult = resultRepository.saveAndFlush(originalResult);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, updatedResult.getId(), updatedResult.getScore(), updatedResult.getId(), updatedResult.getScore());
}
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 19 with ParticipantScore

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

the class ResultListenerIntegrationTest method saveRatedResult_then_saveAnotherUnratedResult_thenRemoveSecondResult_ShouldUpdateStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_saveAnotherUnratedResult_thenRemoveSecondResult_ShouldUpdateStudentScore(boolean isTeamTest) {
    ParticipantScore originalParticipantScore = setupTestScenarioWithOneResultSaved(true, 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(), originalResult.getId(), originalResult.getScore());
    resultRepository.deleteById(newResult.getId());
    List<Result> savedResults = resultRepository.findAll();
    assertThat(savedResults).hasSize(1);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, originalResult.getId(), originalResult.getScore(), originalResult.getId(), originalResult.getScore());
}
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 20 with ParticipantScore

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

the class ResultListenerIntegrationTest method assertParticipantScoreStructure.

private void assertParticipantScoreStructure(ParticipantScore participantScore, Long expectedExerciseId, Long expectedParticipantId, Long expectedLastResultId, Double expectedLastScore, Long expectedLastRatedResultId, Double expectedLastRatedScore, Double expectedLastPoints, Double expectedLastRatedPoints) {
    assertThat(participantScore.getExercise().getId()).isEqualTo(expectedExerciseId);
    if (participantScore.getClass().equals(StudentScore.class)) {
        StudentScore studentScore = (StudentScore) participantScore;
        assertThat(studentScore.getUser().getId()).isEqualTo(expectedParticipantId);
    } else {
        TeamScore teamScore = (TeamScore) participantScore;
        assertThat(teamScore.getTeam().getId()).isEqualTo(expectedParticipantId);
    }
    if (expectedLastResultId == null) {
        assertThat(participantScore.getLastResult()).isNull();
    } else {
        assertThat(participantScore.getLastResult().getId()).isEqualTo(expectedLastResultId);
    }
    assertThat(participantScore.getLastScore()).isEqualTo(expectedLastScore);
    assertThat(participantScore.getLastPoints()).isEqualTo(expectedLastPoints);
    if (expectedLastRatedResultId == null) {
        assertThat(participantScore.getLastRatedResult()).isNull();
    } else {
        assertThat(participantScore.getLastRatedResult().getId()).isEqualTo(expectedLastRatedResultId);
    }
    assertThat(participantScore.getLastRatedScore()).isEqualTo(expectedLastRatedScore);
    assertThat(participantScore.getLastRatedPoints()).isEqualTo(expectedLastRatedPoints);
}
Also used : StudentScore(de.tum.in.www1.artemis.domain.scores.StudentScore) TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

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