Search in sources :

Example 16 with LogicalFlow

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

Example 17 with LogicalFlow

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");
}
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 18 with LogicalFlow

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");
}
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 19 with LogicalFlow

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");
}
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 20 with LogicalFlow

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'");
}
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

LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)72 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)52 Test (org.junit.jupiter.api.Test)52 EntityReference (org.finos.waltz.model.EntityReference)40 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)15 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)13 LogicalFlowService (org.finos.waltz.service.logical_flow.LogicalFlowService)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Collections.emptyList (java.util.Collections.emptyList)12 List (java.util.List)12 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)12 Collection (java.util.Collection)11 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)11 Collections.emptySet (java.util.Collections.emptySet)10 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)10 Assertions (org.junit.jupiter.api.Assertions)10 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)9 org.finos.waltz.integration_test.inmem.helpers (org.finos.waltz.integration_test.inmem.helpers)9