Search in sources :

Example 1 with IdCommandResponse

use of org.finos.waltz.model.IdCommandResponse in project waltz by khartec.

the class SurveyRunServiceTest method surveysAreIssuedToRecipientsViaInvolvementKind.

@Test
public void surveysAreIssuedToRecipientsViaInvolvementKind() throws InsufficientPrivelegeException {
    String stem = "srt_surveysAreIssuedToRecipientsViaInvolvementKind";
    String admin = mkName(stem, "admin");
    personHelper.createPerson(admin);
    String u1 = mkName(stem, "user1");
    Long u1Id = personHelper.createPerson(u1);
    String u2a = mkName(stem, "user2a");
    Long u2aId = personHelper.createPerson(u2a);
    String u2b = mkName(stem, "user2b");
    Long u2bId = personHelper.createPerson(u2b);
    EntityReference appA = appHelper.createNewApp(mkName(stem, "appA"), ouIds.a);
    EntityReference appB = appHelper.createNewApp(mkName(stem, "appB"), ouIds.b);
    long invKind = involvementHelper.mkInvolvementKind(mkName(stem, "invKind"));
    involvementHelper.createInvolvement(u1Id, invKind, appA);
    involvementHelper.createInvolvement(u2aId, invKind, appB);
    involvementHelper.createInvolvement(u2bId, invKind, appB);
    Long grpId = groupHelper.createAppGroupWithAppRefs(mkName(stem, "group"), asSet(appA, appB));
    long tId = templateHelper.createTemplate(admin, mkName("test"));
    // remove person 2
    personHelper.updateIsRemoved(u2aId, true);
    SurveyRunCreateCommand cmd = ImmutableSurveyRunCreateCommand.builder().issuanceKind(SurveyIssuanceKind.GROUP).name("test").description("run desc").selectionOptions(IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.APP_GROUP, grpId))).surveyTemplateId(tId).addInvolvementKindIds(invKind).dueDate(DateTimeUtilities.today().plusMonths(1)).approvalDueDate(DateTimeUtilities.today().plusMonths(1)).contactEmail("someone@somewhere.com").build();
    IdCommandResponse runResp = runService.createSurveyRun(admin, cmd);
    Long surveyRunId = runResp.id().orElseThrow(() -> new AssertionFailedError("Failed to create run"));
    ImmutableInstancesAndRecipientsCreateCommand createCmd = ImmutableInstancesAndRecipientsCreateCommand.builder().surveyRunId(surveyRunId).dueDate(toLocalDate(nowUtcTimestamp())).approvalDueDate(toLocalDate(nowUtcTimestamp())).excludedRecipients(emptySet()).build();
    runService.createSurveyInstancesAndRecipients(createCmd);
    Set<SurveyInstance> instances = instanceService.findForSurveyRun(surveyRunId);
    assertEquals(2, instances.size(), "should be 2 instances");
    SurveyInstance instanceA = findInstanceForApp(instances, appA);
    SurveyInstance instanceB = findInstanceForApp(instances, appB);
    assertNotNull(instanceA);
    assertNotNull(instanceB);
    assertEquals(SurveyInstanceStatus.NOT_STARTED, instanceA.status(), "instance won't have been started yet");
    assertEquals(SurveyInstanceStatus.NOT_STARTED, instanceB.status(), "instance won't have been started yet");
    Long instanceAId = instanceA.id().orElseThrow(() -> new AssertionFailedError("Failed to find instance for app A"));
    Long instanceBId = instanceB.id().orElseThrow(() -> new AssertionFailedError("Failed to find instance for app B"));
    assertNotNull(instanceService.checkPersonIsRecipient(u1, instanceAId), "check user 1 via api");
    assertNotNull(instanceService.checkPersonIsOwnerOrAdmin(admin, instanceAId), "admin is owner of instance A");
    assertNotNull(instanceService.checkPersonIsOwnerOrAdmin(admin, instanceBId), "admin is owner of instance B");
    Set<SurveyInstance> instancesForU1 = instanceService.findForRecipient(u1Id);
    Set<SurveyInstance> instancesForU2a = instanceService.findForRecipient(u2aId);
    assertEquals(asSet(instanceA), instancesForU1, "instances for u1 should be just an instance for appA");
    assertEquals(Collections.emptySet(), instancesForU2a, "should be no instances for user 2A");
    assertEquals(instanceService.findForRecipient(u1Id), instanceService.findForRecipient(u1), "can find by name or id (1)");
    assertEquals(instanceService.findForRecipient(u2bId), instanceService.findForRecipient(u2b), "can find by name or id (2a)");
    assertThrows(IllegalArgumentException.class, () -> instanceService.findForRecipient(u2a), "finding by removed user throws an exception");
    List<Person> aRecips = instanceService.findRecipients(instanceAId);
    List<Person> bRecips = instanceService.findRecipients(instanceBId);
    assertEquals(asSet(u1), recipsToUserIds(aRecips), "Expect user1 to be the recipient");
    assertEquals(asSet(u2b), recipsToUserIds(bRecips), "app B has only one recipient (u2a) as the other involved person (u2a) has been removed");
}
Also used : IdCommandResponse(org.finos.waltz.model.IdCommandResponse) EntityReference(org.finos.waltz.model.EntityReference) AssertionFailedError(junit.framework.AssertionFailedError) Person(org.finos.waltz.model.person.Person) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with IdCommandResponse

use of org.finos.waltz.model.IdCommandResponse in project waltz by khartec.

the class AttestationServiceTest method basicRunCreation.

@Test
public void basicRunCreation() {
    long invId = involvementHelper.mkInvolvementKind(mkName("basicRunCreationInvolvement"));
    AttestationRunCreateCommand cmd = ImmutableAttestationRunCreateCommand.builder().dueDate(DateTimeUtilities.today().plusMonths(1)).targetEntityKind(EntityKind.APPLICATION).attestedEntityKind(EntityKind.LOGICAL_DATA_FLOW).selectionOptions(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.a))).addInvolvementKindIds(invId).name("basicRunCreation Name").description("basicRunCreation Desc").sendEmailNotifications(false).build();
    String user = mkUserId("ast");
    IdCommandResponse response = arSvc.create(user, cmd);
    assertTrue(response.id().isPresent());
    Long runId = response.id().get();
    AttestationRun run = arSvc.getById(runId);
    assertEquals("basicRunCreation Name", run.name());
    assertEquals("basicRunCreation Desc", run.description());
    assertEquals(asSet(invId), run.involvementKindIds());
    assertEquals(AttestationStatus.ISSUED, run.status());
    assertEquals(EntityKind.LOGICAL_DATA_FLOW, run.attestedEntityKind());
    assertEquals(user, run.issuedBy());
    assertEquals(EntityKind.APPLICATION, run.targetEntityKind());
}
Also used : IdCommandResponse(org.finos.waltz.model.IdCommandResponse) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with IdCommandResponse

use of org.finos.waltz.model.IdCommandResponse in project waltz by khartec.

the class AttestationServiceTest method runCreationPreview.

@Test
public void runCreationPreview() {
    EntityReference app = appHelper.createNewApp("a", ouIds.a);
    String involvementKindName = mkName("runCreationPreview");
    String involvedUser = mkName("runCreationPreviewUser");
    long invId = involvementHelper.mkInvolvementKind(involvementKindName);
    Long pId = personHelper.createPerson(involvedUser);
    involvementHelper.createInvolvement(pId, invId, app);
    AttestationRunCreateCommand cmd = ImmutableAttestationRunCreateCommand.builder().dueDate(DateTimeUtilities.today().plusMonths(1)).targetEntityKind(EntityKind.APPLICATION).attestedEntityKind(EntityKind.LOGICAL_DATA_FLOW).selectionOptions(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.a))).addInvolvementKindIds(invId).name("runCreationPreview Name").description("runCreationPreview Desc").sendEmailNotifications(false).build();
    AttestationCreateSummary summary = arSvc.getCreateSummary(cmd);
    assertEquals(1, summary.entityCount());
    assertEquals(1, summary.instanceCount());
    assertEquals(1, summary.recipientCount());
    String runCreationUser = mkUserId("runCreationUser");
    IdCommandResponse resp = arSvc.create(runCreationUser, cmd);
    resp.id().ifPresent(runId -> {
        List<AttestationInstance> instances = aiSvc.findByRunId(runId);
        assertEquals(1, instances.size(), "expected only one instance");
        AttestationInstance instance = first(instances);
        assertEquals(app, instance.parentEntity());
        assertEquals(EntityKind.LOGICAL_DATA_FLOW, instance.attestedEntityKind());
        assertTrue(OptionalUtilities.isEmpty(instance.attestedAt()), "Should not have been attested");
        assertTrue(OptionalUtilities.isEmpty(instance.attestedBy()), "Should not have been attested");
        assertEquals(runId, instance.attestationRunId());
        assertTrue(instance.id().isPresent());
        String attestor = mkUserId("attestor");
        boolean attestationResult = aiSvc.attestInstance(instance.id().get(), attestor);
        assertTrue(attestationResult);
        AttestationInstance attestedInstance = first(aiSvc.findByRunId(runId));
        assertEquals(Optional.of(attestor), attestedInstance.attestedBy());
        assertTrue(attestedInstance.attestedAt().isPresent());
        List<AttestationInstance> instancesForApp = aiSvc.findByEntityReference(app);
        assertEquals(1, instancesForApp.size());
        AttestationInstance instanceForApp = first(instancesForApp);
        assertEquals(instanceForApp, attestedInstance);
        List<AttestationRun> runsForApp = arSvc.findByEntityReference(app);
        assertEquals(1, runsForApp.size(), "Can find runs via entity refs, e.g. for apps");
        AttestationRun runForApp = first(runsForApp);
        assertEquals(Optional.of(runId), runForApp.id());
        assertEquals(runCreationUser, runForApp.issuedBy());
        assertEquals(AttestationStatus.ISSUED, runForApp.status());
        List<AttestationRun> runForUser = arSvc.findByRecipient(involvedUser);
        assertEquals(runsForApp, runForUser);
    });
}
Also used : IdCommandResponse(org.finos.waltz.model.IdCommandResponse) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with IdCommandResponse

use of org.finos.waltz.model.IdCommandResponse in project waltz by khartec.

the class AttestationServiceTest method basicRetrieval.

@Test
@Disabled
public void basicRetrieval() {
    long invId = involvementHelper.mkInvolvementKind(mkName("basicRetrieval"));
    EntityReference appRef = appHelper.createNewApp(mkName("basicRetrieval"), ouIds.a);
    AttestationRunCreateCommand cmd = ImmutableAttestationRunCreateCommand.builder().dueDate(DateTimeUtilities.today().plusMonths(1)).targetEntityKind(EntityKind.APPLICATION).attestedEntityKind(EntityKind.LOGICAL_DATA_FLOW).selectionOptions(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.a))).addInvolvementKindIds(invId).name(mkName("basicRetrieval")).description("basicRetrieval Desc").sendEmailNotifications(false).build();
    String user = mkUserId("ast");
    long pId = personHelper.createPerson(mkName("basicRetrieval"));
    involvementHelper.createInvolvement(pId, invId, appRef);
    IdCommandResponse response = arSvc.create(user, cmd);
    arSvc.issueInstancesForPendingRuns();
    System.out.println("-------------");
    dsl.selectFrom(ATTESTATION_INSTANCE).fetch().forEach(System.out::println);
    System.out.println("-------------");
    List<AttestationInstance> instances = aiSvc.findByIdSelector(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.a)));
    assertFalse(isEmpty(instances));
}
Also used : IdCommandResponse(org.finos.waltz.model.IdCommandResponse) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)4 IdCommandResponse (org.finos.waltz.model.IdCommandResponse)4 Test (org.junit.jupiter.api.Test)4 EntityReference (org.finos.waltz.model.EntityReference)3 AssertionFailedError (junit.framework.AssertionFailedError)1 Person (org.finos.waltz.model.person.Person)1 Disabled (org.junit.jupiter.api.Disabled)1