SNMPImpl implements SnmpService, AutoCloseable { @Override public ListenableFuture<RpcResult<SnmpGetOutput>> snmpGet(SnmpGetInput input) { LOG.debug("Sending {} SNMP request for host: {}, OID: {}, Community: {}", input.getGetType(), input.getIpAddress(), input.getOid(), input.getCommunity()); AsyncGetHandler getHandler = new AsyncGetHandler(input, snmp); return getHandler.getRpcResponse(); } SNMPImpl();   SNMPImpl(Snmp snmp); @Override ListenableFuture<RpcResult<SnmpGetOutput>> snmpGet(SnmpGetInput input); @Override ListenableFuture<RpcResult<SnmpSetOutput>> snmpSet(SnmpSetInput input); @Override ListenableFuture<RpcResult<GetInterfacesOutput>> getInterfaces(final GetInterfacesInput getInterfacesInput); @Override void close(); @Override @SuppressWarnings("checkstyle:IllegalCatch") ListenableFuture<RpcResult<GetNodePropertiesOutput>> getNodeProperties(final GetNodePropertiesInput input);  }
@Test public void testGet() throws IOException, InterruptedException, ExecutionException { final ResponseEvent event = createResponseEvent(); doAnswer(invocation -> { ResponseListener callback = (ResponseListener) invocation.getArguments()[3]; callback.onResponse(event); return null; }).when(mockSnmp).send(argThat(pdu -> { assertEquals("Checking PDU Get type", pdu.getType(), PDU.GET); assertEquals("Checking PDU OID value", pdu.getVariableBindings().get(0).getOid().toString(), SYS_OID_REQUEST); assertEquals("Checking max repititions", pdu.getMaxRepetitions(), MAXREPETITIONS); return true; }), argThat(target -> { assertEquals(target.getSecurityName().toString(), COMMUNITY); assertEquals(target.getAddress().toString(), GET_IP_ADDRESS + "/" + SNMP_LISTEN_PORT.toString()); assertEquals(target.getTimeout(), TIMEOUT); assertEquals(target.getRetries(), RETRIES); assertEquals(target.getVersion(), SnmpConstants.version2c); return true; }), any(), (ResponseListener) any()); String value = "Failed"; String oid = "bad oid"; Ipv4Address ip = new Ipv4Address(GET_IP_ADDRESS); SnmpGetInputBuilder input = new SnmpGetInputBuilder(); input.setCommunity(COMMUNITY); input.setIpAddress(ip); input.setOid(SYS_OID_REQUEST); input.setGetType(SnmpGetType.GET); Future<RpcResult<SnmpGetOutput>> resultFuture = snmpImpl.snmpGet(input.build()); RpcResult<SnmpGetOutput> result = resultFuture.get(); if (result.isSuccessful()) { SnmpGetOutput output = result.getResult(); List<Results> snmpResults = output.getResults(); if (snmpResults.size() == 1) { for (Results r: snmpResults) { value = r.getValue(); oid = r.getOid(); break; } } } assertEquals(value, SYS_OID_RESPONSE); assertEquals(oid, SYS_OID_REQUEST); }