Search in sources :

Example 6 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class DataTypeDecoratorServiceTest method updateDecorators.

@Test
public void updateDecorators() {
    String username = mkName("updateDecorators");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.updateDecorators(null, flow.entityReference(), emptySet(), emptySet()), "Throws exception if no username provided");
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.updateDecorators(username, null, emptySet(), emptySet()), "Throws exception if no ref provided");
    assertThrows(UnsupportedOperationException.class, () -> dtdSvc.updateDecorators(username, mkRef(EntityKind.APPLICATION, -1L), emptySet(), emptySet()), "Throws exception if no unsupported ref provided");
    Long dtId = dataTypeHelper.createDataType("updateDecorators");
    Long dtId2 = dataTypeHelper.createDataType("updateDecorators2");
    Long dtId3 = dataTypeHelper.createDataType("updateDecorators3");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
    Collection<DataTypeDecorator> flowDecorators = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId, dtId2), map(flowDecorators, DataTypeDecorator::dataTypeId), "Adds data types that do not exist on flow");
    dtdSvc.updateDecorators(username, flow.entityReference(), emptySet(), asSet(dtId3));
    Collection<DataTypeDecorator> removeDtNotAssociated = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId, dtId2), map(removeDtNotAssociated, DataTypeDecorator::dataTypeId), "Removing dt not associated does not change set of decorators");
    dtdSvc.updateDecorators(username, flow.entityReference(), emptySet(), asSet(dtId2));
    Collection<DataTypeDecorator> removedDatatype = dtdSvc.findByFlowIds(asSet(flow.entityReference().id()), EntityKind.LOGICAL_DATA_FLOW);
    assertEquals(asSet(dtId), map(removedDatatype, DataTypeDecorator::dataTypeId), "Removed associated datatype");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class DataTypeDecoratorServiceTest method findByEntityId.

@Test
public void findByEntityId() {
    String username = mkName("getByEntityRefAndDataTypeId");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityId(a), "If unsupported kind id throws exception");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    List<DataTypeDecorator> flowWithNoDts = dtdSvc.findByEntityId(flow.entityReference());
    assertEquals(emptyList(), flowWithNoDts, "If flow has no data types returns empty list");
    Long psId = psHelper.createPhysicalSpec(a, "getByEntityRefAndDataTypeId");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    List<DataTypeDecorator> specWithNoDts = dtdSvc.findByEntityId(specRef);
    assertEquals(emptyList(), specWithNoDts, "If spec has no data types returns empty list");
    Long dtId = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId");
    Long dtId2 = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId2");
    Long dtId3 = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId3");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2, dtId3), emptySet());
    List<DataTypeDecorator> flowDecorators = dtdSvc.findByEntityId(flow.entityReference());
    assertEquals(asSet(dtId, dtId2, dtId3), map(flowDecorators, DataTypeDecorator::dataTypeId), "Returns all data types on flow");
    dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2, dtId3), emptySet());
    List<DataTypeDecorator> specDecorators = dtdSvc.findByEntityId(specRef);
    assertEquals(asSet(dtId, dtId2, dtId3), map(specDecorators, DataTypeDecorator::dataTypeId), "Returns all data types on spec");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class DataTypeDecoratorServiceTest method getByEntityRefAndDataTypeId.

@Test
public void getByEntityRefAndDataTypeId() {
    String username = mkName("getByEntityRefAndDataTypeId");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.getByEntityRefAndDataTypeId(a, 1L), "If unsupported kind id throws exception");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    DataTypeDecorator noDt = dtdSvc.getByEntityRefAndDataTypeId(flow.entityReference(), -1L);
    assertNull(noDt, "Returns null no match for dt on flow");
    Long dtId = dataTypeHelper.createDataType("getByEntityRefAndDataTypeId");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId), emptySet());
    DataTypeDecorator dataTypeDecorator = dtdSvc.getByEntityRefAndDataTypeId(flow.entityReference(), dtId);
    assertEquals(dtId, Long.valueOf(dataTypeDecorator.dataTypeId()), "Returns datatype if exists on flow");
    Long psId = psHelper.createPhysicalSpec(a, "getByEntityRefAndDataTypeId");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    dtdSvc.updateDecorators(username, specRef, asSet(dtId), emptySet());
    DataTypeDecorator specDtd = dtdSvc.getByEntityRefAndDataTypeId(specRef, dtId);
    assertEquals(dtId, Long.valueOf(specDtd.dataTypeId()), "Returns datatype if exists on spec");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with EntityReference

use of org.finos.waltz.model.EntityReference 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 10 with EntityReference

use of org.finos.waltz.model.EntityReference 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)

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