Search in sources :

Example 1 with ImmutableAddLogicalFlowCommand

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");
}
Also used : EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) ImmutableAddLogicalFlowCommand(org.finos.waltz.model.logical_flow.ImmutableAddLogicalFlowCommand) LogicalFlowHelper(org.finos.waltz.integration_test.inmem.helpers.LogicalFlowHelper) DataTypeHelper(org.finos.waltz.integration_test.inmem.helpers.DataTypeHelper) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) Tuple2(org.jooq.lambda.tuple.Tuple2) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) CHILDREN(org.finos.waltz.model.HierarchyQueryScope.CHILDREN) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) CollectionUtilities.isEmpty(org.finos.waltz.common.CollectionUtilities.isEmpty) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) AppHelper(org.finos.waltz.integration_test.inmem.helpers.AppHelper) Set(java.util.Set) IdProvider(org.finos.waltz.model.IdProvider) Test(org.junit.jupiter.api.Test) List(java.util.List) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ImmutableAddLogicalFlowCommand(org.finos.waltz.model.logical_flow.ImmutableAddLogicalFlowCommand) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ImmutableAddLogicalFlowCommand

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");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ImmutableAddLogicalFlowCommand(org.finos.waltz.model.logical_flow.ImmutableAddLogicalFlowCommand) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)2 EntityReference (org.finos.waltz.model.EntityReference)2 ImmutableAddLogicalFlowCommand (org.finos.waltz.model.logical_flow.ImmutableAddLogicalFlowCommand)2 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)2 Test (org.junit.jupiter.api.Test)2 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Set (java.util.Set)1 CollectionUtilities.isEmpty (org.finos.waltz.common.CollectionUtilities.isEmpty)1 ListUtilities.asList (org.finos.waltz.common.ListUtilities.asList)1 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 AppHelper (org.finos.waltz.integration_test.inmem.helpers.AppHelper)1 DataTypeHelper (org.finos.waltz.integration_test.inmem.helpers.DataTypeHelper)1 LogicalFlowHelper (org.finos.waltz.integration_test.inmem.helpers.LogicalFlowHelper)1 EntityKind (org.finos.waltz.model.EntityKind)1 EntityLifecycleStatus (org.finos.waltz.model.EntityLifecycleStatus)1 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)1 CHILDREN (org.finos.waltz.model.HierarchyQueryScope.CHILDREN)1