Search in sources :

Example 26 with MockResourceType

use of org.opennms.netmgt.mock.MockResourceType 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)

Example 27 with MockResourceType

use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisit.

public void testVisit() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    attributes.put(new MockAttribute("foo"), 0.0);
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 28 with MockResourceType

use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsSameValue.

public void testVisitGetResultsSameValue() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 5; i++) {
        attributes.put(new MockAttribute("foo"), 0.0);
    }
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 5, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 0.0, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 29 with MockResourceType

use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsDifferentValues.

public void testVisitGetResultsDifferentValues() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 5; i++) {
        attributes.put(new MockAttribute("foo"), 0.0 + i);
    }
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 5, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 4.0 - i, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 30 with MockResourceType

use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitGetResults.

public void testVisitGetResults() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    attributes.put(new MockAttribute("foo"), 0.0);
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 1, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 0.0, stat.getStatistic());
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

MockResourceType (org.opennms.netmgt.mock.MockResourceType)31 OnmsResource (org.opennms.netmgt.model.OnmsResource)31 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)30 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)16 HashSet (java.util.HashSet)13 ResourcePath (org.opennms.netmgt.model.ResourcePath)9 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)6 HashMap (java.util.HashMap)5 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)5 Source (org.opennms.netmgt.measurements.model.Source)5 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)4 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)4 Test (org.junit.Test)3 TreeMap (java.util.TreeMap)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 StringPropertyAttribute (org.opennms.netmgt.model.StringPropertyAttribute)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 RrdDb (org.jrobin.core.RrdDb)1 RrdDef (org.jrobin.core.RrdDef)1