use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method updateSpecDefinitionId.
@Test
public void updateSpecDefinitionId() {
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("updateSpecDefinitionId"));
long specDefnId = psdSvc.create(mkName("updateSpecDefinitionId"), specId, ImmutablePhysicalSpecDefinitionChangeCommand.builder().version("updateSpecDefinitionId").type(PhysicalSpecDefinitionType.DELIMITED).status(ReleaseLifecycleStatus.ACTIVE).delimiter(";").build());
PhysicalFlowCreateCommandResponse flowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("updateSpecDefinitionId"));
PhysicalFlow physicalFlow = pfSvc.getById(flowCreateResp.entityReference().id());
assertEquals(Optional.empty(), physicalFlow.specificationDefinitionId(), "Check the physical flow has been created without correct spec id");
assertThrows(IllegalArgumentException.class, () -> pfSvc.updateSpecDefinitionId(mkName("updateSpecDefinitionId"), physicalFlow.id().get(), null), "Should throw an IllegalArgumentException if the update command is null");
int updated = pfSvc.updateSpecDefinitionId(mkName("updateSpecDefinitionId"), physicalFlow.id().get(), ImmutablePhysicalFlowSpecDefinitionChangeCommand.builder().newSpecDefinitionId(specDefnId).build());
assertEquals(1, updated, "Should successfully update the specification id to the new spec");
PhysicalFlow flowWithNewSpec = pfSvc.getById(flowCreateResp.entityReference().id());
assertEquals(Long.valueOf(specDefnId), flowWithNewSpec.specificationDefinitionId().get(), "Should successfully update the specification id to the new spec");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method create_allowsSimilarFlowToBeCreatedIfOriginalWasRemoved.
@Test
public void create_allowsSimilarFlowToBeCreatedIfOriginalWasRemoved() {
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"));
PhysicalSpecification spec = psSvc.getById(specId);
assertThrows(IllegalArgumentException.class, () -> pfSvc.create(null, mkName("create")), "Should throw exception if null object passed into create");
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse firstCreateResp = pfSvc.create(createCommand, mkName("createAllowsSimilarToBeCreatedInFuture"));
PhysicalFlowDeleteCommandResponse deleteResp = pfHelper.deletePhysicalFlow(firstCreateResp.entityReference().id());
PhysicalFlowCreateCommandResponse secondCreateResp = pfSvc.create(createCommand, mkName("createAllowsSimilarToBeCreatedInFuture"));
PhysicalFlow pf1 = pfSvc.getById(firstCreateResp.entityReference().id());
PhysicalFlow pf2 = pfSvc.getById(secondCreateResp.entityReference().id());
assertTrue(pf1.isRemoved(), "First flows should remain removed");
assertFalse(pf2.isRemoved(), "Second flow should be active");
assertEquals(CommandOutcome.SUCCESS, secondCreateResp.outcome(), "Can successfully create physical flows sharing attributes if the first physical similar was removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findUnderlyingPhysicalFlows.
@Test
public void findUnderlyingPhysicalFlows() {
Collection<PhysicalFlowInfo> underlyingPhysicalFlowsWhenLogicalNull = pfSvc.findUnderlyingPhysicalFlows(null);
assertTrue(isEmpty(underlyingPhysicalFlowsWhenLogicalNull), "If null logical flow id then returns empty list");
Collection<PhysicalFlowInfo> underlyingPhysicalFlowsWhenLogicalDoesntExist = pfSvc.findUnderlyingPhysicalFlows(-1L);
assertTrue(isEmpty(underlyingPhysicalFlowsWhenLogicalDoesntExist), "If invalid logical flow id then returns empty list");
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Collection<PhysicalFlowInfo> noPhysicalsAssociated = pfSvc.findUnderlyingPhysicalFlows(ab.entityReference().id());
assertTrue(isEmpty(noPhysicalsAssociated), "If no physicals associated to the logical then returns empty list");
Long specId = psHelper.createPhysicalSpec(a, mkName("updateAttribute"));
PhysicalFlowCreateCommandResponse flowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findUnderlyingPhysicalFlows"));
Collection<PhysicalFlowInfo> physicalAssociated = pfSvc.findUnderlyingPhysicalFlows(ab.entityReference().id());
assertEquals(1, physicalAssociated.size(), "Returns correct number of underlying physical flows for that logical");
pfHelper.deletePhysicalFlow(flowCreateResp.entityReference().id());
Collection<PhysicalFlowInfo> noActivePhysicals = pfSvc.findUnderlyingPhysicalFlows(ab.entityReference().id());
assertTrue(isEmpty(noActivePhysicals), "If no active physicals associated to the logical then returns empty list");
PhysicalFlowCreateCommandResponse flowCreateResp2 = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findUnderlyingPhysicalFlows"));
Collection<PhysicalFlowInfo> physicalAssociated2 = pfSvc.findUnderlyingPhysicalFlows(ab.entityReference().id());
assertEquals(1, physicalAssociated2.size(), "Returns correct number of underlying physical flows for that logical");
lfSvc.removeFlow(ab.entityReference().id(), mkName("findUnderlyingPhysicalFlows"));
Collection<PhysicalFlowInfo> underlyingPhysicalsForRemovedLogical = pfSvc.findUnderlyingPhysicalFlows(ab.entityReference().id());
assertTrue(isEmpty(underlyingPhysicalsForRemovedLogical), "Returns empty list of the logical flow is removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findByConsumerEntityReference.
@Test
public void findByConsumerEntityReference() {
assertThrows(IllegalArgumentException.class, () -> pfSvc.findByConsumerEntityReference(null), "Null entity reference throws an IllegalArgumentException");
List<PhysicalFlow> entityNotExists = pfSvc.findByConsumerEntityReference(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 bc = lfHelper.createLogicalFlow(b, c);
Long specId = psHelper.createPhysicalSpec(a, "findByExternalId");
PhysicalFlowCreateCommandResponse physicalFlowResponse1 = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findByConsumerEntityReference"));
PhysicalFlowCreateCommandResponse physicalFlowResponse2 = pfHelper.createPhysicalFlow(ac.entityReference().id(), specId, mkName("findByConsumerEntityReference"));
PhysicalFlowCreateCommandResponse physicalFlowResponse3 = pfHelper.createPhysicalFlow(bc.entityReference().id(), specId, mkName("findByConsumerEntityReference"));
List<PhysicalFlow> physicalsUpstreamOfA = pfSvc.findByConsumerEntityReference(a);
assertEquals(emptySet(), map(physicalsUpstreamOfA, d -> d.entityReference().id()), "Returns expected flows upstream of a");
List<PhysicalFlow> physicalsUpstreamOfC = pfSvc.findByConsumerEntityReference(c);
assertEquals(2, physicalsUpstreamOfC.size(), "Returns all flows upstream of a but not downstream flows");
assertEquals(asSet(physicalFlowResponse2.entityReference().id(), physicalFlowResponse3.entityReference().id()), map(physicalsUpstreamOfC, d -> d.entityReference().id()), "Returns expected flows upstream of c");
List<PhysicalFlow> physicalsDownstreamOfB = pfSvc.findByConsumerEntityReference(b);
assertEquals(asSet(physicalFlowResponse1.entityReference().id()), map(physicalsDownstreamOfB, d -> d.entityReference().id()), "Returns expected flows upstream of b");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method create.
@Test
public void create() {
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"));
PhysicalSpecification spec = psSvc.getById(specId);
assertThrows(IllegalArgumentException.class, () -> pfSvc.create(null, mkName("create")), "Should throw exception if null object passed into create");
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
ImmutablePhysicalFlowCreateCommand createCommandInvalidFlowId = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(-1).specification(spec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse createResp = pfSvc.create(createCommand, mkName("create"));
assertEquals(CommandOutcome.SUCCESS, createResp.outcome(), "Can successfully create physical flows");
assertThrows(IllegalArgumentException.class, () -> pfSvc.create(createCommandInvalidFlowId, mkName("create")), "Throws an exception when trying to create a physical flow for an invalid logical flow id");
}
Aggregations