use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method merge_canCreateAdditionalExtIdsInTheExternalIdentifierTableIfNeeded.
@Test
public void merge_canCreateAdditionalExtIdsInTheExternalIdentifierTableIfNeeded() {
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("merge"));
Long specId2 = psHelper.createPhysicalSpec(a, mkName("merge2"));
PhysicalFlowCreateCommandResponse firstFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("merge"));
PhysicalFlowCreateCommandResponse secondFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId2, mkName("merge"));
pfHelper.updateExternalIdOnFlowDirectly(firstFlowCreateResp.entityReference().id(), "merge");
pfHelper.updateExternalIdOnFlowDirectly(secondFlowCreateResp.entityReference().id(), "merge2");
boolean merge = pfSvc.merge(firstFlowCreateResp.entityReference().id(), secondFlowCreateResp.entityReference().id(), mkName("merge"));
List<PhysicalFlow> flowsWithMergeExtId = pfSvc.findByExternalId("merge");
PhysicalFlow firstFlowAfterUpdate = pfSvc.getById(firstFlowCreateResp.entityReference().id());
PhysicalFlow secondFlowAfterUpdate = pfSvc.getById(secondFlowCreateResp.entityReference().id());
assertTrue(secondFlowAfterUpdate.externalId().map(extId -> extId.equalsIgnoreCase("merge2")).orElse(false), "If the target flow already had an ext Id this is retained");
assertTrue(map(flowsWithMergeExtId, d -> d.entityReference().id()).contains(secondFlowCreateResp.entityReference().id()), "Once merged the second flow should have the external id of the original");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method create_shouldRestoreLogicalFlowIfRemoved.
@Test
public void create_shouldRestoreLogicalFlowIfRemoved() {
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();
lfSvc.removeFlow(ab.entityReference().id(), mkName("create"));
PhysicalFlowCreateCommandResponse createRespWithRemovedFlow = pfSvc.create(createCommand, mkName("create"));
assertEquals(CommandOutcome.SUCCESS, createRespWithRemovedFlow.outcome(), "Should restore removed logical flows and create physical");
LogicalFlow abAfterFlowAdded = lfSvc.getById(ab.entityReference().id());
assertFalse(abAfterFlowAdded.isRemoved(), "Logical flows should be active if physicals have been added");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalSpecificationServiceTest method findByEntityReference.
@Test
public void findByEntityReference() {
assertThrows(IllegalArgumentException.class, () -> psSvc.findByEntityReference(null), "Throws exception if entity reference is null");
Set<PhysicalSpecification> whereEntityUnrelated = psSvc.findByEntityReference(mkRef(EntityKind.COST_KIND, -1));
assertEquals(emptySet(), whereEntityUnrelated, "Returns an empty set where entity is not related");
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");
Set<PhysicalSpecification> returnsAsSetEvenIfMultipleLinksToSpec = psSvc.findByEntityReference(a);
assertEquals(asSet(a.id()), map(returnsAsSetEvenIfMultipleLinksToSpec, d -> d.owningEntity().id()), "Should return if no flows but is owning entity");
Set<PhysicalSpecification> noFlows = psSvc.findByEntityReference(b);
assertEquals(emptySet(), noFlows, "Should return empty set for an application if not owner or linked by flow");
PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findByEntityReference"));
Set<PhysicalSpecification> linkedByPhysFlow = psSvc.findByEntityReference(b);
assertEquals(asSet(specId), map(linkedByPhysFlow, d -> d.entityReference().id()), "Should return specs for an application if linked to a flow");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class DataTypeDecoratorServiceTest method findSuggestedByEntityRef.
@Test
public void findSuggestedByEntityRef() {
String username = mkName("updateDecorators");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
assertThrows(UnsupportedOperationException.class, () -> dtdSvc.findSuggestedByEntityRef(a), "Throw exception if not a logical data flow or physical spec");
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Collection<DataType> suggestedWhenNoFlows = dtdSvc.findSuggestedByEntityRef(flow.entityReference());
assertEquals(emptyList(), suggestedWhenNoFlows, "If no flows associated to entity should return empty list");
EntityReference c = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow2 = lfHelper.createLogicalFlow(b, c);
Long dtId = dataTypeHelper.createDataType("updateDecorators");
Long dtId2 = dataTypeHelper.createDataType("updateDecorators2");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());
dtdSvc.updateDecorators(username, flow2.entityReference(), asSet(dtId, dtId2), emptySet());
Collection<DataType> suggestedWhenUpstream = dtdSvc.findSuggestedByEntityRef(flow.entityReference());
assertEquals(asSet(dtId), map(suggestedWhenUpstream, d -> d.id().get()), "Should return suggested data types based on the upstream app");
Collection<DataType> suggestedWhenSrcHasUpstreamAndDownStream = dtdSvc.findSuggestedByEntityRef(flow2.entityReference());
assertEquals(asSet(dtId, dtId2), map(suggestedWhenSrcHasUpstreamAndDownStream, d -> d.id().get()), "Should return suggested data types based on up and down stream flows on the upstream app");
Long specId = psHelper.createPhysicalSpec(a, "updateDecorators");
pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, "updateDecorators");
Collection<DataType> suggestedForPsWhenUpstream = dtdSvc.findSuggestedByEntityRef(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId));
assertEquals(asSet(dtId), map(suggestedForPsWhenUpstream, d -> d.id().get()), "Should return suggested data types based on the upstream app");
Long specId2 = psHelper.createPhysicalSpec(a, "updateDecorators");
Collection<DataType> specNotInvolvedInFlows = dtdSvc.findSuggestedByEntityRef(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId2));
assertEquals(emptyList(), specNotInvolvedInFlows, "Spec not involved in flows should return empty list");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class DataTypeDecoratorServiceTest method findByFlowIds.
@Test
public void findByFlowIds() {
Collection<DataTypeDecorator> lfDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.LOGICAL_DATA_FLOW);
Collection<DataTypeDecorator> psDecs = dtdSvc.findByFlowIds(emptyList(), EntityKind.PHYSICAL_SPECIFICATION);
assertEquals(emptyList(), lfDecs, "If empty id list provided returns empty list");
assertEquals(emptyList(), psDecs, "If empty id list provided returns empty list");
Collection<DataTypeDecorator> invalidId = dtdSvc.findByFlowIds(asList(-1L), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), invalidId, "If flow id doesn't exist returns empty list");
assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByFlowIds(asList(-1L), EntityKind.APPLICATION), "If unsupported kind id throws exception");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Collection<DataTypeDecorator> withNoDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(emptyList(), withNoDecorators, "flow has no decorators");
Long dtId = dataTypeHelper.createDataType("findByFlowIds");
String username = mkName("findByFlowIds");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());
Collection<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(1, flowDecorators.size(), "Flow with one datatype associated returns a set with one decorator");
assertEquals(dtId, Long.valueOf(first(flowDecorators).dataTypeId()), "Returns the correct datatype id on the decorator");
Long dtId2 = dataTypeHelper.createDataType("findByFlowIds2");
Long dtId3 = dataTypeHelper.createDataType("findByFlowIds3");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId2, dtId3), emptySet());
Collection<DataTypeDecorator> multipleDecorators = dtdSvc.findByFlowIds(asList(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
assertEquals(3, multipleDecorators.size());
assertEquals(asSet(dtId, dtId2, dtId3), map(multipleDecorators, DataTypeDecorator::dataTypeId), "Returns all decorators for the flow");
assertThrows(UnsupportedOperationException.class, () -> dtdSvc.findByFlowIds(asSet(dtId), EntityKind.PHYSICAL_SPECIFICATION), "Find by flow ids is only supported for logical flows");
}
Aggregations