use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class DataTypeDecoratorServiceTest method findDatatypeUsageCharacteristics.
@Test
public void findDatatypeUsageCharacteristics() {
String username = mkName("findDatatypeUsageCharacteristics");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
assertThrows(IllegalArgumentException.class, () -> dtdSvc.findDatatypeUsageCharacteristics(a), "Throw exception for entities other than physical specs and logical flows");
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Collection<DataTypeUsageCharacteristics> noDecorators = dtdSvc.findDatatypeUsageCharacteristics(flow.entityReference());
assertEquals(emptyList(), noDecorators, "If there are no decorators on a flow the list of usage characteristics should be empty");
Long dtId = dataTypeHelper.createDataType("findDatatypeUsageCharacteristics");
Long dtId2 = dataTypeHelper.createDataType("findDatatypeUsageCharacteristics");
dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
Collection<DataTypeUsageCharacteristics> decoratorsOnFlow = dtdSvc.findDatatypeUsageCharacteristics(flow.entityReference());
assertEquals(asSet(dtId, dtId2), map(decoratorsOnFlow, DataTypeUsageCharacteristics::dataTypeId), "Returns usage characteristics for each data type associated to a flow");
assertEquals(asSet(true), map(decoratorsOnFlow, DataTypeUsageCharacteristics::isRemovable), "Characteristics suggest all flows are removable when there are no underlying physical flows");
Long specId = psHelper.createPhysicalSpec(a, "findDatatypeUsageCharacteristics");
pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, "findDatatypeUsageCharacteristics");
dtdSvc.updateDecorators(username, mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId), asSet(dtId), emptySet());
Collection<DataTypeUsageCharacteristics> decoratorsOnFlowWithUnderlyingSpec = dtdSvc.findDatatypeUsageCharacteristics(flow.entityReference());
DataTypeUsageCharacteristics dtDecorator = decoratorsOnFlowWithUnderlyingSpec.stream().filter(d -> d.dataTypeId() == dtId).findFirst().get();
DataTypeUsageCharacteristics dt2Decorator = decoratorsOnFlowWithUnderlyingSpec.stream().filter(d -> d.dataTypeId() == dtId2).findFirst().get();
assertFalse(dtDecorator.isRemovable(), "When underlying physical with datatype should not be removable");
assertTrue(dt2Decorator.isRemovable(), "When no underlying physical datatype should remain removable");
Collection<DataTypeUsageCharacteristics> usageCharacteristicsForSpec = dtdSvc.findDatatypeUsageCharacteristics(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId));
assertEquals(asSet(dtId), map(usageCharacteristicsForSpec, DataTypeUsageCharacteristics::dataTypeId), "Returns usage characteristics for each data type associated to a spec");
assertTrue(first(usageCharacteristicsForSpec).isRemovable(), "Specs should always be flagged as removable");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowServiceTest method removeFlowTest.
@Test
public void removeFlowTest() {
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
// a -> b
// a -> c
LogicalFlow ab = helper.createLogicalFlow(a, b);
LogicalFlow ac = helper.createLogicalFlow(a, b);
assertThrows(IllegalArgumentException.class, () -> lfSvc.removeFlow(-1L, "logicalFlowServiceTestRemoveFlow"), "Expect no flows to be removed where id cannot be found");
int removedForExistingIdCount = lfSvc.removeFlow(ab.id().get(), "logicalFlowServiceTestRemoveFlow");
assertEquals(1, removedForExistingIdCount, "Expect only one flow to be removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowServiceTest method addFlows.
@Test
public void addFlows() {
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
dataTypeHelper.createUnknownDatatype();
ImmutableAddLogicalFlowCommand createLoopCommand = ImmutableAddLogicalFlowCommand.builder().source(a).target(a).build();
ImmutableAddLogicalFlowCommand abCreateCommand = ImmutableAddLogicalFlowCommand.builder().source(a).target(b).build();
ImmutableAddLogicalFlowCommand baCreateCommand = ImmutableAddLogicalFlowCommand.builder().source(b).target(a).build();
ImmutableAddLogicalFlowCommand bcCreateCommand = ImmutableAddLogicalFlowCommand.builder().source(b).target(c).build();
List<LogicalFlow> noCreateCommands = lfSvc.addFlows(emptyList(), "addFlowTest");
assertEquals(emptyList(), noCreateCommands, "If no list provided returns empty list");
assertThrows(IllegalArgumentException.class, () -> lfSvc.addFlows(asList(createLoopCommand, abCreateCommand), "addFlowTest"), "If contains invalid flow (same src and trg) throws exception");
List<LogicalFlow> newFlows = lfSvc.addFlows(asList(abCreateCommand, baCreateCommand), "addFlowsTest");
assertEquals(2, newFlows.size(), "2 valid create commands should create 2 flows");
assertEquals(asSet(tuple(a, b), tuple(b, a)), map(newFlows, f -> tuple(f.source(), f.target())), "Source and targets in returned set match");
List<LogicalFlow> duplicatedFlows = lfSvc.addFlows(asList(bcCreateCommand, bcCreateCommand), "addFlowsTest");
assertEquals(1, duplicatedFlows.size(), "multiple create commands for same source and target should not create multiple flows");
assertEquals(asSet(tuple(b, c)), map(duplicatedFlows, f -> tuple(f.source(), f.target())), "multiple create commands for same source and target should not create multiple flows");
List<LogicalFlow> existingFlows = lfSvc.addFlows(asList(bcCreateCommand, abCreateCommand), "addFlowsTest");
assertTrue(existingFlows.isEmpty(), "should not create flow if flow already exists");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowServiceTest method cleanupSelfReferencingFlows.
@Test
public void cleanupSelfReferencingFlows() {
helper.clearAllFlows();
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
int removedFlows = lfSvc.cleanupSelfReferencingFlows();
assertEquals(0, removedFlows, "Nothing removed if no logical flows");
LogicalFlow ab = helper.createLogicalFlow(a, b);
int removedWhereNoSelfReferencingFlows = lfSvc.cleanupSelfReferencingFlows();
assertEquals(0, removedWhereNoSelfReferencingFlows, "Nothing removed if no self-referencing logical flows");
LogicalFlow aa = helper.createLogicalFlow(a, a);
LogicalFlow bb = helper.createLogicalFlow(b, b);
int removedAllWhereSelfReferencingFlows = lfSvc.cleanupSelfReferencingFlows();
assertEquals(2, removedAllWhereSelfReferencingFlows, "Removed all self-referencing logical flows");
LogicalFlow aaFlow = lfSvc.getById(aa.id().get());
assertEquals(EntityLifecycleStatus.REMOVED, aaFlow.entityLifecycleStatus(), "Self referencing flow still exists but is removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class LogicalFlowServiceTest method basicDirectAssociations.
@Test
public void basicDirectAssociations() {
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("c", ouIds.b);
// a -> b
// a -> d
// c
LogicalFlow ab = helper.createLogicalFlow(a, b);
LogicalFlow ad = helper.createLogicalFlow(a, d);
assertEquals(asSet(ab.id(), ad.id()), map(lfSvc.findByEntityReference(a), IdProvider::id), "Can see flow associated to 'a'");
assertEquals(asSet(ab.id()), map(lfSvc.findByEntityReference(b), IdProvider::id), "Can sees flows associated to 'b'");
assertEquals(asSet(ad.id()), map(lfSvc.findByEntityReference(d), IdProvider::id), "Can sees flows associated to 'd'");
assertTrue(isEmpty(lfSvc.findByEntityReference(c)), "Can sees nothing associated to 'c'");
}
Aggregations