use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method create_canCreateNewSpecIfRequired.
@Test
public void create_canCreateNewSpecIfRequired() {
String username = mkName("createWillCreateSpecIfRequired");
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
String specExtId = mkName("createWillCreateSpecIfRequired");
ImmutablePhysicalSpecification newSpec = ImmutablePhysicalSpecification.builder().externalId(specExtId).owningEntity(a).name(specExtId).description(specExtId).format(DataFormatKind.UNKNOWN).lastUpdatedBy(username).isRemoved(false).created(UserTimestamp.mkForUser(username, DateTimeUtilities.nowUtcTimestamp())).build();
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(newSpec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse firstCreateResp = pfSvc.create(createCommand, username);
assertEquals(CommandOutcome.SUCCESS, firstCreateResp.outcome(), "Successfully creates flow when new spec needs to be created");
PhysicalFlow newPhysFlow = pfSvc.getById(firstCreateResp.entityReference().id());
PhysicalSpecification createdSpec = psSvc.getById(newPhysFlow.specificationId());
assertEquals(specExtId, createdSpec.externalId().get(), "Specification associated to new flow has the correct external id");
assertEquals(username, createdSpec.created().get().by(), "Specification associated to flow has the correct user against it");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method merge.
@Test
public void merge() {
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("merge"));
Long specId2 = psHelper.createPhysicalSpec(a, mkName("merge2"));
PhysicalFlowCreateCommandResponse firstFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("merge"));
PhysicalFlowCreateCommandResponse secondFlowCreateResp = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId2, mkName("merge"));
pfHelper.updateExternalIdOnFlowDirectly(firstFlowCreateResp.entityReference().id(), "merge");
boolean merge = pfSvc.merge(firstFlowCreateResp.entityReference().id(), secondFlowCreateResp.entityReference().id(), mkName("merge"));
List<PhysicalFlow> flowsWithMergeExtId = pfSvc.findByExternalId("merge");
PhysicalFlow firstFlowAfterUpdate = pfSvc.getById(firstFlowCreateResp.entityReference().id());
assertTrue(firstFlowAfterUpdate.isRemoved(), "Once merged the original flow should no longer be active");
assertTrue(map(flowsWithMergeExtId, d -> d.entityReference().id()).contains(secondFlowCreateResp.entityReference().id()), "Once merged the second flow should have the external id of the original");
PhysicalSpecification specAfterUpdate = psSvc.getById(specId);
assertTrue(specAfterUpdate.isRemoved(), "If last remaining flow spec should be removed");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findBySpecificationId.
@Test
public void findBySpecificationId() {
List<PhysicalFlow> unknownSpecId = pfSvc.findBySpecificationId(-1);
assertEquals(emptyList(), unknownSpecId, "If unknown spec id returns empty list");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
EntityReference c = appHelper.createNewApp("c", ouIds.b);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
LogicalFlow bc = lfHelper.createLogicalFlow(b, c);
LogicalFlow ac = lfHelper.createLogicalFlow(a, c);
Long specId = psHelper.createPhysicalSpec(a, "findBySpecificationId");
Long specId2 = psHelper.createPhysicalSpec(a, mkName("findBySpecificationId"));
PhysicalFlowCreateCommandResponse physicalFlowResponse = pfHelper.createPhysicalFlow(ab.entityReference().id(), specId, mkName("findBySpecificationId"));
List<PhysicalFlow> physicalFlows = pfSvc.findBySpecificationId(specId);
assertEquals(asSet(physicalFlowResponse.entityReference().id()), map(physicalFlows, d -> d.entityReference().id()), "findBySpecificationId returns correct physical flows");
PhysicalFlowCreateCommandResponse physicalFlowResponse2 = pfHelper.createPhysicalFlow(bc.entityReference().id(), specId, mkName("findBySpecificationId"));
PhysicalFlowCreateCommandResponse physicalFlowResponse3 = pfHelper.createPhysicalFlow(ac.entityReference().id(), specId2, mkName("findBySpecificationId"));
List<PhysicalFlow> physicalFlows2 = pfSvc.findBySpecificationId(specId);
assertEquals(asSet(physicalFlowResponse.entityReference().id(), physicalFlowResponse2.entityReference().id()), map(physicalFlows2, d -> d.entityReference().id()), "findBySpecificationId returns only physical flows with that spec");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method findByExternalId.
@Test
public void findByExternalId() {
List<PhysicalFlow> listFromNullExtId = pfSvc.findByExternalId(null);
assertEquals(emptyList(), listFromNullExtId, "If null ext id returns empty list");
List<PhysicalFlow> listFromUnknownExtId = pfSvc.findByExternalId(mkName("findByExternalId"));
assertEquals(emptyList(), listFromUnknownExtId, "If ext id doesn't exist returns empty list");
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, "findByExternalId");
PhysicalFlowCreateCommandResponse physicalFlowResponse = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findByExternalId"));
extIdHelper.createExtId(physicalFlowResponse.entityReference(), "findByExternalId", mkName("findByExternalId"));
List<PhysicalFlow> physicalFlows = pfSvc.findByExternalId("findByExternalId");
assertEquals(1, physicalFlows.size(), "findByExternalIds returns correct number of physical flows");
assertEquals(asSet(physicalFlowResponse.entityReference().id()), map(physicalFlows, d -> d.entityReference().id()), "findByExternalIds returns correct physical flows");
Long specId2 = psHelper.createPhysicalSpec(a, "findByExternalId2");
PhysicalFlowCreateCommandResponse physicalFlowResponse2 = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId2, mkName("findByExternalId2"));
extIdHelper.createExtId(physicalFlowResponse2.entityReference(), "findByExternalId", mkName("findByExternalId2"));
List<PhysicalFlow> twoPhysicalFlows = pfSvc.findByExternalId("findByExternalId");
assertEquals(2, twoPhysicalFlows.size(), "findByExternalIds returns correct number of physical flows");
assertEquals(asSet(physicalFlowResponse.entityReference().id(), physicalFlowResponse2.entityReference().id()), map(twoPhysicalFlows, d -> d.entityReference().id()), "findByExternalIds returns correct physical flows");
}
use of org.finos.waltz.model.logical_flow.LogicalFlow in project waltz by khartec.
the class PhysicalFlowServiceTest method create_ifDuplicateFlowWillReturnFailureWithMessage.
@Test
public void create_ifDuplicateFlowWillReturnFailureWithMessage() {
String username = mkName("createIfDuplicateFlowWillReturnFailureWithMessage");
EntityReference a = appHelper.createNewApp(mkName("a"), ouIds.a);
EntityReference b = appHelper.createNewApp(mkName("b"), ouIds.a1);
LogicalFlow ab = lfHelper.createLogicalFlow(a, b);
Long specId = psHelper.createPhysicalSpec(a, mkName("createIfDuplicateFlowWillReturnFailureWithMessage"));
PhysicalSpecification spec = psSvc.getById(specId);
ImmutableFlowAttributes flowAttrs = ImmutableFlowAttributes.builder().frequency(FrequencyKind.DAILY).criticality(Criticality.MEDIUM).transport(TransportKindValue.UNKNOWN).basisOffset(0).build();
ImmutablePhysicalFlowCreateCommand createCommand = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
ImmutablePhysicalFlowCreateCommand createCommand2 = ImmutablePhysicalFlowCreateCommand.builder().logicalFlowId(ab.entityReference().id()).specification(spec).flowAttributes(flowAttrs).build();
PhysicalFlowCreateCommandResponse firstCreateResp = pfSvc.create(createCommand, username);
assertEquals(CommandOutcome.SUCCESS, firstCreateResp.outcome(), "Successfully creates flow when new");
PhysicalFlowCreateCommandResponse secondCreateResp = pfSvc.create(createCommand2, username);
assertEquals(CommandOutcome.FAILURE, secondCreateResp.outcome(), "Fails to create flow when a similar one is already active");
assertTrue(secondCreateResp.message().map(msg -> msg.equalsIgnoreCase("Duplicate with existing flow")).orElse(false), "Failure message advises user that there is an existing flow");
}
Aggregations