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");
}
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()));
}
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");
}
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()));
}
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));
}
Aggregations