Search in sources :

Example 16 with SnmpValueFactory

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

the class SnmpValueTest method testNullTerminatedASCIIString.

@Test
public void testNullTerminatedASCIIString() {
    for (final SnmpValueFactory factory : m_factories) {
        final String hex = "49206c696b65206368656573652100";
        final String expectedText = "I like cheese!.";
        final byte[] rawBytes = { (byte) 0x49, (byte) 0x20, (byte) 0x6c, (byte) 0x69, (byte) 0x6b, (byte) 0x65, (byte) 0x20, (byte) 0x63, (byte) 0x68, (byte) 0x65, (byte) 0x65, (byte) 0x73, (byte) 0x65, (byte) 0x21, (byte) 0x00 };
        final String className = factory.getClass().getName();
        final SnmpValue value = factory.getOctetString(rawBytes);
        assertArrayEquals(className + ": getOctetString bytes should match", rawBytes, value.getBytes());
        assertTrue(className + ": getOctetString displayable should be true", value.isDisplayable());
        assertEquals(className + ": getOctetString to String should return " + expectedText, expectedText, value.toString());
        assertEquals(className + ": getOctetString to DisplayString should return " + expectedText, expectedText, value.toDisplayString());
        assertEquals(className + ": getOctetString to HexString should return " + hex, hex, 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 17 with SnmpValueFactory

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

the class SnmpValueTest method testNormalString.

@Test
public void testNormalString() {
    for (final SnmpValueFactory factory : m_factories) {
        final String text = "I like cheese!";
        final String hex = "49206c696b652063686565736521";
        final byte[] rawBytes = text.getBytes();
        final String className = factory.getClass().getName();
        final SnmpValue value = factory.getOctetString(rawBytes);
        assertArrayEquals(className + ": getOctetString bytes should match", rawBytes, value.getBytes());
        assertTrue(className + ": getOctetString displayable should be true", value.isDisplayable());
        assertEquals(className + ": getOctetString to String should return " + text, text, value.toString());
        assertEquals(className + ": getOctetString to DisplayString should return " + text, text, value.toDisplayString());
        assertEquals(className + ": getOctetString to HexString should return " + hex, hex, 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 18 with SnmpValueFactory

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

the class SnmpValueTest method testOtherAddressOctetString.

@Test
public void testOtherAddressOctetString() {
    for (final SnmpValueFactory factory : m_factories) {
        final String hexString = "abcd";
        final byte[] rawBytes = { (byte) 0xab, (byte) 0xcd };
        final String stringBytes = new String(rawBytes);
        final String className = factory.getClass().getName();
        final SnmpValue value = factory.getOctetString(rawBytes);
        assertArrayEquals(className + ": getOctetString bytes should match", rawBytes, value.getBytes());
        assertTrue(className + ": getOctetString displayable should be true", 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 19 with SnmpValueFactory

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

the class SnmpValueTest method testGauge32.

@Test
public void testGauge32() {
    for (final SnmpValueFactory factory : m_factories) {
        final String methodName = "Gauge32";
        final String stringResult = "42";
        final Long numberResult = 42L;
        final SnmpValue value = factory.getGauge32(numberResult);
        final String className = factory.getClass().getName();
        doNumericCheck(className, methodName, value, stringResult, numberResult);
    }
}
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 20 with SnmpValueFactory

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

the class SnmpValueTest method testInt32.

@Test
public void testInt32() {
    for (final SnmpValueFactory factory : m_factories) {
        final String methodName = "Int32";
        final String stringResult = "42";
        final Long numberResult = 42L;
        final SnmpValue value = factory.getInt32(numberResult.intValue());
        final String className = factory.getClass().getName();
        doNumericCheck(className, methodName, value, stringResult, numberResult);
    }
}
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)

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