Search in sources :

Example 41 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 42 with ParticipantScore

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

the class ResultListenerIntegrationTest method saveRatedResult_then_makeResultUnrated_ShouldUpdateOriginalStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_makeResultUnrated_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.setRated(null);
    Result updatedResult = resultRepository.saveAndFlush(originalResult);
    verifyStructureOfParticipantScoreInDatabase(isTeamTest, updatedResult.getId(), updatedResult.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 43 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 44 with ParticipantScore

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

the class ResultListenerIntegrationTest method updateExercisePoints_ShouldUpdatePointsInParticipantScores.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateExercisePoints_ShouldUpdatePointsInParticipantScores(boolean isTeamTest) throws Exception {
    setupTestScenarioWithOneResultSaved(true, isTeamTest);
    Exercise exercise;
    if (isTeamTest) {
        exercise = exerciseRepository.findById(idOfTeamTextExercise).get();
    } else {
        exercise = exerciseRepository.findById(idOfIndividualTextExercise).get();
    }
    exercise.setMaxPoints(100.0);
    exercise.setBonusPoints(100.0);
    database.changeUser("instructor1");
    request.put("/api/text-exercises", exercise, HttpStatus.OK);
    List<ParticipantScore> savedParticipantScores = participantScoreRepository.findAllEagerly();
    assertThat(savedParticipantScores).isNotEmpty().hasSize(1);
    ParticipantScore savedParticipantScore = savedParticipantScores.get(0);
    assertThat(savedParticipantScore.getLastPoints()).isEqualTo(200.0);
    assertThat(savedParticipantScore.getLastRatedPoints()).isEqualTo(200.0);
}
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 45 with ParticipantScore

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

the class ResultListenerIntegrationTest method saveRatedResult_then_saveAnotherRatedResult_thenRemoveSecondResult_ShouldUpdateStudentScore.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void saveRatedResult_then_saveAnotherRatedResult_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, 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(), 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)

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