use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class LogicalFlowServiceTest method findUpstreamFlowsForEntityReferences.
@Test
public void findUpstreamFlowsForEntityReferences() {
helper.clearAllFlows();
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
EntityReference d = appHelper.createNewApp("d", ouIds.b);
helper.createLogicalFlow(a, b);
helper.createLogicalFlow(c, b);
helper.createLogicalFlow(b, c);
helper.createLogicalFlow(b, d);
Collection<LogicalFlow> upstreamFlowsForEmptyList = lfSvc.findUpstreamFlowsForEntityReferences(emptyList());
assertTrue(isEmpty(upstreamFlowsForEmptyList), "No upstreams when no ref provided");
Collection<LogicalFlow> upstreamsWhereOnlySource = lfSvc.findUpstreamFlowsForEntityReferences(asList(a));
assertEquals(0, upstreamsWhereOnlySource.size(), "No upstreams when all refs are only targets");
Collection<LogicalFlow> allUpstreams = lfSvc.findUpstreamFlowsForEntityReferences(asList(b, c));
assertEquals(3, allUpstreams.size(), "Returns all upstreams but not downstreams");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method create.
@Test
public void create() {
String username = mkName("create");
assertThrows(IllegalArgumentException.class, () -> psSvc.create(null), "Should throw exception if create command is null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
String name = mkName("create");
ImmutablePhysicalSpecification createCommand = ImmutablePhysicalSpecification.builder().externalId(name).owningEntity(a).name(name).description("desc").format(DataFormatKind.UNKNOWN).lastUpdatedBy(username).isRemoved(false).created(UserTimestamp.mkForUser(username, DateTimeUtilities.nowUtcTimestamp())).build();
Long specId = psSvc.create(createCommand);
PhysicalSpecification spec = psSvc.getById(specId);
assertEquals(specId, spec.id().get(), "Spec id should be created");
assertEquals(name, spec.name(), "Spec id should be have the same externalId");
assertThrows(IllegalArgumentException.class, () -> psSvc.create(ImmutablePhysicalSpecification.copyOf(spec)), "Cannot create a specification with an id that exists");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class PhysicalSpecificationServiceTest method markRemovedIfUnused.
@Test
public void markRemovedIfUnused() {
String username = mkName("markRemovedIfUnused");
assertThrows(IllegalArgumentException.class, () -> psSvc.markRemovedIfUnused(null, username), "Throws exception if entity reference is null");
ImmutablePhysicalSpecificationDeleteCommand noSpecCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(-1L).build();
CommandResponse<PhysicalSpecificationDeleteCommand> responseNoSpec = psSvc.markRemovedIfUnused(noSpecCmd, username);
assertEquals(CommandOutcome.FAILURE, responseNoSpec.outcome(), "Fails to mark removed if spec not found");
assertEquals("Specification not found", responseNoSpec.message().get(), "Should inform of reason for failure");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
PhysicalFlowCreateCommandResponse physicalFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("markRemovedIfUnused"));
ImmutablePhysicalSpecificationDeleteCommand deleteCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(specId).build();
CommandResponse<PhysicalSpecificationDeleteCommand> responseWithUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
assertEquals(CommandOutcome.FAILURE, responseWithUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
assertEquals("This specification cannot be deleted as it is being referenced by one or more physical flows", responseWithUnderlyingFlows.message().get(), "Should inform of reason for failure");
pfHelper.deletePhysicalFlow(physicalFlow.entityReference().id());
CommandResponse<PhysicalSpecificationDeleteCommand> responseWithNoUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
assertEquals(CommandOutcome.SUCCESS, responseWithNoUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class BookmarkServiceTest method bookmarkCanBeCreated.
@Test
public void bookmarkCanBeCreated() {
EntityReference bookmarkedEntity = mkAppRef();
Bookmark bookmark = createBookmark(bookmarkedEntity, "test bookmark");
List<Bookmark> bookmarks = svc.findByReference(bookmarkedEntity);
assertEquals(1, bookmarks.size());
assertEquals(bookmark, first(bookmarks));
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class DataTypeDecoratorServiceTest method findByEntityIdSelector.
@Test
public void findByEntityIdSelector() {
String username = mkName("findByEntityIdSelector");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
IdSelectionOptions appOpts = mkOpts(a);
assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityIdSelector(EntityKind.APPLICATION, appOpts), "If not logical flow kind or physical spec kind should throw exception");
List<DataTypeDecorator> selectorForLfWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
assertEquals(emptyList(), selectorForLfWhereNoDecorators, "If no flows and decorators for selector returns empty list");
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long dtId = dataTypeHelper.createDataType("findByEntityIdSelector");
Long dtId2 = dataTypeHelper.createDataType("findByEntityIdSelector2");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
List<DataTypeDecorator> selectorWithDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
assertEquals(asSet(dtId, dtId2), map(selectorWithDecorators, DataTypeDecorator::dataTypeId), "Returns all data types for flow selector");
IdSelectionOptions flowOpts = mkOpts(flow.entityReference());
List<DataTypeDecorator> selectorForPsWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
assertEquals(emptyList(), selectorForPsWhereNoDecorators, "If no flows and decorators for selector returns empty list");
Long psId = psHelper.createPhysicalSpec(a, "findByEntityIdSelector");
EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
pfHelper.createPhysicalFlow(flow.entityReference().id(), psId, "findByEntityIdSelector");
dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2), emptySet());
List<DataTypeDecorator> selectorForPs = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
assertEquals(asSet(dtId, dtId2), map(selectorForPs, DataTypeDecorator::dataTypeId), "Returns all data types for spec selector");
}
Aggregations