Search in sources :

Example 1 with ProgrammingExerciseTestCase

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

the class ProgrammingExerciseSolutionEntryResource method deleteSolutionEntry.

/**
 * DELETE programming-exercises/:exerciseId/test-cases/:testCaseId/solution-entries/:solutionEntryId : Delete a solution entry
 * @param exerciseId of the exercise
 * @param testCaseId of the test case
 * @param solutionEntryId of the solution entry that is to be deleted
 * @return the {@link ResponseEntity} with status {@code 204},
 * or with status {@code 409 (Conflict)} if the exerciseId, testcaseId, or solutionEntryId are not valid.
 */
@DeleteMapping("programming-exercises/{exerciseId}/test-cases/{testCaseId}/solution-entries/{solutionEntryId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteSolutionEntry(@PathVariable Long exerciseId, @PathVariable Long testCaseId, @PathVariable Long solutionEntryId) {
    log.debug("REST request to delete SolutionEntry with id : {}", solutionEntryId);
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
    authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
    ProgrammingExerciseTestCase testCase = programmingExerciseTestCaseRepository.findByIdWithExerciseElseThrow(testCaseId);
    ProgrammingExerciseSolutionEntry solutionEntry = programmingExerciseSolutionEntryRepository.findByIdWithTestCaseAndProgrammingExerciseElseThrow(solutionEntryId);
    checkExerciseContainsTestCaseElseThrow(exercise, testCase);
    checkTestCaseContainsSolutionEntryElseThrow(testCase, solutionEntry);
    programmingExerciseSolutionEntryRepository.deleteById(solutionEntryId);
    return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, solutionEntry.toString())).build();
}
Also used : ProgrammingExerciseSolutionEntry(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ProgrammingExerciseTestCase

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

the class CodeHintServiceTest method addTaskToExercise.

private ProgrammingExerciseTask addTaskToExercise(String name, List<ProgrammingExerciseTestCase> testCases) {
    var task = new ProgrammingExerciseTask();
    task.setExercise(exercise);
    task.setTaskName(name);
    task = taskRepository.save(task);
    for (int i = 0; i < testCases.size(); i++) {
        ProgrammingExerciseTestCase testCase = testCases.get(i);
        testCase.getTasks().add(task);
        testCases.set(i, testCaseRepository.save(testCase));
    }
    task.setTestCases(new HashSet<>(testCases));
    return task;
}
Also used : ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)

Example 3 with ProgrammingExerciseTestCase

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

the class HestiaDatabaseTest method addCodeHintToProgrammingExercise.

@Test
void addCodeHintToProgrammingExercise() {
    var programmingExercise = programmingExerciseRepository.getById(programmingExerciseId);
    database.addTestCasesToProgrammingExercise(programmingExercise);
    var testCases = programmingExerciseTestCaseRepository.findByExerciseId(programmingExerciseId);
    assertThat(testCases).isNotEmpty();
    var task = addTaskToProgrammingExercise("Task 1");
    task.setTestCases(testCases);
    task = programmingExerciseTaskRepository.save(task);
    Set<ProgrammingExerciseSolutionEntry> allSolutionEntries = new HashSet<>();
    for (ProgrammingExerciseTestCase testCase : testCases) {
        var solutionEntries = addSolutionEntriesToTestCase(2, testCase);
        assertThat(programmingExerciseSolutionEntryRepository.findByTestCaseId(testCase.getId())).containsExactly(solutionEntries);
        allSolutionEntries.addAll(List.of(solutionEntries));
    }
    var codeHint = (CodeHint) new CodeHint();
    codeHint.setProgrammingExerciseTask(task);
    codeHint.setExercise(programmingExercise);
    codeHint.setTitle("Code Hint 1");
    codeHint = codeHintRepository.save(codeHint);
    for (ProgrammingExerciseSolutionEntry solutionEntry : allSolutionEntries) {
        solutionEntry.setCodeHint(codeHint);
        programmingExerciseSolutionEntryRepository.save(solutionEntry);
    }
    codeHint.setSolutionEntries(allSolutionEntries);
    codeHint = codeHintRepository.save(codeHint);
    task.setExerciseHints(Set.of(codeHint));
    programmingExerciseTaskRepository.save(task);
    assertThat(programmingExerciseSolutionEntryRepository.findByCodeHintId(codeHint.getId())).isEqualTo(allSolutionEntries);
    assertThat(codeHintRepository.findByExerciseId(programmingExerciseId)).containsExactly(codeHint);
}
Also used : ProgrammingExerciseSolutionEntry(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) HashSet(java.util.HashSet) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 4 with ProgrammingExerciseTestCase

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

the class HestiaDatabaseTest method addSolutionEntriesToTestCase.

ProgrammingExerciseSolutionEntry[] addSolutionEntriesToTestCase(int count, ProgrammingExerciseTestCase testCase) {
    var solutionEntries = new ProgrammingExerciseSolutionEntry[count];
    for (int i = 0; i < count; i++) {
        var solutionEntry = new ProgrammingExerciseSolutionEntry();
        solutionEntry.setTestCase(testCase);
        solutionEntry.setCode("Code block 1");
        solutionEntry.setLine(i);
        solutionEntry = programmingExerciseSolutionEntryRepository.save(solutionEntry);
        solutionEntries[i] = solutionEntry;
    }
    return solutionEntries;
}
Also used : ProgrammingExerciseSolutionEntry(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint)

Example 5 with ProgrammingExerciseTestCase

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

the class ProgrammingExerciseSolutionEntryIntegrationTest method testGetSolutionEntriesByTestCaseId.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetSolutionEntriesByTestCaseId() throws Exception {
    ProgrammingExerciseTestCase testCase = programmingExerciseTestCaseRepository.findByExerciseIdWithSolutionEntries(programmingExercise.getId()).stream().findFirst().orElseThrow();
    final var solutionEntries = new HashSet<>(request.getList("/api/programming-exercises/" + programmingExercise.getId() + "/test-cases/" + testCase.getId() + "/solution-entries", HttpStatus.OK, ProgrammingExerciseSolutionEntry.class));
    assertThat(solutionEntries).isEqualTo(testCase.getSolutionEntries());
}
Also used : ProgrammingExerciseSolutionEntry(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) HashSet(java.util.HashSet) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)64 Test (org.junit.jupiter.api.Test)48 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)42 WithMockUser (org.springframework.security.test.context.support.WithMockUser)34 ProgrammingExerciseSolutionEntry (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseSolutionEntry)28 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 BeforeEach (org.junit.jupiter.api.BeforeEach)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 GroupedFile (de.tum.in.www1.artemis.service.hestia.behavioral.GroupedFile)8 ProgrammingLanguage (de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)6 CodeHint (de.tum.in.www1.artemis.domain.hestia.CodeHint)6 ProgrammingExerciseTask (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTask)6 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)6 ProgrammingExerciseTestCaseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository)6 ProgrammingExerciseTestCaseDTO (de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)4 Visibility (de.tum.in.www1.artemis.domain.enumeration.Visibility)4