Search in sources :

Example 21 with ProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project Artemis by ls1intum.

the class ProgrammingSubmissionIntegrationTest method triggerBuildInstructor_cannotGetLastCommitHash.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildInstructor_cannotGetLastCommitHash() throws Exception {
    bambooRequestMockProvider.enableMockingOfRequests();
    doThrow(EntityNotFoundException.class).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.NOT_FOUND, new HttpHeaders());
}
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 22 with ProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation 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 23 with ProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation in project Artemis by ls1intum.

the class RepositoryProgrammingExerciseParticipationJenkinsIntegrationTest method testGetLatestBuildLogsFails.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetLatestBuildLogsFails() throws Exception {
    var programmingExercise = programmingExerciseRepository.findAllWithEagerParticipations().get(0);
    database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
    var submission = new ProgrammingSubmission();
    submission.setSubmissionDate(ZonedDateTime.now().minusMinutes(4));
    submission.setSubmitted(true);
    submission.setCommitHash(TestConstants.COMMIT_HASH_STRING);
    submission.setType(SubmissionType.MANUAL);
    submission.setBuildFailed(true);
    List<BuildLogEntry> buildLogEntries = new ArrayList<>();
    buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry1", submission));
    buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry2", submission));
    buildLogEntries.add(new BuildLogEntry(ZonedDateTime.now(), "LogEntry3", submission));
    submission.setBuildLogEntries(buildLogEntries);
    database.addProgrammingSubmission(programmingExercise, submission, "student1");
    buildLogEntryRepository.deleteAll();
    var participation = studentParticipationRepository.findAll().get(0);
    ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) submission.getParticipation();
    var jobWithDetails = mock(JobWithDetails.class);
    jenkinsRequestMockProvider.mockGetJob(programmingExercise.getProjectKey(), programmingExerciseParticipation.getBuildPlanId(), jobWithDetails, false);
    var lastBuild = mock(Build.class);
    doReturn(lastBuild).when(jobWithDetails).getLastBuild();
    doThrow(IOException.class).when(lastBuild).details();
    var url = "/api/repository/" + participation.getId() + "/buildlogs";
    request.getList(url, HttpStatus.INTERNAL_SERVER_ERROR, BuildLogEntry.class);
}
Also used : BuildLogEntry(de.tum.in.www1.artemis.domain.BuildLogEntry) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation) ArrayList(java.util.ArrayList) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationJenkinsGitlabTest(de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest)

Example 24 with ProgrammingExerciseParticipation

use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation 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)

Aggregations

ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)16 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)12 ProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 HttpHeaders (org.springframework.http.HttpHeaders)8 ProgrammingSubmission (de.tum.in.www1.artemis.domain.ProgrammingSubmission)4 ProgrammingLanguage (de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)4 Participation (de.tum.in.www1.artemis.domain.participation.Participation)4 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)4 Nullable (javax.annotation.Nullable)4 NotNull (javax.validation.constraints.NotNull)4 ResponseEntity (org.springframework.http.ResponseEntity)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AbstractSpringIntegrationJenkinsGitlabTest (de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest)2 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2