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;
}
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));
}
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);
}
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);
}
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));
}
Aggregations