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