use of org.finos.waltz.model.EntityReference 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.EntityReference 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.EntityReference 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'");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class LogicalFlowServiceTest method bySelector.
@Test
public void bySelector() {
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
// c
LogicalFlow ab = helper.createLogicalFlow(a, b);
LogicalFlow ac = helper.createLogicalFlow(a, c);
assertEquals(asSet(ab.id(), ac.id()), map(lfSvc.findBySelector(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.root), CHILDREN)), IdProvider::id), "find by root ou gives all");
assertEquals(asSet(ac.id()), map(lfSvc.findBySelector(mkOpts(mkRef(EntityKind.ORG_UNIT, ouIds.b), CHILDREN)), IdProvider::id), "find by ou 'b' gives only one flow");
}
use of org.finos.waltz.model.EntityReference in project waltz by khartec.
the class LogicalFlowServiceTest method findActiveByFlowIdsTest.
@Test
public void findActiveByFlowIdsTest() {
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);
// a -> b
// a -> c
LogicalFlow ab = helper.createLogicalFlow(a, b);
LogicalFlow ac = helper.createLogicalFlow(a, c);
LogicalFlow ad = helper.createLogicalFlow(a, d);
int removedFlowCount = lfSvc.removeFlow(ab.id().get(), "logicalFlowServiceTestRemoveFlow");
Collection<LogicalFlow> activeFlows = lfSvc.findActiveByFlowIds(asSet(ab.id().get(), ac.id().get(), ad.id().get()));
Set<Long> activeFlowIds = map(activeFlows, r -> r.id().get());
assertEquals(activeFlows.size(), 2);
assertEquals(asSet(ad.id().get(), ac.id().get()), activeFlowIds);
assertEquals(asSet(ac.id().get(), ad.id().get()), activeFlowIds);
}
Aggregations