use of de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestCaseServiceTest method shouldAllowTestCaseWeightSumZeroManualAssessment.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@EnumSource(AssessmentType.class)
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldAllowTestCaseWeightSumZeroManualAssessment(AssessmentType assessmentType) throws Exception {
// for non-automatic exercises the update succeeds and triggers an update
if (assessmentType != AssessmentType.AUTOMATIC) {
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getSolutionParticipation());
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getTemplateParticipation());
}
programmingExercise.setAssessmentType(assessmentType);
programmingExerciseRepository.save(programmingExercise);
List<Feedback> feedbacks = new ArrayList<>();
feedbacks.add(new Feedback().text("test1"));
feedbacks.add(new Feedback().text("test2"));
feedbacks.add(new Feedback().text("test3"));
testCaseService.generateTestCasesFromFeedbacks(feedbacks, programmingExercise);
Set<ProgrammingExerciseTestCase> testCases = testCaseRepository.findByExerciseId(programmingExercise.getId());
Set<ProgrammingExerciseTestCaseDTO> testCaseDTOs = testCases.stream().map(testCase -> {
final ProgrammingExerciseTestCaseDTO testCaseDTO = new ProgrammingExerciseTestCaseDTO();
testCaseDTO.setId(testCase.getId());
testCaseDTO.setBonusMultiplier(testCase.getBonusMultiplier());
testCaseDTO.setBonusPoints(testCase.getBonusPoints());
testCaseDTO.setVisibility(testCase.getVisibility());
testCaseDTO.setWeight(0.0);
return testCaseDTO;
}).collect(Collectors.toSet());
if (assessmentType == AssessmentType.AUTOMATIC) {
assertThatThrownBy(() -> testCaseService.update(programmingExercise.getId(), testCaseDTOs)).isInstanceOf(BadRequestAlertException.class).hasMessageContaining("The sum of all test case weights is 0 or below.");
} else {
Set<ProgrammingExerciseTestCase> updated = testCaseService.update(programmingExercise.getId(), testCaseDTOs);
assertThat(updated).hasSize(3);
assertThat(updated).allMatch(testCase -> testCase.getWeight() == 0.0);
}
}
use of de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO in project Artemis by ls1intum.
the class ProgrammingExerciseTestCaseServiceTest method shouldAllowTestCaseWeightSumZeroManualAssessment.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@EnumSource(AssessmentType.class)
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldAllowTestCaseWeightSumZeroManualAssessment(AssessmentType assessmentType) throws Exception {
// for non-automatic exercises the update succeeds and triggers an update
if (assessmentType != AssessmentType.AUTOMATIC) {
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getSolutionParticipation());
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getTemplateParticipation());
}
programmingExercise.setAssessmentType(assessmentType);
programmingExerciseRepository.save(programmingExercise);
List<Feedback> feedbacks = new ArrayList<>();
feedbacks.add(new Feedback().text("test1"));
feedbacks.add(new Feedback().text("test2"));
feedbacks.add(new Feedback().text("test3"));
testCaseService.generateTestCasesFromFeedbacks(feedbacks, programmingExercise);
Set<ProgrammingExerciseTestCase> testCases = testCaseRepository.findByExerciseId(programmingExercise.getId());
Set<ProgrammingExerciseTestCaseDTO> testCaseDTOs = testCases.stream().map(testCase -> {
final ProgrammingExerciseTestCaseDTO testCaseDTO = new ProgrammingExerciseTestCaseDTO();
testCaseDTO.setId(testCase.getId());
testCaseDTO.setBonusMultiplier(testCase.getBonusMultiplier());
testCaseDTO.setBonusPoints(testCase.getBonusPoints());
testCaseDTO.setVisibility(testCase.getVisibility());
testCaseDTO.setWeight(0.0);
return testCaseDTO;
}).collect(Collectors.toSet());
if (assessmentType == AssessmentType.AUTOMATIC) {
assertThatThrownBy(() -> testCaseService.update(programmingExercise.getId(), testCaseDTOs)).isInstanceOf(BadRequestAlertException.class).hasMessageContaining("The sum of all test case weights is 0 or below.");
} else {
Set<ProgrammingExerciseTestCase> updated = testCaseService.update(programmingExercise.getId(), testCaseDTOs);
assertThat(updated).hasSize(3);
assertThat(updated).allMatch(testCase -> testCase.getWeight() == 0.0);
}
}
use of de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestCaseResource method updateTestCases.
/**
* Update the changeable fields of the provided test case dtos.
* We don't transfer the whole test case object here, because we need to make sure that only weights and visibility can be updated!
* Will only return test case objects in the response that could be updated.
*
* @param exerciseId of exercise the test cases belong to.
* @param testCaseProgrammingExerciseTestCaseDTOS of the test cases to update the weights and visibility of.
* @return the set of test cases for the given programming exercise.
*/
@PatchMapping(Endpoints.UPDATE_TEST_CASES)
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Set<ProgrammingExerciseTestCase>> updateTestCases(@PathVariable Long exerciseId, @RequestBody Set<ProgrammingExerciseTestCaseDTO> testCaseProgrammingExerciseTestCaseDTOS) {
log.debug("REST request to update the weights {} of the exercise {}", testCaseProgrammingExerciseTestCaseDTOS, exerciseId);
var programmingExercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, programmingExercise, null);
Set<ProgrammingExerciseTestCase> updatedTests = programmingExerciseTestCaseService.update(exerciseId, testCaseProgrammingExerciseTestCaseDTOS);
// A test case is now marked as AFTER_DUE_DATE: a scheduled score update might be needed.
if (updatedTests.stream().anyMatch(ProgrammingExerciseTestCase::isAfterDueDate)) {
programmingExerciseService.scheduleOperations(programmingExercise.getId());
}
// We don't need the linked exercise here.
for (ProgrammingExerciseTestCase testCase : updatedTests) {
testCase.setExercise(null);
}
return ResponseEntity.ok(updatedTests);
}
use of de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestCaseServiceTest method shouldUpdateTestWeight.
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void shouldUpdateTestWeight() throws Exception {
// After a test case update, the solution and template repository should be build, so the ContinuousIntegrationService needs to be triggered
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getSolutionParticipation());
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getTemplateParticipation());
String dummyHash = "9b3a9bd71a0d80e5bbc42204c319ed3d1d4f0d6d";
doReturn(ObjectId.fromString(dummyHash)).when(gitService).getLastCommitHash(any());
database.addProgrammingParticipationWithResultForExercise(programmingExercise, "student1");
ProgrammingExerciseTestCase testCase = testCaseRepository.findAll().get(0);
Set<ProgrammingExerciseTestCaseDTO> programmingExerciseTestCaseDTOS = new HashSet<>();
ProgrammingExerciseTestCaseDTO programmingExerciseTestCaseDTO = new ProgrammingExerciseTestCaseDTO();
programmingExerciseTestCaseDTO.setId(testCase.getId());
programmingExerciseTestCaseDTO.setWeight(400.0);
programmingExerciseTestCaseDTO.setBonusMultiplier(1.0);
programmingExerciseTestCaseDTO.setBonusPoints(0.0);
programmingExerciseTestCaseDTO.setVisibility(Visibility.ALWAYS);
programmingExerciseTestCaseDTOS.add(programmingExerciseTestCaseDTO);
assertThat(programmingExercise.getTestCasesChanged()).isFalse();
testCaseService.update(programmingExercise.getId(), programmingExerciseTestCaseDTOS);
ProgrammingExercise updatedProgrammingExercise = programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(programmingExercise.getId()).get();
assertThat(testCaseRepository.findById(testCase.getId()).get().getWeight()).isEqualTo(400);
assertThat(updatedProgrammingExercise.getTestCasesChanged()).isTrue();
verify(groupNotificationService, times(1)).notifyEditorAndInstructorGroupsAboutChangedTestCasesForProgrammingExercise(updatedProgrammingExercise);
verify(websocketMessagingService, times(1)).sendMessage("/topic/programming-exercises/" + programmingExercise.getId() + "/test-cases-changed", true);
}
use of de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestCaseService method update.
/**
* Update the updatable attributes of the provided test case dtos. Returns an entry in the set for each test case that could be updated.
*
* @param exerciseId of exercise the test cases belong to.
* @param testCaseProgrammingExerciseTestCaseDTOS of the test cases to update the weights and visibility of.
* @return the updated test cases.
* @throws EntityNotFoundException if the programming exercise could not be found.
*/
public Set<ProgrammingExerciseTestCase> update(Long exerciseId, Set<ProgrammingExerciseTestCaseDTO> testCaseProgrammingExerciseTestCaseDTOS) throws EntityNotFoundException {
ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithTestCasesById(exerciseId).orElseThrow(() -> new EntityNotFoundException("Programming Exercise", exerciseId));
Set<ProgrammingExerciseTestCase> existingTestCases = programmingExercise.getTestCases();
Set<ProgrammingExerciseTestCase> updatedTests = new HashSet<>();
for (ProgrammingExerciseTestCaseDTO programmingExerciseTestCaseDTO : testCaseProgrammingExerciseTestCaseDTOS) {
Optional<ProgrammingExerciseTestCase> matchingTestCaseOpt = existingTestCases.stream().filter(testCase -> testCase.getId().equals(programmingExerciseTestCaseDTO.getId())).findFirst();
if (matchingTestCaseOpt.isEmpty()) {
continue;
}
ProgrammingExerciseTestCase matchingTestCase = matchingTestCaseOpt.get();
matchingTestCase.setWeight(programmingExerciseTestCaseDTO.getWeight());
matchingTestCase.setVisibility(programmingExerciseTestCaseDTO.getVisibility());
matchingTestCase.setBonusMultiplier(programmingExerciseTestCaseDTO.getBonusMultiplier());
matchingTestCase.setBonusPoints(programmingExerciseTestCaseDTO.getBonusPoints());
validateTestCase(matchingTestCase);
updatedTests.add(matchingTestCase);
}
if (!isTestCaseWeightSumValid(programmingExercise, existingTestCases)) {
throw new BadRequestAlertException("The sum of all test case weights is 0 or below.", "TestCaseGrading", "weightSumError", true);
}
testCaseRepository.saveAll(updatedTests);
programmingExerciseTaskService.updateTasksFromProblemStatement(programmingExercise);
// At least one test was updated with a new weight or runAfterDueDate flag. We use this flag to inform the instructor about outdated student results.
programmingSubmissionService.setTestCasesChangedAndTriggerTestCaseUpdate(exerciseId);
return updatedTests;
}
Aggregations