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