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();
}
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;
}
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);
}
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;
}
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());
}
Aggregations