Search in sources :

Example 1 with WSManClientFactory

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Definition(org.opennms.netmgt.config.wsman.Definition) WSManConfigDao(org.opennms.netmgt.dao.WSManConfigDao) WSManClientFactory(org.opennms.core.wsman.WSManClientFactory) Matchers.anyObject(org.mockito.Matchers.anyObject) WSManClient(org.opennms.core.wsman.WSManClient) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 WSManClient (org.opennms.core.wsman.WSManClient)1 WSManClientFactory (org.opennms.core.wsman.WSManClientFactory)1 Definition (org.opennms.netmgt.config.wsman.Definition)1 WSManConfigDao (org.opennms.netmgt.dao.WSManConfigDao)1 MonitoredService (org.opennms.netmgt.poller.MonitoredService)1