diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/fingerprint/FingerprintFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/fingerprint/FingerprintFactory.java index 999a42d657..e873af8d9a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/fingerprint/FingerprintFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/fingerprint/FingerprintFactory.java @@ -614,7 +614,7 @@ public class FingerprintFactory { // relationships final NodeList relationshipElems = DomUtils.getChildNodesByTagName(connectionElem, "relationship"); - final List sortedRelationshipElems = sortElements(relationshipElems, getConnectionRelationshipsComparator()); + final List sortedRelationshipElems = sortElements(relationshipElems, getElementTextComparator()); for (final Element relationshipElem : sortedRelationshipElems) { builder.append(getValue(relationshipElem, NO_VALUE)); } @@ -766,36 +766,7 @@ public class FingerprintFactory { } }; } - - private Comparator getConnectionRelationshipsComparator() { - return getSingleChildComparator("relationship"); - } - - private Comparator getSingleChildComparator(final String childElementName) { - return new Comparator() { - @Override - public int compare(final Element e1, final Element e2) { - if (e2 == null) { - return -1; - } else if (e1 == null) { - return 1; - } - - // compare using processor ids - final String e1Id = getFirstValue(DomUtils.getChildNodesByTagName(e1, childElementName)); - if (e1Id == null) { - return 1; - } - final String e2Id = getFirstValue(DomUtils.getChildNodesByTagName(e2, childElementName)); - if (e2Id == null) { - return -1; - } - - return e1Id.compareTo(e2Id); - } - }; - } - + private Comparator getElementTextComparator() { return new Comparator() { @Override diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java index 09acbc98f6..befe332b5e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/fingerprint/FingerprintFactoryTest.java @@ -16,24 +16,6 @@ */ package org.apache.nifi.fingerprint; -import static org.apache.nifi.controller.serialization.ScheduledStateLookup.IDENTITY_LOOKUP; -import static org.apache.nifi.fingerprint.FingerprintFactory.FLOW_CONFIG_XSD; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.Collections; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import java.util.Optional; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.connectable.Position; @@ -55,6 +37,25 @@ import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.Optional; + +import static org.apache.nifi.controller.serialization.ScheduledStateLookup.IDENTITY_LOOKUP; +import static org.apache.nifi.fingerprint.FingerprintFactory.FLOW_CONFIG_XSD; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** */ public class FingerprintFactoryTest { @@ -124,6 +125,13 @@ public class FingerprintFactoryTest { assertNotEquals(fp1, fp2); } + @Test + public void testConnectionWithMultipleRelationshipsSortedInFingerprint() throws IOException { + final String fingerprint = fingerprinter.createFingerprint(getResourceBytes("/nifi/fingerprint/flow-connection-with-multiple-rels.xml"), null); + assertNotNull(fingerprint); + assertTrue(fingerprint.contains("AAABBBCCCDDD")); + } + @Test public void testSchemaValidation() throws IOException { FingerprintFactory fp = new FingerprintFactory(null, getValidatingDocumentBuilder(), extensionManager); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow-connection-with-multiple-rels.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow-connection-with-multiple-rels.xml new file mode 100644 index 0000000000..45bc5e7cc0 --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/nifi/fingerprint/flow-connection-with-multiple-rels.xml @@ -0,0 +1,40 @@ + + + + 15 + + + 5bd05300-f03d-4511-a13f-6a36afe2bcc5 + + + 1 + 0 +