Search in sources :

Example 1 with JdbcDataCollectionConfig

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;
}
Also used : JdbcDataCollectionConfigDao(org.opennms.netmgt.dao.JdbcDataCollectionConfigDao) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) Matchers.anyObject(org.mockito.Matchers.anyObject) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) JdbcDataCollectionConfig(org.opennms.netmgt.config.jdbc.JdbcDataCollectionConfig) JdbcAgentState(org.opennms.netmgt.collectd.jdbc.JdbcAgentState) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

HashMap (java.util.HashMap)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 JdbcAgentState (org.opennms.netmgt.collectd.jdbc.JdbcAgentState)1 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)1 JdbcDataCollectionConfig (org.opennms.netmgt.config.jdbc.JdbcDataCollectionConfig)1 JdbcDataCollectionConfigDao (org.opennms.netmgt.dao.JdbcDataCollectionConfigDao)1