pvillard31 commented on code in PR #11570:
URL: https://github.com/apache/nifi/pull/11570#discussion_r4147112947
##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/StandardNiFiServiceFacadeTest.java:
##########
@@ -462,6 +478,143 @@ public void
testGetComponentsAffectedByFlowUpdate_WithNewStatelessProcessGroup_R
assertTrue(affected.isEmpty(), "No local components should be affected
for added Stateless group");
}
+ @Test
+ public void
testGetFlowUpdateImpactExtractsRemovedConnectionMetadataAndAffectedProjection()
{
+ final String rootGroupId = "root-group-instance";
+ final String removedGroupId = "removed-group-instance";
+
+ final ProcessGroup rootGroup = mock(ProcessGroup.class);
+
when(processGroupDAO.getProcessGroup(rootGroupId)).thenReturn(rootGroup);
+
+ final ProcessGroup rootGroupMetadata = mock(ProcessGroup.class);
+ when(rootGroupMetadata.getIdentifier()).thenReturn(rootGroupId);
+ when(rootGroupMetadata.getName()).thenReturn("Root Group");
+
+ final ProcessGroup removedGroup = mock(ProcessGroup.class);
+ when(removedGroup.getIdentifier()).thenReturn(removedGroupId);
+
when(processGroupDAO.getProcessGroup(removedGroupId)).thenReturn(removedGroup);
+ when(removedGroup.findAllProcessors()).thenReturn(List.of());
+ when(removedGroup.findAllFunnels()).thenReturn(List.of());
+ when(removedGroup.findAllInputPorts()).thenReturn(List.of());
+ when(removedGroup.findAllOutputPorts()).thenReturn(List.of());
+ when(removedGroup.findAllRemoteProcessGroups()).thenReturn(List.of());
+ when(removedGroup.findAllControllerServices()).thenReturn(Set.of());
+
+ final ProcessorNode removedSource = createLocalConnectableProcessor(
+ "removed-source-instance", "removed-source-versioned",
ConnectableType.PROCESSOR, rootGroupMetadata);
+ final Port removedDestination = createLocalConnectablePort(
+ "removed-destination-instance",
"removed-destination-versioned", ConnectableType.OUTPUT_PORT,
rootGroupMetadata);
+ final Port changedSource = createLocalConnectablePort(
+ "changed-source-instance", "changed-source-versioned",
ConnectableType.INPUT_PORT, rootGroupMetadata);
+ final ProcessorNode changedDestination =
createLocalConnectableProcessor(
+ "changed-destination-instance",
"changed-destination-versioned", ConnectableType.PROCESSOR, rootGroupMetadata);
+
+ when(rootGroup.findAllProcessors()).thenReturn(List.of(removedSource,
changedDestination));
+ when(rootGroup.findAllFunnels()).thenReturn(List.of());
+ when(rootGroup.findAllInputPorts()).thenReturn(List.of(changedSource));
+
when(rootGroup.findAllOutputPorts()).thenReturn(List.of(removedDestination));
+ when(rootGroup.findAllRemoteProcessGroups()).thenReturn(List.of());
+
+ stubLocalConnectableAuthorizable(removedSource.getIdentifier());
+ stubLocalConnectableAuthorizable(removedDestination.getIdentifier());
+ stubLocalConnectableAuthorizable(changedSource.getIdentifier());
+ stubLocalConnectableAuthorizable(changedDestination.getIdentifier());
+ stubConnectionAuthorizable("removed-connection-instance");
+ stubConnectionAuthorizable("changed-connection-instance");
+ stubProcessGroupAuthorizable(removedGroupId, removedGroup);
+ stubInputPortAuthorizable("removed-endpoint-instance");
+
+ final FlowComparison comparison = mock(FlowComparison.class);
+ when(comparison.getDifferences()).thenReturn(Set.of(
+ new StandardFlowDifference(DifferenceType.COMPONENT_REMOVED,
createRemovedConnection(), null, null, null, "Removed connection"),
+ new StandardFlowDifference(DifferenceType.SOURCE_CHANGED,
createSourceChangedConnection(), createReplacementConnection(), null, null,
"Source changed connection"),
+ new StandardFlowDifference(DifferenceType.COMPONENT_REMOVED,
createRemovedGroup(removedGroupId), null, null, null, "Removed group"),
+ new StandardFlowDifference(DifferenceType.COMPONENT_REMOVED,
createRemovedEndpoint(removedGroupId), null, null, null, "Removed endpoint")
+ ));
+
+ final StandardNiFiServiceFacade serviceFacadeSpy = spy(serviceFacade);
+
doReturn(comparison).when(serviceFacadeSpy).compareFlowUpdate(eq(rootGroup),
any(RegisteredFlowSnapshot.class));
+
+ final RegisteredFlowSnapshot updatedSnapshot = new
RegisteredFlowSnapshot();
+ final FlowUpdateImpact impact =
serviceFacadeSpy.getFlowUpdateImpact(rootGroupId, updatedSnapshot);
+
+ assertNotNull(impact);
+ assertEquals(Set.of(removedGroupId),
impact.getRemovedProcessGroupIds());
+ assertEquals(Set.of("removed-endpoint-instance"),
impact.getRemovedEndpointIds());
+
+ final Map<String, RemovedConnectionDescriptor>
removedConnectionByInstanceId = impact.getRemovedConnections().stream()
+
.collect(Collectors.toMap(RemovedConnectionDescriptor::getConnectionInstanceId,
Function.identity()));
+ assertEquals(Set.of("removed-connection-instance",
"changed-connection-instance"), removedConnectionByInstanceId.keySet());
+
+ final RemovedConnectionDescriptor pureRemoval =
removedConnectionByInstanceId.get("removed-connection-instance");
+ assertEquals(RemovalReason.COMPONENT_REMOVED,
pureRemoval.getRemovalReason());
+ assertEquals("removed-connection-versioned",
pureRemoval.getConnectionVersionedId());
+ assertEquals("root-group-instance",
pureRemoval.getContainingProcessGroupId());
+ assertEquals("removed-source-instance",
pureRemoval.getSourceInstanceId());
+ assertEquals("removed-source-versioned",
pureRemoval.getSourceVersionedId());
+ assertEquals("removed-source-group-instance",
pureRemoval.getSourceProcessGroupId());
+ assertEquals(ConnectableType.PROCESSOR, pureRemoval.getSourceType());
+ assertEquals("removed-destination-instance",
pureRemoval.getDestinationInstanceId());
+ assertEquals("removed-destination-versioned",
pureRemoval.getDestinationVersionedId());
+ assertEquals("removed-destination-group-instance",
pureRemoval.getDestinationProcessGroupId());
+ assertEquals(ConnectableType.OUTPUT_PORT,
pureRemoval.getDestinationType());
+
+ final RemovedConnectionDescriptor sourceChanged =
removedConnectionByInstanceId.get("changed-connection-instance");
+ assertEquals(RemovalReason.SOURCE_CHANGED,
sourceChanged.getRemovalReason());
+ assertEquals("changed-source-instance",
sourceChanged.getSourceInstanceId());
+ assertEquals("changed-destination-instance",
sourceChanged.getDestinationInstanceId());
+
+ final Set<String> affectedIdsFromImpact =
impact.getAffectedComponents().stream()
+ .map(AffectedComponentEntity::getId)
+ .collect(Collectors.toCollection(LinkedHashSet::new));
+ assertTrue(affectedIdsFromImpact.contains("removed-source-instance"));
Review Comment:
Agreed. The test now asserts the exact expected set of affected component
IDs, including removed and changed connections, and no longer compares a
projection against the same implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]