Search in sources :

Example 1 with ProgrammingExerciseTestCaseDTO

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);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) Feedback(de.tum.in.www1.artemis.domain.Feedback) ProgrammingExerciseTestCaseType(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType) ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) ProgrammingExerciseTestCaseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) Visibility(de.tum.in.www1.artemis.domain.enumeration.Visibility) ProgrammingExerciseTestCaseService(de.tum.in.www1.artemis.service.programming.ProgrammingExerciseTestCaseService) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.jupiter.api.Test) ProgrammingExerciseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Feedback(de.tum.in.www1.artemis.domain.Feedback) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) WithMockUser(org.springframework.security.test.context.support.WithMockUser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ProgrammingExerciseTestCaseDTO

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);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) Feedback(de.tum.in.www1.artemis.domain.Feedback) ProgrammingExerciseTestCaseType(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType) ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) ProgrammingExerciseTestCaseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) Visibility(de.tum.in.www1.artemis.domain.enumeration.Visibility) ProgrammingExerciseTestCaseService(de.tum.in.www1.artemis.service.programming.ProgrammingExerciseTestCaseService) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.jupiter.api.Test) ProgrammingExerciseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WithMockUser(org.springframework.security.test.context.support.WithMockUser) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) Feedback(de.tum.in.www1.artemis.domain.Feedback) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) WithMockUser(org.springframework.security.test.context.support.WithMockUser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ProgrammingExerciseTestCaseDTO

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);
}
Also used : ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with ProgrammingExerciseTestCaseDTO

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);
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) ProgrammingExerciseTestCase(de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase) 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 5 with ProgrammingExerciseTestCaseDTO

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;
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) AuditEventRepository(org.springframework.boot.actuate.audit.AuditEventRepository) ProgrammingExerciseTestCaseType(de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType) ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) LoggerFactory(org.slf4j.LoggerFactory) ProgrammingExerciseTestCaseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository) Visibility(de.tum.in.www1.artemis.domain.enumeration.Visibility) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO) Constants(de.tum.in.www1.artemis.config.Constants) ProgrammingExerciseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository) ProgrammingExerciseTaskService(de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) ErrorConstants(de.tum.in.www1.artemis.web.rest.errors.ErrorConstants) AuditEvent(org.springframework.boot.actuate.audit.AuditEvent) Service(org.springframework.stereotype.Service) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ProgrammingExerciseTestCaseDTO(de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO)

Aggregations

ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)6 ProgrammingExerciseTestCaseDTO (de.tum.in.www1.artemis.web.rest.dto.ProgrammingExerciseTestCaseDTO)6 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)4 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)4 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)4 ProgrammingLanguage (de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)4 Visibility (de.tum.in.www1.artemis.domain.enumeration.Visibility)4 ProgrammingExerciseTestCaseType (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType)4 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)4 ProgrammingExerciseTestCaseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository)4 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Constants (de.tum.in.www1.artemis.config.Constants)2 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)2 Feedback (de.tum.in.www1.artemis.domain.Feedback)2 ProgrammingExerciseTaskService (de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService)2