Search in sources :

Example 1 with SnmpValueFactory

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

the class SnmpValueTest method testInetAddress.

@Test
public void testInetAddress() {
    for (final SnmpValueFactory factory : m_factories) {
        final InetAddress address = InetAddressUtils.addr("192.168.0.1");
        final SnmpValue value = factory.getIpAddress(address);
        final String className = factory.getClass().getName();
        assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
        assertEquals(className + ": getInetAddress to InetAddress should return 192.168.0.1", address, value.toInetAddress());
        assertEquals(className + ": getInetAddress to String should return 192.168.0.1", "192.168.0.1", value.toString());
        assertEquals(className + ": getInetAddress to DisplayString should return 192.168.0.1", "192.168.0.1", value.toDisplayString());
        try {
            value.toInt();
            fail(className + ": getInetAddress to int should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toLong();
            fail(className + ": getInetAddress to long should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toBigInteger();
            fail(className + ": getInetAddress to BigInteger should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toHexString();
            fail(className + ": getInetAddress to HexString should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toSnmpObjId();
            fail(className + ": getInetAddress 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) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with SnmpValueFactory

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

the class SnmpValueTest method testNull.

@Test
public void testNull() {
    for (final SnmpValueFactory factory : m_factories) {
        final SnmpValue value = factory.getNull();
        final String factoryClassName = factory.getClass().getName();
        assertFalse(factoryClassName + ": Null isDisplayable should be false", value.isDisplayable());
        assertTrue(factoryClassName + ": Null isNull should be true", value.isNull());
        assertFalse(factoryClassName + ": Null isEndOfMib should be false", value.isEndOfMib());
        assertFalse(factoryClassName + ": Null isError should be false", value.isError());
    }
}
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 3 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory 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 4 with SnmpValueFactory

use of org.opennms.netmgt.snmp.SnmpValueFactory 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 5 with SnmpValueFactory

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

the class SnmpValueTest method testSnmpObjId.

@Test
public void testSnmpObjId() {
    for (final SnmpValueFactory factory : m_factories) {
        final String oid = ".1.3.6.1.4.1.2925.4.5.2.1.1";
        final SnmpObjId id = SnmpObjId.get(oid);
        final SnmpValue value = factory.getObjectId(id);
        final String className = factory.getClass().getName();
        assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
        assertEquals(className + ": getObjectId to SnmpObjId should return " + oid, id, value.toSnmpObjId());
        assertEquals(className + ": getObjectId to String should return " + oid, oid, value.toString());
        assertEquals(className + ": getObjectId to DisplayString should return " + oid, oid, value.toDisplayString());
        try {
            value.toInt();
            fail(className + ": getObjectId to int should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toLong();
            fail(className + ": getObjectId to long should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toBigInteger();
            fail(className + ": getObjectId to BigInteger should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toHexString();
            fail(className + ": getObjectId to HexString should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toInetAddress();
            fail(className + ": getObjectId to InetAddress 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) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Aggregations

SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)25 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)24 Test (org.junit.Test)23 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 Parm (org.opennms.netmgt.xml.event.Parm)7 LinkedHashMap (java.util.LinkedHashMap)5 DirtiesContext (org.springframework.test.annotation.DirtiesContext)5 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)2 Event (org.opennms.netmgt.xml.event.Event)2 InetAddress (java.net.InetAddress)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Robin (org.jrobin.core.Robin)1 RrdDb (org.jrobin.core.RrdDb)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)1 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)1 MockSnmpValueFactory (org.opennms.netmgt.snmp.mock.MockSnmpValueFactory)1