Search in sources :

Example 11 with ProgrammingSubmission

use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.

the class ManagementResourceIntegrationTest method toggleFeatures.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void toggleFeatures() throws Exception {
    // This setup only needed in this test case
    var course = database.addCourseWithOneProgrammingExercise();
    var programmingExercise1 = programmingExerciseRepository.findAll().get(0);
    var programmingExercise2 = ModelFactory.generateProgrammingExercise(ZonedDateTime.now(), ZonedDateTime.now().plusHours(2), course);
    var participation = database.addStudentParticipationForProgrammingExercise(programmingExercise1, "admin");
    database.addProgrammingSubmission(programmingExercise1, new ProgrammingSubmission(), "admin");
    doNothing().when(continuousIntegrationService).performEmptySetupCommit(any());
    doReturn(ContinuousIntegrationService.BuildStatus.BUILDING).when(continuousIntegrationService).getBuildStatus(any());
    doNothing().when(continuousIntegrationService).deleteBuildPlan(any(), any());
    doNothing().when(continuousIntegrationService).deleteProject(any());
    bitbucketRequestMockProvider.enableMockingOfRequests(true);
    mockDefaultBranch(programmingExercise1);
    mockDefaultBranch(programmingExercise2);
    bambooRequestMockProvider.enableMockingOfRequests(true);
    mockTriggerFailedBuild(participation);
    mockGrantReadAccess(participation);
    // Try to access 5 different endpoints with programming feature toggle enabled
    request.put("/api/exercises/" + programmingExercise1.getId() + "/resume-programming-participation", null, HttpStatus.OK);
    request.put("/api/participations/" + participation.getId() + "/cleanupBuildPlan", null, HttpStatus.OK);
    request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-failed-build", null, HttpStatus.OK, null);
    request.delete("/api/exercises/" + programmingExercise1.getId() + "/cleanup", HttpStatus.OK);
    programmingExercise2 = programmingExerciseRepository.save(programmingExercise2);
    request.delete("/api/programming-exercises/" + programmingExercise2.getId(), HttpStatus.OK);
    var features = new HashMap<Feature, Boolean>();
    features.put(Feature.ProgrammingExercises, false);
    request.put("/api/management/feature-toggle", features, HttpStatus.OK);
    verify(this.websocketMessagingService).sendMessage("/topic/management/feature-toggles", featureToggleService.enabledFeatures());
    assertThat(featureToggleService.isFeatureEnabled(Feature.ProgrammingExercises)).as("Feature was disabled").isFalse();
    // Try to access 5 different endpoints with programming feature toggle disabled
    request.put("/api/exercises/" + programmingExercise1.getId() + "/resume-programming-participation", null, HttpStatus.FORBIDDEN);
    request.put("/api/participations/" + participation.getId() + "/cleanupBuildPlan", null, HttpStatus.FORBIDDEN);
    request.postWithoutLocation("/api/programming-submissions/" + participation.getId() + "/trigger-failed-build", null, HttpStatus.FORBIDDEN, null);
    request.delete("/api/exercises/" + programmingExercise1.getId() + "/cleanup", HttpStatus.FORBIDDEN);
    programmingExercise2 = programmingExerciseRepository.save(programmingExercise2);
    request.delete("/api/programming-exercises/" + programmingExercise2.getId(), HttpStatus.FORBIDDEN);
    // Reset
    featureToggleService.enableFeature(Feature.ProgrammingExercises);
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) HashMap(java.util.HashMap) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 12 with ProgrammingSubmission

use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.

the class ProgrammingExerciseTest method findAppropriateSubmissionRespectingIndividualDueDate.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void findAppropriateSubmissionRespectingIndividualDueDate(boolean isSubmissionAfterIndividualDueDate) {
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(programmingExerciseId);
    exercise.setDueDate(ZonedDateTime.now());
    exercise = programmingExerciseRepository.save(exercise);
    ProgrammingSubmission submission = new ProgrammingSubmission();
    submission.setType(SubmissionType.OTHER);
    if (isSubmissionAfterIndividualDueDate) {
        submission.setSubmissionDate(ZonedDateTime.now().plusHours(26));
    } else {
        // submission time after exercise due date but before individual due date
        submission.setSubmissionDate(ZonedDateTime.now().plusHours(1));
    }
    submission = database.addProgrammingSubmission(exercise, submission, "student1");
    ProgrammingExerciseStudentParticipation participation = participationRepository.findByExerciseIdAndStudentLogin(programmingExerciseId, "student1").get();
    participation.setIndividualDueDate(ZonedDateTime.now().plusDays(1));
    submission.setParticipation(participation);
    Submission latestValidSubmission = exercise.findAppropriateSubmissionByResults(Set.of(submission));
    if (isSubmissionAfterIndividualDueDate) {
        assertThat(latestValidSubmission).isNull();
    } else {
        assertThat(latestValidSubmission).isEqualTo(submission);
    }
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Submission(de.tum.in.www1.artemis.domain.Submission) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with ProgrammingSubmission

use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.

the class ProgrammingSubmissionAndResultGitlabJenkinsIntegrationTest method shouldReceiveBuildLogsOnNewStudentParticipationResult.

@Test
@WithMockUser(username = "student1", roles = "USER")
void shouldReceiveBuildLogsOnNewStudentParticipationResult() throws Exception {
    // Precondition: Database has participation and a programming submission.
    String userLogin = "student1";
    database.addCourseWithOneProgrammingExercise(false, false, ProgrammingLanguage.JAVA);
    ProgrammingExercise exercise = programmingExerciseRepository.findAllWithEagerParticipationsAndLegalSubmissions().get(1);
    var participation = database.addStudentParticipationForProgrammingExercise(exercise, userLogin);
    var submission = database.createProgrammingSubmission(participation, false);
    List<String> logs = new ArrayList<>();
    logs.add("[2021-05-10T15:19:49.740Z] [ERROR] BubbleSort.java:[15,9] not a statement");
    logs.add("[2021-05-10T15:19:49.740Z] [ERROR] BubbleSort.java:[15,10] ';' expected");
    var notification = createJenkinsNewResultNotification(exercise.getProjectKey(), userLogin, ProgrammingLanguage.JAVA, List.of());
    notification.setLogs(logs);
    postResult(notification, HttpStatus.OK);
    var submissionWithLogsOptional = submissionRepository.findWithEagerBuildLogEntriesById(submission.getId());
    assertThat(submissionWithLogsOptional).isPresent();
    // Assert that the submission contains build log entries
    ProgrammingSubmission submissionWithLogs = submissionWithLogsOptional.get();
    List<BuildLogEntry> buildLogEntries = submissionWithLogs.getBuildLogEntries();
    assertThat(buildLogEntries).hasSize(2);
    assertThat(buildLogEntries.get(0).getLog()).isEqualTo("[ERROR] BubbleSort.java:[15,9] not a statement");
    assertThat(buildLogEntries.get(1).getLog()).isEqualTo("[ERROR] BubbleSort.java:[15,10] ';' expected");
}
Also used : BuildLogEntry(de.tum.in.www1.artemis.domain.BuildLogEntry) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ArrayList(java.util.ArrayList) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationJenkinsGitlabTest(de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with ProgrammingSubmission

use of de.tum.in.www1.artemis.domain.ProgrammingSubmission in project ArTEMiS by ls1intum.

the class ProgrammingSubmissionAndResultIntegrationTestService method postSubmission.

/**
 * This is the simulated request from the VCS to Artemis on a new commit.
 * @return The submission that was created
 */
public ProgrammingSubmission postSubmission(Long participationId, HttpStatus expectedStatus, String jsonRequest) throws Exception {
    JSONParser jsonParser = new JSONParser();
    Object obj = jsonParser.parse(jsonRequest);
    // Api should return ok.
    request.postWithoutLocation(PROGRAMMING_SUBMISSION_RESOURCE_API_PATH + participationId, obj, expectedStatus, new HttpHeaders());
    List<ProgrammingSubmission> submissions = programmingSubmissionRepository.findAll();
    // Submission should have been created for the participation.
    assertThat(submissions).hasSize(1);
    // Make sure that both the submission and participation are correctly linked with each other.
    return submissions.get(0);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) JSONParser(org.json.simple.parser.JSONParser)

Example 15 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)

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