Search in sources :

Example 76 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource 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)

Example 77 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource 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 78 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource 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 79 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource 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 80 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class ResponseTimeResourceTypeTest method canGetChildByName.

@Test
public void canGetChildByName() throws IOException {
    expect(ipInterfaceDao.get(node, "127.0.0.1")).andReturn(ipInterface);
    OnmsResource parent = createMock(OnmsResource.class);
    expect(parent.getEntity()).andReturn(node);
    replay(ipInterface, parent, ipInterfaceDao);
    OnmsResource resource = responseTimeResourceType.getChildByName(parent, "127.0.0.1");
    verify(ipInterface, parent, ipInterfaceDao);
    assertEquals("127.0.0.1", resource.getName());
    assertEquals(parent, resource.getParent());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) Test(org.junit.Test)

Aggregations

OnmsResource (org.opennms.netmgt.model.OnmsResource)143 Test (org.junit.Test)54 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)28 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)23 File (java.io.File)22 ResourcePath (org.opennms.netmgt.model.ResourcePath)19 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)14 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)12 HashMap (java.util.HashMap)11 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)11 ResourceId (org.opennms.netmgt.model.ResourceId)11 Date (java.util.Date)10 Source (org.opennms.netmgt.measurements.model.Source)8 LinkedList (java.util.LinkedList)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7