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);
}
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());
}
}
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++;
}
}
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++;
}
}
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());
}
}
Aggregations