Search in sources :

Example 11 with MockResourceType

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());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 12 with MockResourceType

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) TreeMap(java.util.TreeMap) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 13 with MockResourceType

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) TreeMap(java.util.TreeMap) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) HashSet(java.util.HashSet) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 14 with MockResourceType

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();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 15 with MockResourceType

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();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) 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