Search in sources :

Example 86 with EntityReference

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

the class PhysicalSpecificationServiceTest method search.

@Test
public void search() {
    assertThrows(IllegalArgumentException.class, () -> psSvc.search(null), "Search options cannot be null");
    List<PhysicalSpecification> emptyQry = psSvc.search(mkForEntity(EntityKind.PHYSICAL_SPECIFICATION, ""));
    assertEquals(emptyList(), emptyQry, "Entity qry should return empty results");
    List<PhysicalSpecification> noResults = psSvc.search(mkForEntity(EntityKind.PHYSICAL_SPECIFICATION, "search"));
    assertEquals(emptyList(), noResults, "Entity qry should return empty results");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    Long specId = psHelper.createPhysicalSpec(a, "search");
    List<PhysicalSpecification> result = psSvc.search(mkForEntity(EntityKind.PHYSICAL_SPECIFICATION, "search"));
    assertEquals(asSet(specId), map(result, r -> r.entityReference().id()), "Entity qry should return results which match");
    Long specId2 = psHelper.createPhysicalSpec(a, "search");
    List<PhysicalSpecification> multipleSpecs = psSvc.search(mkForEntity(EntityKind.PHYSICAL_SPECIFICATION, "search"));
    assertEquals(asSet(specId, specId2), map(multipleSpecs, r -> r.entityReference().id()), "Entity qry should return results which match");
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 87 with EntityReference

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

the class SurveyInstanceResponseCopyTest method copyResponses.

@Test
public void copyResponses() {
    EntityReference a1 = appHelper.createNewApp(mkName("copyResponses"), ouIds.a);
    EntityReference a2 = appHelper.createNewApp(mkName("copyResponses"), ouIds.a);
    String username = mkName("copyResponses");
    Long personId = personHelper.createPerson(username);
    long templateId = templateHelper.createTemplate(username, mkName("copyResponses"));
    long qId = templateHelper.addQuestion(templateId);
    long invKindId = involvementHelper.mkInvolvementKind(mkName("invKind"));
    involvementHelper.createInvolvement(personId, invKindId, a1);
    involvementHelper.createInvolvement(personId, invKindId, a2);
    ImmutableSurveyRunCreateCommand runCmd = mkRunCommand(templateId, EntityReference.mkRef(EntityKind.ORG_UNIT, ouIds.a), invKindId);
    Long runId = runService.createSurveyRun(username, runCmd).id().get();
    InstancesAndRecipientsCreateCommand createCmd = mkInstancesRecipCreateCmd(runId);
    runService.createSurveyInstancesAndRecipients(createCmd);
    Set<SurveyInstance> instances = instanceService.findForSurveyRun(runId);
    SurveyInstance sourceSurvey = find(instances, d -> d.surveyEntity().id() == a1.id()).get();
    SurveyInstance targetSurvey = find(instances, d -> d.surveyEntity().id() == a2.id()).get();
    instanceService.saveResponse(username, sourceSurvey.id().get(), mkResponse(qId));
    ImmutableCopySurveyResponsesCommand copyCommand = ImmutableCopySurveyResponsesCommand.builder().targetSurveyInstanceIds(ListUtilities.asList(targetSurvey.id().get())).build();
    instanceService.copyResponses(sourceSurvey.id().get(), copyCommand, username);
    List<SurveyInstanceQuestionResponse> responses = instanceService.findResponses(targetSurvey.id().get());
    SurveyInstanceQuestionResponse q1StringResponse = find(responses, r -> r.questionResponse().questionId().equals(qId)).get();
    assertEquals("Can copy survey question responses to target instance", "yes", q1StringResponse.questionResponse().stringResponse().get());
    long q2Id = templateHelper.addQuestion(templateId);
    instanceService.saveResponse(username, sourceSurvey.id().get(), mkListResponse(q2Id));
    instanceService.copyResponses(sourceSurvey.id().get(), copyCommand, username);
    List<SurveyInstanceQuestionResponse> responsesWithListResponse = instanceService.findResponses(targetSurvey.id().get());
    SurveyInstanceQuestionResponse q2ListResponse = find(responsesWithListResponse, r -> r.questionResponse().questionId().equals(q2Id)).get();
    assertEquals("Can copy survey question list responses to target instance", asSet("yes", "no", "maybe"), fromCollection(q2ListResponse.questionResponse().listResponse().get()));
}
Also used : org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) SurveyRunService(org.finos.waltz.service.survey.SurveyRunService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) org.finos.waltz.model.survey(org.finos.waltz.model.survey) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities.nowUtcTimestamp(org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) ListUtilities(org.finos.waltz.common.ListUtilities) DateTimeUtilities.toLocalDate(org.finos.waltz.common.DateTimeUtilities.toLocalDate) CollectionUtilities.find(org.finos.waltz.common.CollectionUtilities.find) EntityReference(org.finos.waltz.model.EntityReference) SurveyInstanceService(org.finos.waltz.service.survey.SurveyInstanceService) Assert.assertEquals(org.junit.Assert.assertEquals) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 88 with EntityReference

use of org.finos.waltz.model.EntityReference 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 89 with EntityReference

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

the class BookmarkServiceTest method bookmarksCanReadById.

@Test
public void bookmarksCanReadById() {
    EntityReference bookmarkedEntity = mkAppRef();
    Bookmark bookmark1 = createBookmark(bookmarkedEntity, "test bookmark1");
    assertEquals(bookmark1, svc.getById(bookmark1.id().get()));
}
Also used : Bookmark(org.finos.waltz.model.bookmark.Bookmark) ImmutableBookmark(org.finos.waltz.model.bookmark.ImmutableBookmark) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 90 with EntityReference

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

the class BookmarkServiceTest method bookmarksCanDeletedById.

@Test
public void bookmarksCanDeletedById() {
    EntityReference bookmarkedEntity = mkAppRef();
    Bookmark bookmark = createBookmark(bookmarkedEntity, "test bookmark1");
    Long bookmarkId = bookmark.id().get();
    assertEquals(bookmark, svc.getById(bookmarkId));
    assertTrue(svc.deleteById(bookmark, mkUserId()));
    assertNull(svc.getById(bookmarkId));
}
Also used : Bookmark(org.finos.waltz.model.bookmark.Bookmark) ImmutableBookmark(org.finos.waltz.model.bookmark.ImmutableBookmark) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7