This is an automated email from the ASF dual-hosted git repository. tpalfy pushed a commit to branch pr/8160/merge in repository https://gitbox.apache.org/repos/asf/nifi.git
commit e031ff254741d097bc51a9858b5c451cde4f52be Author: tpalfy <tpa...@cloudera.com> AuthorDate: Wed Jan 24 20:58:31 2024 +0100 NIFI-12500: Fix failing test in SNMPRequestIT --- .../apache/nifi/snmp/operations/SNMPRequestIT.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/operations/SNMPRequestIT.java b/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/operations/SNMPRequestIT.java index ebc457bd87..ca03396582 100644 --- a/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/operations/SNMPRequestIT.java +++ b/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/operations/SNMPRequestIT.java @@ -30,6 +30,7 @@ import org.apache.nifi.snmp.testagents.TestAgent; import org.apache.nifi.snmp.testagents.TestSNMPV1Agent; import org.apache.nifi.snmp.testagents.TestSNMPV2cAgent; import org.apache.nifi.snmp.testagents.TestSNMPV3Agent; +import org.apache.nifi.util.EqualsWrapper; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -46,10 +47,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -250,15 +253,31 @@ class SNMPRequestIT { final Optional<SNMPSingleResponse> optionalResponse = getSNMPHandler.get(getFlowFileAttributesForSnmpGet(INVALID_OID, READ_ONLY_OID_2), target); if (optionalResponse.isPresent()) { final SNMPSingleResponse response = optionalResponse.get(); + final Set<SNMPValue> actualVariableBindings = new HashSet<>(response.getVariableBindings()); + final Set<SNMPValue> expectedVariableBindings; + + final List<Function<SNMPValue, Object>> equalsProperties = Arrays.asList( + SNMPValue::getOid, + SNMPValue::getVariable + ); + if (version == SnmpConstants.version1) { - assertEquals("Null", response.getVariableBindings().get(1).getVariable()); - assertEquals(READ_ONLY_OID_VALUE_2, response.getVariableBindings().get(0).getVariable()); + expectedVariableBindings = new HashSet<>(Arrays.asList( + new SNMPValue(INVALID_OID, "Null"), + new SNMPValue(READ_ONLY_OID_2, READ_ONLY_OID_VALUE_2) + )); assertEquals(NO_SUCH_NAME, response.getErrorStatusText()); } else { - assertEquals(NO_SUCH_OBJECT, response.getVariableBindings().get(1).getVariable()); - assertEquals(READ_ONLY_OID_VALUE_2, response.getVariableBindings().get(0).getVariable()); + expectedVariableBindings = new HashSet<>(Arrays.asList( + new SNMPValue(INVALID_OID, NO_SUCH_OBJECT), + new SNMPValue(READ_ONLY_OID_2, READ_ONLY_OID_VALUE_2) + )); assertEquals(SUCCESS, response.getErrorStatusText()); } + assertEquals( + new HashSet<>(EqualsWrapper.wrapList(actualVariableBindings, equalsProperties)), + new HashSet<>(EqualsWrapper.wrapList(expectedVariableBindings, equalsProperties)) + ); } else { fail("Response is not present."); }