Search in sources :

Example 16 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 17 with ProgrammingSubmission

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

Example 18 with ProgrammingSubmission

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

Example 19 with ProgrammingSubmission

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();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ArrayList(java.util.ArrayList) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 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