use of org.opennms.core.wsman.WSManClientFactory in project opennms by OpenNMS.
the class WSManMonitorTest method poll.
private static PollStatus poll(String rule, Node response) {
String resourceUri = "mock-resource-uri";
Map<String, String> selectors = Maps.newHashMap();
selectors.put("mock-selector-a", "a1");
selectors.put("mock-selector-b", "b1");
Definition agentConfig = new Definition();
WSManConfigDao configDao = mock(WSManConfigDao.class);
when(configDao.getAgentConfig(anyObject())).thenReturn(agentConfig);
WSManClient client = mock(WSManClient.class);
when(client.get(resourceUri, selectors)).thenReturn(response);
WSManClientFactory clientFactory = mock(WSManClientFactory.class);
when(clientFactory.getClient(anyObject())).thenReturn(client);
WsManMonitor monitor = new WsManMonitor();
monitor.setWSManConfigDao(configDao);
monitor.setWSManClientFactory(clientFactory);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put(WsManMonitor.RESOURCE_URI_PARAM, resourceUri);
selectors.entrySet().stream().forEach(e -> parameters.put(WsManMonitor.SELECTOR_PARAM_PREFIX + e.getKey(), e.getValue()));
parameters.put(WsManMonitor.RULE_PARAM, rule);
InetAddress localhost;
try {
localhost = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
MonitoredService svc = mock(MonitoredService.class);
when(svc.getAddress()).thenReturn(localhost);
return monitor.poll(svc, parameters);
}
Aggregations