use of org.opennms.netmgt.config.jdbc.JdbcDataCollectionConfig in project opennms by OpenNMS.
the class JdbcCollectorTest method collect.
public CollectionSet collect(JdbcDataCollection collection, ResultSet resultSet, ResourceType... resourceTypes) throws Exception {
final int nodeId = 1;
JdbcDataCollectionConfig config = new JdbcDataCollectionConfig();
config.setRrdRepository(tempFolder.getRoot().getAbsolutePath());
JdbcDataCollectionConfigDao jdbcCollectionDao = mock(JdbcDataCollectionConfigDao.class);
when(jdbcCollectionDao.getConfig()).thenReturn(config);
when(jdbcCollectionDao.getDataCollectionByName(null)).thenReturn(collection);
ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> {
for (ResourceType resourceType : resourceTypes) {
if (resourceType.getName().equals(name)) {
return resourceType;
}
}
return null;
});
MyJdbcCollector jdbcCollector = new MyJdbcCollector();
jdbcCollector.setJdbcCollectionDao(jdbcCollectionDao);
jdbcCollector.initialize();
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getNodeId()).thenReturn(nodeId);
when(agent.getAddress()).thenReturn(InetAddressUtils.ONE_TWENTY_SEVEN);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get("snmp", Integer.toString(nodeId)));
JdbcAgentState jdbcAgentState = mock(JdbcAgentState.class);
when(jdbcAgentState.groupIsAvailable(any(String.class))).thenReturn(true);
when(jdbcAgentState.executeJdbcQuery(anyObject(), anyObject())).thenReturn(resultSet);
jdbcCollector.setJdbcAgentState(jdbcAgentState);
Map<String, Object> params = new HashMap<>();
params.putAll(jdbcCollector.getRuntimeAttributes(agent, params));
CollectionSet collectionSet = jdbcCollector.collect(agent, params);
return collectionSet;
}
Aggregations