Search in sources :

Example 11 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpValueTest method testTimeTicks.

@Test
public void testTimeTicks() {
    for (final SnmpValueFactory factory : m_factories) {
        final String className = factory.getClass().getName();
        final SnmpValue[] values = { factory.getTimeTicks(42) };
        for (final SnmpValue value : values) {
            assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
            assertEquals(className + ": getTimeTicks to int should return " + value.toInt(), 42, value.toInt());
            assertEquals(className + ": getTimeTicks to long should return " + value.toLong(), 42, value.toLong());
            assertEquals(className + ": getTimeTicks to BigInteger should return " + value.toBigInteger(), BigInteger.valueOf(42), value.toBigInteger());
            assertEquals(className + ": getTimeTicks to String should return 42", "42", value.toString());
            assertEquals(className + ": getTimeTicks to DisplayString should return 42", "42", value.toDisplayString());
            try {
                value.toHexString();
                fail(className + ": getTimeTicks to HexString should throw an IllegalArgumentException");
            } catch (final IllegalArgumentException e) {
            /* expected */
            }
            try {
                value.toInetAddress();
                fail(className + ": getTimeTicks to InetAddress should throw an IllegalArgumentException");
            } catch (final IllegalArgumentException e) {
            /* expected */
            }
            try {
                value.toSnmpObjId();
                fail(className + ": getTimeTicks to SnmpObjId should throw an IllegalArgumentException");
            } catch (final IllegalArgumentException e) {
            /* expected */
            }
        }
    }
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) JoeSnmpValueFactory(org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 12 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SnmpValueTest method testMacAddressOctetString.

@Test
public void testMacAddressOctetString() {
    for (final SnmpValueFactory factory : m_factories) {
        final String hexString = "005056e7a72f";
        final byte[] rawBytes = { 0, (byte) 0x50, (byte) 0x56, (byte) 0xe7, (byte) 0xa7, (byte) 0x2f };
        final String stringBytes = "." + new String(Arrays.copyOfRange(rawBytes, 1, rawBytes.length));
        final String className = factory.getClass().getName();
        final SnmpValue value = factory.getOctetString(rawBytes);
        assertArrayEquals(className + ": getOctetString bytes should match", rawBytes, value.getBytes());
        assertFalse(className + ": getOctetString displayable should be false", value.isDisplayable());
        assertEquals(className + ": getOctetString to String should return " + stringBytes, stringBytes, value.toString());
        assertEquals(className + ": getOctetString to DisplayString should return " + stringBytes, stringBytes, value.toDisplayString());
        assertEquals(className + ": getOctetString to HexString should return " + hexString, hexString, value.toHexString());
        try {
            value.toInt();
            fail(className + ": getOctetString to int should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toLong();
            fail(className + ": getOctetString to long should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toBigInteger();
            fail(className + ": getOctetString to BigInteger should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
    }
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) JoeSnmpValueFactory(org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 13 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class MockSnmpStrategyTest method testSetMultipleBadAgent.

@Test
public void testSetMultipleBadAgent() throws Exception {
    final SnmpAgentConfig sac = getAgentConfig();
    sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
    final SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
    final SnmpValue[] values = new SnmpValue[] { m_strategy.getValueFactory().getInt32(4), m_strategy.getValueFactory().getGauge32(5) };
    m_strategy.set(sac, oids, values);
    final SnmpValue[] results = m_strategy.get(sac, oids);
    assertNotNull(results);
    assertEquals(2, results.length);
    assertNull(results[0]);
    assertNull(results[1]);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Example 14 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class MockSnmpStrategyTest method testSetBadAgent.

@Test
public void testSetBadAgent() throws Exception {
    final SnmpAgentConfig sac = getAgentConfig();
    sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
    m_strategy.set(sac, SnmpObjId.get(".1.3.5.1.1.3.0"), m_strategy.getValueFactory().getInt32(4));
    final SnmpValue result = m_strategy.get(sac, SnmpObjId.get(".1.3.5.1.1.3.0"));
    assertNull(result);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Example 15 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TestAgent method getNextResponseVarBind.

TestVarBind getNextResponseVarBind(SnmpObjId lastOid, int errIndex) {
    try {
        SnmpObjId objId = getFollowingObjId(lastOid);
        SnmpValue value = getVarBindValue(objId, errIndex);
        return new TestVarBind(objId, value);
    } catch (AgentEndOfMibException e) {
        return handleEndOfMib(lastOid, errIndex);
    }
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)14 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4