Search in sources :

Example 1 with DataTypeUsageCharacteristics

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

Aggregations

BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)1 EntityReference (org.finos.waltz.model.EntityReference)1 DataTypeUsageCharacteristics (org.finos.waltz.model.datatype.DataTypeUsageCharacteristics)1 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)1 Test (org.junit.jupiter.api.Test)1