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