use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.
the class AbstractContinuousIntegrationService method createFallbackSubmission.
/**
* There can be two reasons for the case that there is no programmingSubmission:
* 1) Manual build triggered from CI (e.g. by the instructor)
* 2) An unknown error that caused the programming submission not to be created when the code commits have been pushed.
* we can still get the commit hash from the payload of the CI build result and "reverse engineer" the programming submission object to be consistent
*/
@NotNull
protected ProgrammingSubmission createFallbackSubmission(ProgrammingExerciseParticipation participation, ZonedDateTime submissionDate, String commitHash) {
ProgrammingSubmission submission = new ProgrammingSubmission();
submission.setParticipation((Participation) participation);
submission.setSubmitted(true);
// We set this to manual because all programming submissions should correspond to a student commit in the git history.
// In case we cannot find the appropriate submission, it means something has not worked before, but there will still be a commit in the student repository
submission.setType(SubmissionType.MANUAL);
submission.setCommitHash(commitHash);
submission.setSubmissionDate(submissionDate);
return submission;
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project Artemis by ls1intum.
the class ParticipationServiceTest method testCreateParticipationForExternalSubmission.
/**
* Test for methods of {@link ParticipationService} used by {@link de.tum.in.www1.artemis.web.rest.ResultResource#createResultForExternalSubmission(Long, String, Result)}.
*/
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testCreateParticipationForExternalSubmission() throws Exception {
Optional<User> student = userRepository.findOneWithGroupsAndAuthoritiesByLogin("student1");
var someURL = new VcsRepositoryUrl("http://vcs.fake.fake");
// Copy Repository in ParticipationService#copyRepository(..)
doReturn(someURL).when(versionControlService).copyRepository(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class));
// Configure Repository in ParticipationService#configureRepository(..)
doNothing().when(versionControlService).configureRepository(any(), any(), anyBoolean());
// Configure WebHook in ParticipationService#configureRepositoryWebHook(..)
doNothing().when(versionControlService).addWebHookForParticipation(any());
// Do Nothing when setRepositoryPermissionsToReadOnly in ParticipationService#createParticipationWithEmptySubmissionIfNotExisting
doNothing().when(versionControlService).setRepositoryPermissionsToReadOnly(any(), any(String.class), any());
// Return the default branch for all repositories of the exercise
doReturn(defaultBranch).when(versionControlService).getOrRetrieveBranchOfExercise(programmingExercise);
StudentParticipation participation = participationService.createParticipationWithEmptySubmissionIfNotExisting(programmingExercise, student.get(), SubmissionType.EXTERNAL);
assertThat(participation).isNotNull();
assertThat(participation.getSubmissions()).hasSize(1);
assertThat(participation.getStudent()).contains(student.get());
ProgrammingSubmission programmingSubmission = (ProgrammingSubmission) participation.findLatestSubmission().get();
assertThat(programmingSubmission.getType()).isEqualTo(SubmissionType.EXTERNAL);
// results are not added in the invoked method above
assertThat(programmingSubmission.getResults()).isNullOrEmpty();
}
use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project Artemis by ls1intum.
the class HestiaUtilTestService method setupTemplate.
/**
* Sets up the template 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 templateRepo The repository
* @return The programming exercise
*/
public ProgrammingExercise setupTemplate(Map<String, String> files, ProgrammingExercise exercise, LocalRepository templateRepo) throws Exception {
templateRepo.configureRepos("templateLocalRepo", "templateOriginRepo");
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(templateRepo.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 templateRepoUrl = new GitUtilService.MockFileRepositoryUrl(templateRepo.localRepoFile);
exercise.setTemplateRepositoryUrl(templateRepoUrl.toString());
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(templateRepoUrl, true);
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(templateRepoUrl, false);
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(templateRepoUrl), eq(true), any());
doReturn(gitService.getExistingCheckedOutRepositoryByLocalPath(templateRepo.localRepoFile.toPath(), null)).when(gitService).getOrCheckoutRepository(eq(templateRepoUrl), eq(false), any());
bitbucketRequestMockProvider.enableMockingOfRequests(true);
bitbucketRequestMockProvider.mockDefaultBranch(defaultBranch, urlService.getProjectKeyFromRepositoryUrl(templateRepoUrl));
var savedExercise = exerciseRepository.save(exercise);
database.addTemplateParticipationForProgrammingExercise(savedExercise);
var templateParticipation = templateProgrammingExerciseParticipationRepository.findByProgrammingExerciseId(savedExercise.getId()).orElseThrow();
templateParticipation.setRepositoryUrl(templateRepoUrl.toString());
templateProgrammingExerciseParticipationRepository.save(templateParticipation);
var templateSubmission = new ProgrammingSubmission();
templateSubmission.setParticipation(templateParticipation);
templateSubmission.setCommitHash(String.valueOf(files.hashCode()));
programmingSubmissionRepository.save(templateSubmission);
return savedExercise;
}
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 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