Search in sources :

Example 1 with Visibility

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

the class UserTestService method updateUserNotificationVisibilityHideUntilAsStudentIsSuccessful.

// Test
public void updateUserNotificationVisibilityHideUntilAsStudentIsSuccessful() throws Exception {
    request.put("/api/users/notification-visibility", false, HttpStatus.OK);
    User userInDB = userRepository.findOneByLogin("student1").get();
    assertThat(userInDB.getHideNotificationsUntil()).isNotNull();
    assertThat(userInDB.getHideNotificationsUntil()).isStrictlyBetween(ZonedDateTime.now().minusSeconds(1), ZonedDateTime.now().plusSeconds(1));
}
Also used : User(de.tum.in.www1.artemis.domain.User)

Example 2 with Visibility

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

the class UserTestService method updateUserNotificationVisibilityShowAllAsStudentIsSuccessful.

// Test
public void updateUserNotificationVisibilityShowAllAsStudentIsSuccessful() throws Exception {
    request.put("/api/users/notification-visibility", true, HttpStatus.OK);
    User userInDB = userRepository.findOneByLogin("student1").get();
    assertThat(userInDB.getHideNotificationsUntil()).isNull();
}
Also used : User(de.tum.in.www1.artemis.domain.User)

Example 3 with Visibility

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

the class ProgrammingExerciseGradingServiceTest method shouldRecalculateScoreWithTestCaseBonusButNoExerciseBonus.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldRecalculateScoreWithTestCaseBonusButNoExerciseBonus() {
    // Set up test cases with bonus
    var testCases = testCaseService.findByExerciseId(programmingExercise.getId()).stream().collect(Collectors.toMap(ProgrammingExerciseTestCase::getTestName, Function.identity()));
    testCases.get("test1").active(true).visibility(Visibility.ALWAYS).weight(5.).bonusMultiplier(1D).setBonusPoints(7D);
    testCases.get("test2").active(true).visibility(Visibility.ALWAYS).weight(2.).bonusMultiplier(2D).setBonusPoints(0D);
    testCases.get("test3").active(true).visibility(Visibility.ALWAYS).weight(3.).bonusMultiplier(1D).setBonusPoints(10.5D);
    testCaseRepository.saveAll(testCases.values());
    Participation participation = database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
    var result1 = new Result();
    result1.setParticipation(participation);
    result1 = updateAndSaveAutomaticResult(result1, false, false, true);
    var result2 = new Result();
    result2.setParticipation(participation);
    result2 = updateAndSaveAutomaticResult(result2, true, false, false);
    var result3 = new Result();
    result3.setParticipation(participation);
    result3 = updateAndSaveAutomaticResult(result3, false, true, false);
    var result4 = new Result();
    result4.setParticipation(participation);
    result4 = updateAndSaveAutomaticResult(result4, false, true, true);
    var result5 = new Result();
    result5.setParticipation(participation);
    result5 = updateAndSaveAutomaticResult(result5, true, true, true);
    var result6 = new Result();
    result6.setParticipation(participation);
    result6 = updateAndSaveAutomaticResult(result6, false, false, false);
    // Build failure
    var resultBF = new Result().feedbacks(List.of()).rated(true).score(0D).hasFeedback(false).resultString("Build Failed").completionDate(ZonedDateTime.now()).assessmentType(AssessmentType.AUTOMATIC);
    resultBF.setParticipation(participation);
    gradingService.calculateScoreForResult(resultBF, programmingExercise, true);
    // Missing feedback
    var resultMF = new Result();
    resultMF.setParticipation(participation);
    var feedbackMF = new Feedback().result(result).text("test3").positive(true).type(FeedbackType.AUTOMATIC).result(resultMF);
    // List must be mutable
    resultMF.feedbacks(new ArrayList<>(List.of(feedbackMF))).rated(true).score(0D).hasFeedback(true).completionDate(ZonedDateTime.now()).assessmentType(AssessmentType.AUTOMATIC);
    gradingService.calculateScoreForResult(resultMF, programmingExercise, true);
    // Assertions result1 - calculated
    assertThat(result1.getScore()).isEqualTo(55D, Offset.offset(offsetByTenThousandth));
    assertThat(result1.getResultString()).isEqualTo("1 of 3 passed");
    assertThat(result1.getHasFeedback()).isTrue();
    assertThat(result1.isSuccessful()).isFalse();
    assertThat(result1.getFeedbacks()).hasSize(3);
    // Assertions result2 - calculated
    assertThat(result2.getScore()).isEqualTo(66.6667);
    assertThat(result2.getResultString()).isEqualTo("1 of 3 passed");
    assertThat(result2.getHasFeedback()).isTrue();
    assertThat(result2.isSuccessful()).isFalse();
    assertThat(result2.getFeedbacks()).hasSize(3);
    // Assertions result3 - calculated
    assertThat(result3.getScore()).isEqualTo(40D);
    assertThat(result3.getResultString()).isEqualTo("1 of 3 passed");
    assertThat(result3.getHasFeedback()).isTrue();
    assertThat(result3.isSuccessful()).isFalse();
    assertThat(result3.getFeedbacks()).hasSize(3);
    // Assertions result4 - calculated
    assertThat(result4.getScore()).isEqualTo(95D, Offset.offset(offsetByTenThousandth));
    assertThat(result4.getResultString()).isEqualTo("2 of 3 passed");
    assertThat(result4.getHasFeedback()).isTrue();
    assertThat(result4.isSuccessful()).isFalse();
    assertThat(result4.getFeedbacks()).hasSize(3);
    // Assertions result5 - capped to 100
    assertThat(result5.getScore()).isEqualTo(100D);
    assertThat(result5.getResultString()).isEqualTo("3 of 3 passed");
    assertThat(result5.getHasFeedback()).isFalse();
    assertThat(result5.isSuccessful()).isTrue();
    assertThat(result5.getFeedbacks()).hasSize(3);
    // Assertions result6 - only negative feedback
    assertThat(result6.getScore()).isEqualTo(0D);
    assertThat(result6.getResultString()).isEqualTo("0 of 3 passed");
    assertThat(result6.getHasFeedback()).isTrue();
    assertThat(result6.isSuccessful()).isFalse();
    assertThat(result6.getFeedbacks()).hasSize(3);
    // Assertions resultBF - build failure
    assertThat(resultBF.getScore()).isEqualTo(0D);
    // Won't get touched by the service method
    assertThat(resultBF.getResultString()).isEqualTo("Build Failed");
    assertThat(resultBF.getHasFeedback()).isFalse();
    // Won't get touched by the service method
    assertThat(resultBF.isSuccessful()).isNull();
    assertThat(resultBF.getFeedbacks()).isEmpty();
    // Assertions resultMF - missing feedback will be created but is negative
    assertThat(resultMF.getScore()).isEqualTo(55D, Offset.offset(offsetByTenThousandth));
    assertThat(resultMF.getResultString()).isEqualTo("1 of 3 passed");
    // Generated missing feedback is omitted
    assertThat(resultMF.getHasFeedback()).isFalse();
    assertThat(resultMF.isSuccessful()).isFalse();
    // Feedback is created for test cases if missing
    assertThat(resultMF.getFeedbacks()).hasSize(3);
}
Also used : Participation(de.tum.in.www1.artemis.domain.participation.Participation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) SolutionProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) 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 4 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project Artemis by ls1intum.

the class UserResource method updateUserNotificationVisibility.

/**
 * Updates the HideNotificationsUntil property that indicates which notifications to show (based on their creation date)
 *
 * @param showAllNotifications is true if all notifications should be displayed in the sidebar else depending on the HideNotificationsUntil property
 * @return void
 */
@PutMapping("users/notification-visibility")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Void> updateUserNotificationVisibility(@RequestBody boolean showAllNotifications) {
    log.debug("REST request to update notification visibility for logged-in user");
    User user = userRepository.getUser();
    // if all notifications (regardless of their creation date) should be shown hideUntil should be null
    ZonedDateTime hideUntil = showAllNotifications ? null : ZonedDateTime.now();
    userService.updateUserNotificationVisibility(user.getId(), hideUntil);
    return ResponseEntity.ok().build();
}
Also used : User(de.tum.in.www1.artemis.domain.User) ZonedDateTime(java.time.ZonedDateTime) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with Visibility

use of de.tum.in.www1.artemis.domain.enumeration.Visibility in project Artemis by ls1intum.

the class UserTestService method updateUserNotificationVisibilityHideUntilAsStudentIsSuccessful.

// Test
public void updateUserNotificationVisibilityHideUntilAsStudentIsSuccessful() throws Exception {
    request.put("/api/users/notification-visibility", false, HttpStatus.OK);
    User userInDB = userRepository.findOneByLogin("student1").get();
    assertThat(userInDB.getHideNotificationsUntil()).isNotNull();
    assertThat(userInDB.getHideNotificationsUntil()).isStrictlyBetween(ZonedDateTime.now().minusSeconds(1), ZonedDateTime.now().plusSeconds(1));
}
Also used : User(de.tum.in.www1.artemis.domain.User)

Aggregations

User (de.tum.in.www1.artemis.domain.User)6 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)4 Participation (de.tum.in.www1.artemis.domain.participation.Participation)4 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)4 SolutionProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.SolutionProgrammingExerciseParticipation)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)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 ProgrammingExerciseTestCase (de.tum.in.www1.artemis.domain.ProgrammingExerciseTestCase)2 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)2 ProgrammingLanguage (de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)2 Visibility (de.tum.in.www1.artemis.domain.enumeration.Visibility)2 ProgrammingExerciseTestCaseType (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTestCaseType)2 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)2 ProgrammingExerciseTestCaseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseTestCaseRepository)2 ProgrammingExerciseTaskService (de.tum.in.www1.artemis.service.hestia.ProgrammingExerciseTaskService)2