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