Skip to content

Commit

Permalink
NIFI-14279 - StandardFlowDifference hashCode should include fieldName
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sampson <chris.sampson82@gmail.com>

This closes #9729.
  • Loading branch information
pvillard31 authored and ChrisSamo632 committed Feb 27, 2025
1 parent ecd4dbb commit 244691e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ public String toString() {

@Override
public int hashCode() {
return 31 + 17 * (componentA == null ? 0 : Objects.hashCode(componentA.getIdentifier())) +
17 * (componentB == null ? 0 : Objects.hashCode(componentB.getIdentifier())) +
15 * (componentA == null ? 0 : Objects.hash(componentA.getInstanceIdentifier())) +
15 * (componentB == null ? 0 : Objects.hash(componentB.getInstanceIdentifier())) +
Objects.hash(description, type, valueA, valueB);
return Objects.hash(
type,
componentA == null ? null : componentA.getIdentifier(),
componentA == null ? null : componentA.getInstanceIdentifier(),
componentB == null ? null : componentB.getIdentifier(),
componentB == null ? null : componentB.getInstanceIdentifier(),
fieldName.orElse(null),
valueA,
valueB,
description);
}

@Override
Expand Down Expand Up @@ -128,6 +133,7 @@ public boolean equals(final Object obj) {

return Objects.equals(componentAId, otherComponentAId) && Objects.equals(componentBId, otherComponentBId)
&& Objects.equals(description, other.description) && Objects.equals(type, other.type)
&& Objects.equals(valueA, other.valueA) && Objects.equals(valueB, other.valueB);
&& Objects.equals(valueA, other.valueA) && Objects.equals(valueB, other.valueB)
&& fieldName.orElse("").equals(other.fieldName.orElse(""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@ public void testAssetReferencesChanged() {
assertEquals(contextB.getIdentifier(), difference.getComponentB().getIdentifier());
}

@Test
public void testMultipleParametersNamesChanged() {
final Set<FlowDifference> differences = new HashSet<>();

final Set<VersionedParameter> parametersA = new HashSet<>();
parametersA.add(createParameter("Param 1", "ABC", true));
parametersA.add(createParameter("Param 2", "XYZ", true));

final Set<VersionedParameter> parametersB = new HashSet<>();
parametersB.add(createParameter("New Param 1", "ABC", true));
parametersB.add(createParameter("New Param 2", "XYZ", true));

final VersionedParameterContext contextA = new VersionedParameterContext();
contextA.setIdentifier("id");
contextA.setInstanceIdentifier("instanceId");
contextA.setParameters(parametersA);

final VersionedParameterContext contextB = new VersionedParameterContext();
contextB.setIdentifier("id");
contextB.setInstanceIdentifier("instanceId");
contextB.setParameters(parametersB);

comparator.compare(contextA, contextB, differences);

assertEquals(4, differences.size());
}

private VersionedParameter createParameter(final String name, final String value, final boolean sensitive) {
return createParameter(name, value, sensitive, null);
}
Expand Down

0 comments on commit 244691e

Please sign in to comment.