use of org.finos.waltz.model.logical_flow.ImmutableAddLogicalFlowCommand 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.ImmutableAddLogicalFlowCommand in project waltz by khartec.
the class LogicalFlowServiceTest method addFlow.
@Test
public void addFlow() {
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
dataTypeHelper.createUnknownDatatype();
ImmutableAddLogicalFlowCommand createLoopCommand = ImmutableAddLogicalFlowCommand.builder().source(a).target(a).build();
ImmutableAddLogicalFlowCommand createCommand = ImmutableAddLogicalFlowCommand.builder().source(a).target(b).build();
assertThrows(IllegalArgumentException.class, () -> lfSvc.addFlow(createLoopCommand, "addFlowTest"), "If source and target are the same, flow rejected and exception thrown");
LogicalFlow newFlow = lfSvc.addFlow(createCommand, "addFlowTest");
assertEquals(a, newFlow.source(), "Flow created should have the same source as in the create command");
assertEquals(b, newFlow.target(), "Flow created should have the same target as in the create command");
assertEquals("addFlowTest", newFlow.lastUpdatedBy(), "Flow created should have the user as the last updated by value");
}
Aggregations