use of org.finos.waltz.model.logical_flow.LogicalFlow 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.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findByProducerEntityReference.
@Test
public void findByProducerEntityReference() {
assertThrows(IllegalArgumentException.class, () -> pfSvc.findByProducerEntityReference(null), "Null entity reference throws an IllegalArgumentException");
List<PhysicalFlow> entityNotExists = pfSvc.findByProducerEntityReference(mkRef(EntityKind.APPLICATION, -1));
assertEquals(emptyList(), entityNotExists, "Returns empty list when entity doesn't exist");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
LogicalFlow ac = lfHelper.createLogicalFlow(a, c);
LogicalFlow ca = lfHelper.createLogicalFlow(c, a);
Long specId = psHelper.createPhysicalSpec(a, "findByExternalId");
PhysicalFlowCreateCommandResponse physicalFlowResponse1 = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findByProducerEntityReference"));
PhysicalFlowCreateCommandResponse physicalFlowResponse2 = pfHelper.createPhysicalFlow(ac.entityReference().id(), specId, mkName("findByProducerEntityReference"));
PhysicalFlowCreateCommandResponse physicalFlowResponse3 = pfHelper.createPhysicalFlow(ca.entityReference().id(), specId, mkName("findByProducerEntityReference"));
List<PhysicalFlow> physicalsDownstreamOfA = pfSvc.findByProducerEntityReference(a);
assertEquals(2, physicalsDownstreamOfA.size(), "Returns all flows downstream of a but not upstream flows");
assertEquals(asSet(physicalFlowResponse1.entityReference().id(), physicalFlowResponse2.entityReference().id()), map(physicalsDownstreamOfA, d -> d.entityReference().id()), "Returns expected flows downstream of a");
List<PhysicalFlow> physicalsDownstreamOfC = pfSvc.findByProducerEntityReference(c);
assertEquals(asSet(physicalFlowResponse3.entityReference().id()), map(physicalsDownstreamOfC, d -> d.entityReference().id()), "Returns expected flows downstream of c");
List<PhysicalFlow> physicalsDownstreamOfB = pfSvc.findByProducerEntityReference(b);
assertEquals(emptySet(), map(physicalsDownstreamOfB, d -> d.entityReference().id()), "Returns expected flows downstream of b");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method delete.
@Test
public void delete() {
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("delete"));
PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("delete"));
assertThrows(IllegalArgumentException.class, () -> pfSvc.delete(null, mkName("deletingFlow")), "Should throw exception if passed in a null phys flow id");
PhysicalFlowDeleteCommandResponse invalidFlowIdResp = pfSvc.delete(ImmutablePhysicalFlowDeleteCommand.builder().flowId(-1).build(), mkName("deletingFlow"));
assertEquals(CommandOutcome.FAILURE, invalidFlowIdResp.outcome(), "Should return failure if the flow does not exist");
PhysicalFlowDeleteCommandResponse deletedFlowResp = pfSvc.delete(ImmutablePhysicalFlowDeleteCommand.builder().flowId(physFlow.entityReference().id()).build(), mkName("deletingFlow"));
PhysicalFlow physicalFlowAfterDeletion = pfSvc.getById(physFlow.entityReference().id());
assertEquals(CommandOutcome.SUCCESS, deletedFlowResp.outcome(), "Should be successful if flow was deleted");
assertTrue(physicalFlowAfterDeletion.isRemoved(), "Physical flow should be soft deleted with isRemoved set true");
PhysicalFlowDeleteCommandResponse reDeletingFlowResp = pfSvc.delete(ImmutablePhysicalFlowDeleteCommand.builder().flowId(physFlow.entityReference().id()).build(), mkName("deletingFlow"));
assertEquals(CommandOutcome.FAILURE, reDeletingFlowResp.outcome(), "Should fail when trying to delete a flow that is already removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method updateAttribute.
@Test
public void updateAttribute() {
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("updateAttribute"));
PhysicalSpecification spec = psSvc.getById(specId);
ImmutableFlowAttributes flowAttributes = ImmutableFlowAttributes.builder().transport(TransportKindValue.UNKNOWN).description("before").basisOffset(1).criticality(Criticality.MEDIUM).frequency(FrequencyKind.DAILY).build();
ImmutablePhysicalFlowCreateCommand createCmd = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttributes).build();
PhysicalFlowCreateCommandResponse flowResp = pfSvc.create(createCmd, mkName("updateAttribute"));
assertThrows(UnsupportedOperationException.class, () -> pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("invalidAttr").entityReference(flowResp.entityReference()).value("invalid").build()), "If attribute name is not recognised throw exception");
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("description").entityReference(flowResp.entityReference()).value("after").build());
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("frequency").entityReference(flowResp.entityReference()).value("MONTHLY").build());
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("criticality").entityReference(flowResp.entityReference()).value("LOW").build());
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("entity_lifecycle_status").entityReference(flowResp.entityReference()).value("REMOVED").build());
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("basisOffset").entityReference(flowResp.entityReference()).value("0").build());
pfSvc.updateAttribute(mkName("updateAttribute"), ImmutableSetAttributeCommand.builder().name("transport").entityReference(flowResp.entityReference()).value("OTHER").build());
PhysicalFlow physFlowAfterUpdates = pfSvc.getById(flowResp.entityReference().id());
assertEquals("after", physFlowAfterUpdates.description(), "Description should be updated after updateAttribute");
assertEquals(FrequencyKind.MONTHLY, physFlowAfterUpdates.frequency(), "Frequency should be updated after updateAttribute");
assertEquals(TransportKindValue.of("OTHER"), physFlowAfterUpdates.transport(), "Transport should be updated after updateAttribute");
assertEquals(0, physFlowAfterUpdates.basisOffset(), "Basis offset should be updated after updateAttribute");
assertEquals(EntityLifecycleStatus.REMOVED, physFlowAfterUpdates.entityLifecycleStatus(), "EntityLifecycleStatus should be updated after updateAttribute");
assertEquals(Criticality.LOW, physFlowAfterUpdates.criticality(), "Criticality should be updated after updateAttribute");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findByEntityReference.
@Test
public void findByEntityReference() {
assertThrows(IllegalArgumentException.class, () -> pfSvc.findByEntityReference(null), "Null entity reference throws an IllegalArgumentException");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
LogicalFlow ac = lfHelper.createLogicalFlow(a, c);
Long specId = psHelper.createPhysicalSpec(a, "findByExternalId");
PhysicalFlowCreateCommandResponse physicalFlowResponse1 = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findByExternalId"));
PhysicalFlowCreateCommandResponse physicalFlowResponse2 = pfHelper.createPhysicalFlow(ac.entityReference().id(), specId, mkName("findByExternalId"));
List<PhysicalFlow> entityNotExists = pfSvc.findByEntityReference(mkRef(EntityKind.APPLICATION, -1));
assertEquals(emptyList(), entityNotExists, "Returns empty list when entity doesn't exist");
List<PhysicalFlow> entityExists = pfSvc.findByEntityReference(mkRef(EntityKind.APPLICATION, a.id()));
assertEquals(2, entityExists.size(), "Returns correct number of flows for entity");
assertEquals(asSet(physicalFlowResponse1.entityReference().id(), physicalFlowResponse2.entityReference().id()), map(entityExists, d -> d.entityReference().id()), "Returns correct flows for entity");
List<PhysicalFlow> correctFlowsForEntity = pfSvc.findByEntityReference(mkRef(EntityKind.APPLICATION, b.id()));
assertEquals(1, correctFlowsForEntity.size(), "Returns correct number of flows for entity");
assertEquals(asSet(physicalFlowResponse1.entityReference().id()), map(correctFlowsForEntity, d -> d.entityReference().id()), "Returns correct flows for entity");
}
Aggregations