use of org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand in project waltz by khartec.
the class AssessmentsTest method createUpdateAndRemoveSingleRating.
@Test
public void createUpdateAndRemoveSingleRating() {
String user = NameHelper.mkUserId("user");
String name = NameHelper.mkName("testAssessment");
String role = NameHelper.mkName("testRole");
SchemeDetail schemeDetail = createScheme();
AssessmentDefinition def = ImmutableAssessmentDefinition.builder().name(name).description("desc").isReadOnly(false).permittedRole(role).entityKind(EntityKind.APPLICATION).lastUpdatedBy(user).visibility(AssessmentVisibility.SECONDARY).ratingSchemeId(schemeDetail.id).build();
long defId = definitionService.save(def);
definitionService.save(ImmutableAssessmentDefinition.copyOf(def).withId(defId).withDescription("updated desc"));
Collection<AssessmentDefinition> allDefs = definitionService.findAll();
AssessmentDefinition found = find(d -> d.id().equals(Optional.of(defId)), allDefs).orElseThrow(AssertionError::new);
assertEquals("updated desc", found.description());
assertEquals(found, definitionService.getById(defId));
EntityReference app1 = appHelper.createNewApp(NameHelper.mkName("app1"), ouIds.a);
EntityReference app2 = appHelper.createNewApp(NameHelper.mkName("app2"), ouIds.b);
SaveAssessmentRatingCommand cmd = ImmutableSaveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).ratingId(schemeDetail.y).lastUpdatedBy(user).build();
ratingService.store(cmd, user);
changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.ADD);
assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.y, ratingService.findForEntity(app1)));
assertTrue(ratingService.findForEntity(app2).isEmpty());
ratingService.store(ImmutableSaveAssessmentRatingCommand.copyOf(cmd).withRatingId(schemeDetail.n), user);
changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.UPDATE);
assertNotNull(find(r -> r.assessmentDefinitionId() == defId && r.ratingId() == schemeDetail.n, ratingService.findForEntity(app1)));
List<AssessmentRating> allRatingsAfterUpdate = ratingService.findByDefinitionId(defId);
assertEquals(1, allRatingsAfterUpdate.size());
assertTrue(find(r -> r.entityReference().equals(app1) && r.ratingId() == schemeDetail.n, allRatingsAfterUpdate).isPresent());
ratingService.remove(ImmutableRemoveAssessmentRatingCommand.builder().assessmentDefinitionId(defId).entityReference(app1).lastUpdatedBy(user).build(), user);
changeLogHelper.assertChangeLogContainsAtLeastOneMatchingOperation(app1, Operation.REMOVE);
assertTrue(ratingService.findForEntity(app1).isEmpty());
List<AssessmentRating> allRatingsAfterRemoval = ratingService.findByDefinitionId(defId);
assertTrue(allRatingsAfterRemoval.isEmpty());
}
Aggregations