Search in sources :

Example 51 with ResourcePath

use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.

the class DefaultRrdDaoTest method testFetchLastValue.

public void testFetchLastValue() throws Exception {
    String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
    String rrdFile = "ifInOctets.jrb";
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    int interval = 300000;
    Double expectedValue = new Double(1.0);
    String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
    expect(m_rrdStrategy.fetchLastValue(fullRrdFilePath, attribute.getName(), interval)).andReturn(expectedValue);
    m_mocks.replayAll();
    Double value = m_dao.getLastFetchValue(attribute, interval);
    m_mocks.verifyAll();
    assertNotNull("last fetched value must not be null, but was null", value);
    assertEquals("last fetched value", expectedValue, value);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Aggregations

ResourcePath (org.opennms.netmgt.model.ResourcePath)51 OnmsResource (org.opennms.netmgt.model.OnmsResource)19 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)14 MockResourceType (org.opennms.netmgt.mock.MockResourceType)9 Test (org.junit.Test)8 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)8 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Resource (org.opennms.newts.api.Resource)6 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 Sample (org.opennms.newts.api.Sample)5 IOException (java.io.IOException)3 List (java.util.List)3 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)3 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Timestamp (org.opennms.newts.api.Timestamp)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2