Search in sources :

Example 16 with MockResourceType

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

the class RrdStatisticAttributeVisitorTest method testVisitWithNotANumberRrdAttribute.

public void testVisitWithNotANumberRrdAttribute() 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("somethingOtherThanInterfaceSnmp");
    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[] {}, Collections.singletonMap("result", new double[] {}), 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_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)

Example 17 with MockResourceType

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

the class RrdStatisticAttributeVisitorTest method testVisitTwice.

public void testVisitTwice() throws Exception {
    final RrdStatisticAttributeVisitor attributeVisitor1 = new RrdStatisticAttributeVisitor();
    attributeVisitor1.setFetchStrategy(m_fetchStrategy);
    attributeVisitor1.setConsolidationFunction("AVERAGE");
    attributeVisitor1.setStartTime(m_startTime);
    attributeVisitor1.setEndTime(m_endTime);
    attributeVisitor1.setStatisticVisitor(m_statisticVisitor);
    attributeVisitor1.afterPropertiesSet();
    final RrdStatisticAttributeVisitor attributeVisitor2 = new RrdStatisticAttributeVisitor();
    attributeVisitor2.setFetchStrategy(m_fetchStrategy);
    attributeVisitor2.setConsolidationFunction("AVERAGE");
    attributeVisitor2.setStartTime(m_startTime);
    attributeVisitor2.setEndTime(m_endTime);
    attributeVisitor2.setStatisticVisitor(m_statisticVisitor);
    attributeVisitor2.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(attributeVisitor1.getConsolidationFunction().toUpperCase());
    expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 1.0 }), m_endTime - m_startTime, Collections.emptyMap()));
    m_statisticVisitor.visit(attribute, 1.0);
    expect(m_fetchStrategy.fetch(m_startTime, m_endTime, 1, 0, null, null, Collections.singletonList(source), false)).andReturn(new FetchResults(new long[] { m_startTime }, Collections.singletonMap("result", new double[] { 2.0 }), m_endTime - m_startTime, Collections.emptyMap()));
    m_statisticVisitor.visit(attribute, 2.0);
    m_mocks.replayAll();
    attributeVisitor1.visit(attribute);
    attributeVisitor2.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)

Example 18 with MockResourceType

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

the class PropertiesGraphDaoIT method testGetPrefabGraphsForResourceWithSuppressUnused.

@Test
public void testGetPrefabGraphsForResourceWithSuppressUnused() {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interface");
    HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
    attributes.add(new RrdGraphAttribute("ifHCInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifHCOutOctets", "", ""));
    attributes.add(new ExternalValueAttribute("ifSpeed", ""));
    OnmsResource resource = new OnmsResource("node", "1", resourceType, attributes, ResourcePath.get("foo"));
    PrefabGraph[] graphs = m_dao.getPrefabGraphsForResource(resource);
    assertEquals("prefab graph array size", 1, graphs.length);
    assertEquals("prefab graph[0] name", "mib2.HCbits", graphs[0].getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with MockResourceType

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

the class ResourceTreeWalkerTest method testWalkTopLevel.

public void testWalkTopLevel() {
    ResourceTreeWalker walker = new ResourceTreeWalker();
    walker.setResourceDao(m_resourceDao);
    walker.setVisitor(m_visitor);
    m_mocks.replayAll();
    walker.afterPropertiesSet();
    m_mocks.verifyAll();
    MockResourceType resourceType = new MockResourceType();
    List<OnmsResource> resources = new ArrayList<OnmsResource>(2);
    resources.add(new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo")));
    resources.add(new OnmsResource("2", "Node Two", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo")));
    expect(m_resourceDao.findTopLevelResources()).andReturn(resources);
    for (OnmsResource resource : resources) {
        m_visitor.visit(resource);
    }
    m_mocks.replayAll();
    walker.walk();
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) ArrayList(java.util.ArrayList) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 20 with MockResourceType

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

the class ResourceTypeFilteringResourceVisitorTest method testVisitWithoutMatch.

public void testVisitWithoutMatch() throws Exception {
    ResourceTypeFilteringResourceVisitor filteringVisitor = new ResourceTypeFilteringResourceVisitor();
    filteringVisitor.setDelegatedVisitor(m_delegatedVisitor);
    filteringVisitor.setResourceTypeMatch("interfaceSnmp");
    filteringVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    m_mocks.replayAll();
    filteringVisitor.visit(resource);
    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)

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