Search in sources :

Example 1 with StorageStrategyService

use of org.opennms.netmgt.collection.api.StorageStrategyService in project opennms by OpenNMS.

the class FrameRelayStorageStrategyTest method testStrategy.

@Test
public void testStrategy() {
    // Create Mocks
    StorageStrategyService service = EasyMock.createMock(StorageStrategyService.class);
    // Valid source interface
    EasyMock.expect(service.getSnmpInterfaceLabel(1)).andReturn("Se0_0").anyTimes();
    // Invalid source interface
    EasyMock.expect(service.getSnmpInterfaceLabel(2)).andReturn(null).anyTimes();
    EasyMock.replay(service);
    // Create Strategy
    FrameRelayStorageStrategy strategy = new FrameRelayStorageStrategy();
    strategy.setResourceTypeName("frCircuitIfIndex");
    strategy.setStorageStrategyService(service);
    // Test InterfaceName
    ResourcePath parentResource = ResourcePath.get("1");
    Assert.assertEquals("Se0_0", strategy.getInterfaceName(parentResource.getName(), "1"));
    // Test InterfaceName (invalid source interface index);
    Assert.assertEquals("2", strategy.getInterfaceName(parentResource.getName(), "2"));
    // Test Resource Name
    MockCollectionResource resource = new MockCollectionResource(parentResource, "1.100", "frCircuitIfIndex");
    String resourceName = strategy.getResourceNameFromIndex(resource);
    Assert.assertEquals("Se0_0.100", resourceName);
    // Test Resource Name (invalid source interface index)
    resource.setInstance("2.100");
    Assert.assertEquals("2.100", strategy.getResourceNameFromIndex(resource));
    // Test RelativePath
    Assert.assertEquals(ResourcePath.get("1", "frCircuitIfIndex", "Se0_0.100"), strategy.getRelativePathForAttribute(parentResource, resourceName));
    EasyMock.verify(service);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) StorageStrategyService(org.opennms.netmgt.collection.api.StorageStrategyService) Test(org.junit.Test)

Example 2 with StorageStrategyService

use of org.opennms.netmgt.collection.api.StorageStrategyService in project opennms by OpenNMS.

the class HostFileSystemStorageStrategyTest method testStrategy.

@SuppressWarnings("deprecation")
@Test
public void testStrategy() throws Exception {
    // Create Mocks
    StorageStrategyService service = EasyMock.createMock(StorageStrategyService.class);
    SnmpAgentConfig agentConfig = new SnmpAgentConfig(InetAddressUtils.addr("127.0.0.1"));
    agentConfig.setPort(1161);
    EasyMock.expect(service.getAgentConfig()).andReturn(agentConfig).anyTimes();
    EasyMock.replay(service);
    // Create Strategy
    HostFileSystemStorageStrategy strategy = new HostFileSystemStorageStrategy();
    strategy.setResourceTypeName("hrStorageIndex");
    strategy.setStorageStrategyService(service);
    // Test Resource Name - root file system
    ResourcePath parentResource = ResourcePath.get("1");
    MockCollectionResource resource = new MockCollectionResource(parentResource, "1", "hrStorageIndex");
    resource.getAttributeMap().put("hrStorageDescr", "/");
    String resourceName = strategy.getResourceNameFromIndex(resource);
    Assert.assertEquals("_root_fs", resourceName);
    // Test Resource Name - root file system
    resource.setInstance("8");
    resource.getAttributeMap().put("hrStorageDescr", "Volumes-iDisk");
    Assert.assertEquals("Volumes-iDisk", strategy.getResourceNameFromIndex(resource));
    // Test RelativePath
    Assert.assertEquals(ResourcePath.get("1", "hrStorageIndex", "_root_fs"), strategy.getRelativePathForAttribute(parentResource, resourceName));
    EasyMock.verify(service);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) ResourcePath(org.opennms.netmgt.model.ResourcePath) StorageStrategyService(org.opennms.netmgt.collection.api.StorageStrategyService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 StorageStrategyService (org.opennms.netmgt.collection.api.StorageStrategyService)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1