tpalfy commented on code in PR #8160:
URL: https://github.com/apache/nifi/pull/8160#discussion_r1465482740
##########
nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/test/java/org/apache/nifi/snmp/operations/SNMPRequestIT.java:
##########
@@ -237,9 +243,11 @@ void testSnmpGetInvalidOidWithFlowFileInput(int version,
SNMPConfigurationFactor
agent.start();
try {
final SNMPConfiguration snmpConfiguration =
snmpConfigurationFactory.createSnmpGetSetConfiguration(agent.getPort());
- snmpResourceHandler =
SNMPFactoryProvider.getFactory(version).createSNMPResourceHandler(snmpConfiguration);
- final GetSNMPHandler getSNMPHandler = new
GetSNMPHandler(snmpResourceHandler);
- final Optional<SNMPSingleResponse> optionalResponse =
getSNMPHandler.get(getFlowFileAttributesForSnmpGet(INVALID_OID,
READ_ONLY_OID_2));
+ final SNMPContext factory =
SNMPFactoryProvider.getFactory(version);
+ final Target target =
factory.createTargetInstance(snmpConfiguration);
+ final Snmp snmpManager =
factory.createSnmpManagerInstance(snmpConfiguration);
+ final GetSNMPHandler getSNMPHandler = new
GetSNMPHandler(snmpManager);
+ final Optional<SNMPSingleResponse> optionalResponse =
getSNMPHandler.get(getFlowFileAttributesForSnmpGet(INVALID_OID,
READ_ONLY_OID_2), target);
if (optionalResponse.isPresent()) {
final SNMPSingleResponse response = optionalResponse.get();
if (version == SnmpConstants.version1) {
Review Comment:
Unfortunately this integration test fails because the order in which the
OIDs are added to the request and hence the order in which they are in the
response is not deterministic.
I suggest changing lines 253-261 to this:
```java
final List<SNMPValue> actualVariableBindings =
response.getVariableBindings();
final List<SNMPValue> expectedVariableBindings;
final List<Function<SNMPValue, Object>> equalsProperties =
Arrays.asList(
SNMPValue::getOid,
SNMPValue::getVariable
);
if (version == SnmpConstants.version1) {
expectedVariableBindings = 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 {
expectedVariableBindings = 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))
);
```
--
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]