Search in sources :

Example 41 with OnmsResource

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

the class RrdStatisticAttributeVisitorTest method testVisitWithNonRrdAttribute.

public void testVisitWithNonRrdAttribute() 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("something other than interfaceSnmp");
    OnmsAttribute attribute = new StringPropertyAttribute("ifInOctets", "one billion octets!");
    attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
    m_mocks.replayAll();
    attributeVisitor.visit(attribute);
    m_mocks.verifyAll();
}
Also used : StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 42 with OnmsResource

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

the class ResponseTimeResourceTypeTest method canGetResourcesForNode.

@Test
public void canGetResourcesForNode() throws IOException {
    expect(node.getIpInterfaces()).andReturn(ipInterfaces);
    expect(node.getLocation()).andReturn(null);
    expect(ipInterface.getIpAddress()).andReturn(InetAddress.getByName("127.0.0.1")).atLeastOnce();
    replay(node, ipInterface);
    NodeResourceType nodeResourceType = new NodeResourceType(resourceDao, nodeDao);
    OnmsResource nodeResource = new OnmsResource("1", "Node", nodeResourceType, Collections.emptySet(), ResourcePath.get("foo"));
    nodeResource.setEntity(node);
    List<OnmsResource> resources = responseTimeResourceType.getResourcesForParent(nodeResource);
    verify(node, ipInterface);
    assertEquals(1, resources.size());
    assertEquals("127.0.0.1", resources.get(0).getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) Test(org.junit.Test)

Example 43 with OnmsResource

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

the class ResponseTimeResourceTypeTest method canGetResourcesForNodeAtLocation.

@Test
public void canGetResourcesForNodeAtLocation() throws IOException {
    OnmsMonitoringLocation location = new OnmsMonitoringLocation();
    location.setLocationName(NON_DEFAULT_LOCATION_NAME);
    expect(node.getIpInterfaces()).andReturn(ipInterfaces);
    expect(node.getLocation()).andReturn(location).atLeastOnce();
    expect(ipInterface.getIpAddress()).andReturn(InetAddress.getByName("127.0.0.1")).atLeastOnce();
    replay(node, ipInterface);
    NodeResourceType nodeResourceType = new NodeResourceType(resourceDao, nodeDao);
    OnmsResource nodeResource = new OnmsResource("1", "Node", nodeResourceType, Collections.emptySet(), ResourcePath.get("foo"));
    nodeResource.setEntity(node);
    List<OnmsResource> resources = responseTimeResourceType.getResourcesForParent(nodeResource);
    verify(node, ipInterface);
    assertEquals(1, resources.size());
    assertEquals("127.0.0.1", resources.get(0).getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Test(org.junit.Test)

Example 44 with OnmsResource

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

the class RrdResourceAttributeUtilsTest method testLoadPropertiesEmpty.

@Test
public void testLoadPropertiesEmpty() throws Exception {
    OnmsResource childResource = createResource();
    createPropertiesFile(childResource, "", false);
    Properties p = RrdResourceAttributeUtils.getStringProperties(m_fileAnticipator.getTempDir(), "snmp/1/eth0");
    assertNotNull("properties should not be null", p);
    assertEquals("properties size", 0, p.size());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 45 with OnmsResource

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

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