use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.
the class ReportDefinitionTest method testUnfilteredResourceAttributeFilteringWithNoMatch.
public void testUnfilteredResourceAttributeFilteringWithNoMatch() throws Exception {
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
OnmsResource resource = new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
EasyMock.expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(resource));
ReportDefinition def = createReportDefinition();
def.setResourceAttributeKey("ifSpeed");
def.setResourceAttributeValueMatch("100000000");
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
m_mocks.replayAll();
report.walk();
assertEquals("results size", 0, report.getResults().size());
}
use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.
the class ReportDefinitionTest method testFilteredResourceAttributeFilteringWithNoMatch.
public void testFilteredResourceAttributeFilteringWithNoMatch() throws Exception {
final OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("Node One");
EasyMock.expect(m_nodeDao.load(1)).andReturn(node);
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
ReportDefinition def = createReportDefinition();
def.getReport().getPackage().setFilter("");
def.setResourceAttributeKey("ifSpeed");
def.setResourceAttributeValueMatch("100000000");
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
SortedMap<Integer, String> sortedNodeMap = new TreeMap<Integer, String>();
sortedNodeMap.put(node.getId(), node.getLabel());
EasyMock.expect(m_filterDao.getNodeMap("")).andReturn(sortedNodeMap);
EasyMock.expect(m_resourceDao.getResourceForNode(node)).andReturn(resource);
m_mocks.replayAll();
report.walk();
assertEquals("results size", 0, report.getResults().size());
}
use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.
the class ReportDefinitionTest method testFilteredResourceAttributeFilteringWithMatch.
public void testFilteredResourceAttributeFilteringWithMatch() throws Exception {
OnmsAttribute rrdAttribute = new RrdGraphAttribute("IfInOctets", "something", "something else");
ExternalValueAttribute externalValueAttribute = new ExternalValueAttribute("ifSpeed", "100000000");
Set<OnmsAttribute> attributes = new HashSet<>();
attributes.add(rrdAttribute);
attributes.add(externalValueAttribute);
final OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("Node One");
EasyMock.expect(m_nodeDao.load(1)).andReturn(node);
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsResource resource = new OnmsResource(node.getId().toString(), node.getLabel(), resourceType, attributes, ResourcePath.get("foo"));
ReportDefinition def = createReportDefinition();
def.getReport().getPackage().setFilter("");
def.setResourceAttributeKey(externalValueAttribute.getName());
def.setResourceAttributeValueMatch(externalValueAttribute.getValue());
ReportInstance report = def.createReport(m_nodeDao, m_resourceDao, m_fetchStrategy, m_filterDao);
SortedMap<Integer, String> sortedNodeMap = new TreeMap<Integer, String>();
sortedNodeMap.put(node.getId(), node.getLabel());
EasyMock.expect(m_filterDao.getNodeMap("")).andReturn(sortedNodeMap);
EasyMock.expect(m_resourceDao.getResourceForNode(node)).andReturn(resource);
Source source = new Source();
source.setLabel("result");
source.setResourceId(resource.getId().toString());
source.setAttribute(rrdAttribute.getName());
source.setAggregation("AVERAGE");
FetchResults results = new FetchResults(new long[] { report.getStartTime() }, Collections.singletonMap("result", new double[] { 100.0 }), report.getEndTime() - report.getStartTime(), Collections.emptyMap());
EasyMock.expect(m_fetchStrategy.fetch(report.getStartTime(), report.getEndTime(), 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_mocks.replayAll();
report.walk();
assertEquals("results size", 1, report.getResults().size());
}
use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.
the class ResourceTreeWalkerTest method testWalkChildren.
public void testWalkChildren() {
ResourceTreeWalker walker = new ResourceTreeWalker();
walker.setResourceDao(m_resourceDao);
walker.setVisitor(m_visitor);
m_mocks.replayAll();
walker.afterPropertiesSet();
m_mocks.verifyAll();
MockResourceType resourceType = new MockResourceType();
OnmsResource childResource = new OnmsResource("eth0", "Interface eth0", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
OnmsResource topResource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), Collections.singletonList(childResource), new ResourcePath("foo"));
expect(m_resourceDao.findTopLevelResources()).andReturn(Collections.singletonList(topResource));
m_visitor.visit(topResource);
m_visitor.visit(childResource);
m_mocks.replayAll();
walker.walk();
m_mocks.verifyAll();
}
use of org.opennms.netmgt.mock.MockResourceType in project opennms by OpenNMS.
the class RrdStatisticAttributeVisitorTest method testVisitWithRrdAttribute.
public void testVisitWithRrdAttribute() throws Exception {
RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
attributeVisitor.setFetchStrategy(m_fetchStrategy);
attributeVisitor.setConsolidationFunction("AVERAGE");
attributeVisitor.setStartTime(m_startTime);
attributeVisitor.setEndTime(m_endTime);
attributeVisitor.setStatisticVisitor(m_statisticVisitor);
attributeVisitor.afterPropertiesSet();
MockResourceType resourceType = new MockResourceType();
resourceType.setName("interfaceSnmp");
OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
Source source = new Source();
source.setLabel("result");
source.setResourceId(attribute.getResource().getId().toString());
source.setAttribute(attribute.getName());
source.setAggregation(attributeVisitor.getConsolidationFunction().toUpperCase());
FetchResults results = new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap());
expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(results);
m_statisticVisitor.visit(attribute, 1.0);
m_mocks.replayAll();
attributeVisitor.visit(attribute);
m_mocks.verifyAll();
}
Aggregations