Search in sources :

Example 1 with JdbcDataCollectionConfigDao

use of org.opennms.netmgt.dao.JdbcDataCollectionConfigDao in project opennms by OpenNMS.

the class JdbcCollectorComplianceIT method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    JdbcDataCollection collection = new JdbcDataCollection();
    collection.setJdbcRrd(new JdbcRrd());
    JdbcDataCollectionConfigDao jdbcCollectionDao = mock(JdbcDataCollectionConfigDao.class, RETURNS_DEEP_STUBS);
    when(jdbcCollectionDao.getDataCollectionByName(COLLECTION)).thenReturn(collection);
    when(jdbcCollectionDao.getConfig().buildRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    return new ImmutableMap.Builder<String, Object>().put("jdbcDataCollectionConfigDao", jdbcCollectionDao).put("resourceTypesDao", resourceTypesDao).build();
}
Also used : JdbcDataCollectionConfigDao(org.opennms.netmgt.dao.JdbcDataCollectionConfigDao) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) JdbcDataCollection(org.opennms.netmgt.config.jdbc.JdbcDataCollection) JdbcRrd(org.opennms.netmgt.config.jdbc.JdbcRrd) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with JdbcDataCollectionConfigDao

use of org.opennms.netmgt.dao.JdbcDataCollectionConfigDao 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

JdbcDataCollectionConfigDao (org.opennms.netmgt.dao.JdbcDataCollectionConfigDao)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 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 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)1 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)1 JdbcDataCollection (org.opennms.netmgt.config.jdbc.JdbcDataCollection)1 JdbcDataCollectionConfig (org.opennms.netmgt.config.jdbc.JdbcDataCollectionConfig)1 JdbcRrd (org.opennms.netmgt.config.jdbc.JdbcRrd)1 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)1