Search in sources :

Example 1 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project ArTEMiS by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForCourse.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForCourse() throws Exception {
    createGradeScale();
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.GRADE);
    assertThat(gradeStepsDTO.title).isEqualTo(course.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 2 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project ArTEMiS by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForExam.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForExam() throws Exception {
    exam.setPublishResultsDate(ZonedDateTime.now());
    examRepository.save(exam);
    GradeStep gradeStep1 = new GradeStep();
    GradeStep gradeStep2 = new GradeStep();
    gradeStep1.setGradeName("Name1");
    gradeStep2.setGradeName("Name2");
    gradeStep1.setLowerBoundPercentage(0);
    gradeStep1.setUpperBoundPercentage(60);
    gradeStep2.setUpperBoundInclusive(true);
    gradeStep2.setLowerBoundPercentage(60);
    gradeStep2.setUpperBoundPercentage(100);
    gradeStep1.setGradingScale(examGradingScale);
    gradeStep2.setGradingScale(examGradingScale);
    gradeSteps = Set.of(gradeStep1, gradeStep2);
    examGradingScale.setGradeSteps(gradeSteps);
    examGradingScale.setGradeType(GradeType.BONUS);
    gradingScaleRepository.save(examGradingScale);
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.BONUS);
    assertThat(gradeStepsDTO.title).isEqualTo(exam.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project Artemis by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForExam.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForExam() throws Exception {
    exam.setPublishResultsDate(ZonedDateTime.now());
    examRepository.save(exam);
    GradeStep gradeStep1 = new GradeStep();
    GradeStep gradeStep2 = new GradeStep();
    gradeStep1.setGradeName("Name1");
    gradeStep2.setGradeName("Name2");
    gradeStep1.setLowerBoundPercentage(0);
    gradeStep1.setUpperBoundPercentage(60);
    gradeStep2.setUpperBoundInclusive(true);
    gradeStep2.setLowerBoundPercentage(60);
    gradeStep2.setUpperBoundPercentage(100);
    gradeStep1.setGradingScale(examGradingScale);
    gradeStep2.setGradingScale(examGradingScale);
    gradeSteps = Set.of(gradeStep1, gradeStep2);
    examGradingScale.setGradeSteps(gradeSteps);
    examGradingScale.setGradeType(GradeType.BONUS);
    gradingScaleRepository.save(examGradingScale);
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.BONUS);
    assertThat(gradeStepsDTO.title).isEqualTo(exam.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project Artemis by ls1intum.

the class GradeStepIntegrationTest method testGetAllGradeStepsForCourse.

/**
 * Test get request for all grade steps
 *
 * @throws Exception
 */
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetAllGradeStepsForCourse() throws Exception {
    createGradeScale();
    GradeStepsDTO gradeStepsDTO = request.get("/api/courses/" + course.getId() + "/grading-scale/grade-steps", HttpStatus.OK, GradeStepsDTO.class);
    assertThat(gradeStepsDTO.gradeType).isEqualTo(GradeType.GRADE);
    assertThat(gradeStepsDTO.title).isEqualTo(course.getTitle());
    assertThat(gradeStepsDTO.gradeSteps).usingRecursiveComparison().ignoringFields("gradingScale", "id").ignoringCollectionOrder().isEqualTo(gradeSteps);
}
Also used : GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 5 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project ArTEMiS by ls1intum.

the class GradeStepResource method getAllGradeStepsForCourse.

/**
 * GET /courses/{courseId}/grading-scale/grade-steps : Find all grade steps for the grading scale of a course
 *
 * @param courseId the course to which the grading scale belongs
 * @return ResponseEntity with status 200 (Ok) with body a list of grade steps if the grading scale exists and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/grading-scale/grade-steps")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeStepsDTO> getAllGradeStepsForCourse(@PathVariable Long courseId) {
    log.debug("REST request to get all grade steps for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    GradingScale gradingScale = gradingScaleRepository.findByCourseIdOrElseThrow(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
    GradeStepsDTO gradeStepsDTO = prepareGradeStepsDTO(gradingScale, course.getMaxPoints(), course.getTitle());
    return ResponseEntity.ok(gradeStepsDTO);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GradeStepsDTO (de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO)8 Course (de.tum.in.www1.artemis.domain.Course)4 GradingScale (de.tum.in.www1.artemis.domain.GradingScale)4 Test (org.junit.jupiter.api.Test)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 User (de.tum.in.www1.artemis.domain.User)2 Exam (de.tum.in.www1.artemis.domain.exam.Exam)2 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)2