Search in sources :

Example 1 with SaveAssessmentRatingCommand

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());
}
Also used : ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) EntityKind(org.finos.waltz.model.EntityKind) AssessmentVisibility(org.finos.waltz.model.assessment_definition.AssessmentVisibility) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableRemoveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableRemoveAssessmentRatingCommand) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) ImmutableRatingSchemeItem(org.finos.waltz.model.rating.ImmutableRatingSchemeItem) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) ChangeLogHelper(org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper) Collection(java.util.Collection) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) NameHelper(org.finos.waltz.integration_test.inmem.helpers.NameHelper) RatingSchemeHelper(org.finos.waltz.integration_test.inmem.helpers.RatingSchemeHelper) AssessmentDefinitionService(org.finos.waltz.service.assessment_definition.AssessmentDefinitionService) Operation(org.finos.waltz.model.Operation) Test(org.junit.jupiter.api.Test) List(java.util.List) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) Optional(java.util.Optional) AssessmentDefinition(org.finos.waltz.model.assessment_definition.AssessmentDefinition) ImmutableAssessmentDefinition(org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition) ImmutableSaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand) SaveAssessmentRatingCommand(org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 CollectionUtilities.find (org.finos.waltz.common.CollectionUtilities.find)1 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)1 AppHelper (org.finos.waltz.integration_test.inmem.helpers.AppHelper)1 ChangeLogHelper (org.finos.waltz.integration_test.inmem.helpers.ChangeLogHelper)1 NameHelper (org.finos.waltz.integration_test.inmem.helpers.NameHelper)1 RatingSchemeHelper (org.finos.waltz.integration_test.inmem.helpers.RatingSchemeHelper)1 EntityKind (org.finos.waltz.model.EntityKind)1 EntityReference (org.finos.waltz.model.EntityReference)1 Operation (org.finos.waltz.model.Operation)1 AssessmentDefinition (org.finos.waltz.model.assessment_definition.AssessmentDefinition)1 AssessmentVisibility (org.finos.waltz.model.assessment_definition.AssessmentVisibility)1 ImmutableAssessmentDefinition (org.finos.waltz.model.assessment_definition.ImmutableAssessmentDefinition)1 AssessmentRating (org.finos.waltz.model.assessment_rating.AssessmentRating)1 ImmutableRemoveAssessmentRatingCommand (org.finos.waltz.model.assessment_rating.ImmutableRemoveAssessmentRatingCommand)1 ImmutableSaveAssessmentRatingCommand (org.finos.waltz.model.assessment_rating.ImmutableSaveAssessmentRatingCommand)1 SaveAssessmentRatingCommand (org.finos.waltz.model.assessment_rating.SaveAssessmentRatingCommand)1 ImmutableRatingSchemeItem (org.finos.waltz.model.rating.ImmutableRatingSchemeItem)1