Search in sources :

Example 11 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class PhysicalSpecificationServiceTest method markRemovedIfUnused.

@Test
public void markRemovedIfUnused() {
    String username = mkName("markRemovedIfUnused");
    assertThrows(IllegalArgumentException.class, () -> psSvc.markRemovedIfUnused(null, username), "Throws exception if entity reference is null");
    ImmutablePhysicalSpecificationDeleteCommand noSpecCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(-1L).build();
    CommandResponse<PhysicalSpecificationDeleteCommand> responseNoSpec = psSvc.markRemovedIfUnused(noSpecCmd, username);
    assertEquals(CommandOutcome.FAILURE, responseNoSpec.outcome(), "Fails to mark removed if spec not found");
    assertEquals("Specification not found", responseNoSpec.message().get(), "Should inform of reason for failure");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
    PhysicalFlowCreateCommandResponse physicalFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("markRemovedIfUnused"));
    ImmutablePhysicalSpecificationDeleteCommand deleteCmd = ImmutablePhysicalSpecificationDeleteCommand.builder().specificationId(specId).build();
    CommandResponse<PhysicalSpecificationDeleteCommand> responseWithUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
    assertEquals(CommandOutcome.FAILURE, responseWithUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
    assertEquals("This specification cannot be deleted as it is being referenced by one or more physical flows", responseWithUnderlyingFlows.message().get(), "Should inform of reason for failure");
    pfHelper.deletePhysicalFlow(physicalFlow.entityReference().id());
    CommandResponse<PhysicalSpecificationDeleteCommand> responseWithNoUnderlyingFlows = psSvc.markRemovedIfUnused(deleteCmd, username);
    assertEquals(CommandOutcome.SUCCESS, responseWithNoUnderlyingFlows.outcome(), "Should not remove spec if underlying flows");
}
Also used : PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) 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 12 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.

the class DataTypeDecoratorServiceTest method findByEntityIdSelector.

@Test
public void findByEntityIdSelector() {
    String username = mkName("findByEntityIdSelector");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    IdSelectionOptions appOpts = mkOpts(a);
    assertThrows(IllegalArgumentException.class, () -> dtdSvc.findByEntityIdSelector(EntityKind.APPLICATION, appOpts), "If not logical flow kind or physical spec kind should throw exception");
    List<DataTypeDecorator> selectorForLfWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(emptyList(), selectorForLfWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long dtId = dataTypeHelper.createDataType("findByEntityIdSelector");
    Long dtId2 = dataTypeHelper.createDataType("findByEntityIdSelector2");
    dtdSvc.updateDecorators(username, flow.entityReference(), asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorWithDecorators = dtdSvc.findByEntityIdSelector(EntityKind.LOGICAL_DATA_FLOW, appOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorWithDecorators, DataTypeDecorator::dataTypeId), "Returns all data types for flow selector");
    IdSelectionOptions flowOpts = mkOpts(flow.entityReference());
    List<DataTypeDecorator> selectorForPsWhereNoDecorators = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(emptyList(), selectorForPsWhereNoDecorators, "If no flows and decorators for selector returns empty list");
    Long psId = psHelper.createPhysicalSpec(a, "findByEntityIdSelector");
    EntityReference specRef = mkRef(EntityKind.PHYSICAL_SPECIFICATION, psId);
    pfHelper.createPhysicalFlow(flow.entityReference().id(), psId, "findByEntityIdSelector");
    dtdSvc.updateDecorators(username, specRef, asSet(dtId, dtId2), emptySet());
    List<DataTypeDecorator> selectorForPs = dtdSvc.findByEntityIdSelector(EntityKind.PHYSICAL_SPECIFICATION, flowOpts);
    assertEquals(asSet(dtId, dtId2), map(selectorForPs, DataTypeDecorator::dataTypeId), "Returns all data types for spec selector");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow 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 14 with LogicalFlow

use of org.finos.waltz.model.logical_flow.LogicalFlow 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 15 with LogicalFlow

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

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