Search in sources :

Example 66 with ProgrammingSubmission

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;
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) NotNull(javax.validation.constraints.NotNull)

Example 67 with ProgrammingSubmission

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();
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationJenkinsGitlabTest(de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest)

Example 68 with ProgrammingSubmission

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;
}
Also used : Path(java.nio.file.Path) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Map(java.util.Map) File(java.io.File)

Example 69 with ProgrammingSubmission

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;
}
Also used : Path(java.nio.file.Path) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Map(java.util.Map) File(java.io.File)

Example 70 with ProgrammingSubmission

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);
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ProgrammingSubmission (de.tum.in.www1.artemis.domain.ProgrammingSubmission)30 WithMockUser (org.springframework.security.test.context.support.WithMockUser)26 Test (org.junit.jupiter.api.Test)24 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)16 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)16 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)16 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 HttpHeaders (org.springframework.http.HttpHeaders)10 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)8 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)8 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)8 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)8 ArrayList (java.util.ArrayList)8 AbstractSpringIntegrationJenkinsGitlabTest (de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest)6 ProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation)6 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 Path (java.nio.file.Path)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 AbstractSpringDevelopmentTest (de.tum.in.www1.artemis.AbstractSpringDevelopmentTest)4