Search in sources :

Example 11 with EntityReference

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");
}
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 12 with EntityReference

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

Example 13 with EntityReference

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

Example 14 with EntityReference

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

Example 15 with EntityReference

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

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7