use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class HestiaUtilTestService method setupSolution.
/**
* Sets up the solution repository of a programming exercise with specified files
*
* @param files The fileNames mapped to the content of the files
* @param exercise The programming exercise
* @param solutionRepo The repository
* @return The programming exercise
*/
public ProgrammingExercise setupSolution(Map<String, String> files, ProgrammingExercise exercise, LocalRepository solutionRepo) throws Exception {
solutionRepo.configureRepos("solutionLocalRepo", "solutionOriginRepo");
for (Map.Entry<String, String> entry : files.entrySet()) {
String fileName = entry.getKey();
String content = entry.getValue();
// add file to the repository folder
Path filePath = Path.of(solutionRepo.localRepoFile + "/" + fileName);
Files.createDirectories(filePath.getParent());
File solutionFile = Files.createFile(filePath).toFile();
// write content to the created file
FileUtils.write(solutionFile, content, Charset.defaultCharset());
}
var solutionRepoUrl = new GitUtilService.MockFileRepositoryUrl(solutionRepo.localRepoFile);
exercise.setSolutionRepositoryUrl(solutionRepoUrl.toString());
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(solutionRepoUrl, true);
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(solutionRepoUrl, false);
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(solutionRepoUrl), eq(true), any());
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(solutionRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(solutionRepoUrl), eq(false), any());
bitbucketRequestMockProvider.enableMockingOfRequests(true);
bitbucketRequestMockProvider.mockDefaultBranch(defaultBranch, urlService.getProjectKeyFromRepositoryUrl(solutionRepoUrl));
var savedExercise = exerciseRepository.save(exercise);
database.addSolutionParticipationForProgrammingExercise(savedExercise);
var solutionParticipation = solutionProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(savedExercise.getId()).orElseThrow();
solutionParticipation.setRepositoryUrl(solutionRepoUrl.toString());
solutionProgrammingExerciseParticipationRepository.save(solutionParticipation);
var solutionSubmission = new ProgrammingSubmission();
solutionSubmission.setParticipation(solutionParticipation);
solutionSubmission.setCommitHash(String.valueOf(files.hashCode()));
programmingSubmissionRepository.save(solutionSubmission);
return savedExercise;
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildStudent.
@Test
@WithMockUser(username = "student1", roles = "USER")
void triggerBuildStudent() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-build";
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
ProgrammingSubmission submission = submissions.get(0);
var optionalSubmission = submissionRepository.findWithEagerResultsById(submission.getId());
assertThat(optionalSubmission).isPresent();
assertThat(optionalSubmission.get().getLatestResult()).isNull();
assertThat(submission.isSubmitted()).isTrue();
assertThat(submission.getType()).isEqualTo(SubmissionType.MANUAL);
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildInstructor.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildInstructor() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
String login = "student1";
StudentParticipation participation = database.addStudentParticipationForProgrammingExercise(exercise, login);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
bambooRequestMockProvider.mockTriggerBuild((ProgrammingExerciseParticipation) participation);
request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=INSTRUCTOR", null, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
ProgrammingSubmission submission = submissions.get(0);
var optionalSubmission = submissionRepository.findWithEagerResultsById(submission.getId());
assertThat(optionalSubmission).isPresent();
assertThat(optionalSubmission.get().getLatestResult()).isNull();
assertThat(submission.isSubmitted()).isTrue();
assertThat(submission.getType()).isEqualTo(SubmissionType.INSTRUCTOR);
// Trigger the call again and make sure that the submission shouldn't be recreated
request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=INSTRUCTOR", null, HttpStatus.OK, new HttpHeaders());
var updatedSubmissions = submissionRepository.findAll();
assertThat(updatedSubmissions).hasSize(1);
assertThat(updatedSubmissions.get(0).getId()).isEqualTo(submission.getId());
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildForParticipationsInstructorEmpty.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildForParticipationsInstructorEmpty() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
String login1 = "student1";
String login2 = "student2";
String login3 = "student3";
ProgrammingExerciseStudentParticipation participation1 = database.addStudentParticipationForProgrammingExercise(exercise, login1);
database.addStudentParticipationForProgrammingExercise(exercise, login2);
ProgrammingExerciseStudentParticipation participation3 = database.addStudentParticipationForProgrammingExercise(exercise, login3);
// We only trigger two participations here: 1 and 3.
bambooRequestMockProvider.mockTriggerBuild(participation1);
bambooRequestMockProvider.mockTriggerBuild(participation3);
// Mock again because we call the trigger request two times
bambooRequestMockProvider.mockTriggerBuild(participation1);
bambooRequestMockProvider.mockTriggerBuild(participation3);
List<Long> participationsToTrigger = new ArrayList<>(Arrays.asList(participation1.getId(), participation3.getId()));
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
// Perform a call to trigger-instructor-build-all twice. We want to check that the submissions
// aren't being re-created.
String url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build";
request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
// Note: the participations above have no submissions, so the builds will not be triggered
assertThat(submissions).isEmpty();
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class TestwiseCoverageIntegrationTest method setup.
@BeforeEach
public void setup() {
database.addCourseWithOneProgrammingExercise(false, true, ProgrammingLanguage.JAVA);
database.addUsers(1, 1, 0, 0);
programmingExercise = programmingExerciseRepository.findAll().get(0);
var solutionParticipation = solutionProgrammingExerciseRepository.findWithEagerResultsAndSubmissionsByProgrammingExerciseId(programmingExercise.getId()).get();
var unsavedPreviousSubmission = new ProgrammingSubmission();
unsavedPreviousSubmission.setParticipation(solutionParticipation);
unsavedPreviousSubmission.setSubmissionDate(ZonedDateTime.of(2022, 4, 5, 12, 0, 0, 0, ZoneId.of("Europe/Berlin")));
var previousSolutionSubmission = programmingSubmissionRepository.save(unsavedPreviousSubmission);
var unsavedLatestSubmission = new ProgrammingSubmission();
unsavedLatestSubmission.setParticipation(solutionParticipation);
unsavedLatestSubmission.setSubmissionDate(ZonedDateTime.of(2022, 4, 5, 13, 0, 0, 0, ZoneId.of("Europe/Berlin")));
latestSolutionSubmission = programmingSubmissionRepository.save(unsavedLatestSubmission);
var testCase1 = programmingExerciseTestCaseRepository.save(new ProgrammingExerciseTestCase().exercise(programmingExercise).testName("test1()"));
var testCase2 = programmingExerciseTestCaseRepository.save(new ProgrammingExerciseTestCase().exercise(programmingExercise).testName("test2()"));
generateAndSaveSimpleReport(0.3, "src/de/tum/in/ase/BubbleSort.java", 15, 5, 1, 5, testCase1, previousSolutionSubmission);
latestReport = generateAndSaveSimpleReport(0.4, "src/de/tum/in/ase/BubbleSort.java", 20, 8, 1, 8, testCase2, latestSolutionSubmission);
}
Aggregations