Search in sources :

Example 1 with PhysicalFlowCreateCommandResponse

use of org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse 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 2 with PhysicalFlowCreateCommandResponse

use of org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse in project waltz by khartec.

the class PhysicalSpecificationServiceTest method findBySelector.

@Test
public void findBySelector() {
    assertThrows(IllegalArgumentException.class, () -> psSvc.findBySelector(null), "Options cannot be null");
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
    IdSelectionOptions specOpts = mkOpts(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId));
    Collection<PhysicalSpecification> specs = psSvc.findBySelector(specOpts);
    assertEquals(1, specs.size(), "When selector is a spec only returns one result");
    assertEquals(specId, first(specs).id().get(), "Returns spec when using spec selector");
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
    Long specId2 = psHelper.createPhysicalSpec(b, "findByEntityReference");
    PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findBySelector"));
    PhysicalFlowCreateCommandResponse physFlow2 = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId2, mkName("findBySelector"));
    IdSelectionOptions appOpts = mkOpts(mkRef(EntityKind.APPLICATION, b.id()));
    assertThrows(UnsupportedOperationException.class, () -> psSvc.findBySelector(appOpts), "Throws exception  for unsupported entity kinds");
    IdSelectionOptions flowOpts = mkOpts(mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.entityReference().id()));
    Collection<PhysicalSpecification> specsForFlow = psSvc.findBySelector(flowOpts);
    assertEquals(2, specsForFlow.size(), "Returns all specs linked to a flow");
    assertEquals(asSet(specId, specId2), map(specsForFlow, d -> d.entityReference().id()), "Returns all specs linked to a flow");
    pfHelper.deletePhysicalFlow(physFlow2.entityReference().id());
    psHelper.removeSpec(specId2);
    Collection<PhysicalSpecification> activeSpecsForFlow = psSvc.findBySelector(flowOpts);
    assertEquals(1, activeSpecsForFlow.size(), "Returns all specs linked to a flow");
    assertEquals(asSet(specId), map(activeSpecsForFlow, d -> d.entityReference().id()), "Returns only active specs linked to a flow");
}
Also used : PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) 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) 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 3 with PhysicalFlowCreateCommandResponse

use of org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse in project waltz by khartec.

the class PhysicalSpecificationServiceTest method isUsed.

@Test
public void isUsed() {
    assertThrows(IllegalArgumentException.class, () -> psSvc.isUsed(null), "Specification id must not be null");
    String username = mkName("propagateDataTypesToLogicalFlows");
    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");
    assertFalse(psSvc.isUsed(specId), "Should return false when so physical flows");
    PhysicalFlowCreateCommandResponse physicalFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, username);
    assertTrue(psSvc.isUsed(specId), "Should return false when associated physical flows");
    pfHelper.deletePhysicalFlow(physicalFlow.entityReference().id());
    assertFalse(psSvc.isUsed(specId), "Should return false when all physical flows are removed");
}
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 4 with PhysicalFlowCreateCommandResponse

use of org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse in project waltz by khartec.

the class PhysicalSpecificationServiceTest method findByEntityReference.

@Test
public void findByEntityReference() {
    assertThrows(IllegalArgumentException.class, () -> psSvc.findByEntityReference(null), "Throws exception if entity reference is null");
    Set<PhysicalSpecification> whereEntityUnrelated = psSvc.findByEntityReference(mkRef(EntityKind.COST_KIND, -1));
    assertEquals(emptySet(), whereEntityUnrelated, "Returns an empty set where entity is not related");
    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");
    Set<PhysicalSpecification> returnsAsSetEvenIfMultipleLinksToSpec = psSvc.findByEntityReference(a);
    assertEquals(asSet(a.id()), map(returnsAsSetEvenIfMultipleLinksToSpec, d -> d.owningEntity().id()), "Should return if no flows but is owning entity");
    Set<PhysicalSpecification> noFlows = psSvc.findByEntityReference(b);
    assertEquals(emptySet(), noFlows, "Should return empty set for an application if not owner or linked by flow");
    PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findByEntityReference"));
    Set<PhysicalSpecification> linkedByPhysFlow = psSvc.findByEntityReference(b);
    assertEquals(asSet(specId), map(linkedByPhysFlow, d -> d.entityReference().id()), "Should return specs for an application if linked to a flow");
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) 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)

Aggregations

BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)4 EntityReference (org.finos.waltz.model.EntityReference)4 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)4 PhysicalFlowCreateCommandResponse (org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse)4 Test (org.junit.jupiter.api.Test)4 Collection (java.util.Collection)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptySet (java.util.Collections.emptySet)2 List (java.util.List)2 Set (java.util.Set)2 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)2 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)2 ListUtilities.asList (org.finos.waltz.common.ListUtilities.asList)2 SetUtilities.asSet (org.finos.waltz.common.SetUtilities.asSet)2 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)2 org.finos.waltz.integration_test.inmem.helpers (org.finos.waltz.integration_test.inmem.helpers)2 NameHelper.mkName (org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName)2 EntityKind (org.finos.waltz.model.EntityKind)2 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)2 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)2