use of org.opennms.netmgt.snmp.SnmpValueFactory in project opennms by OpenNMS.
the class TrapHandlerITCase method testV1TrapOIDWildCardMatch.
@Test
@DirtiesContext
public void testV1TrapOIDWildCardMatch() throws Exception {
SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
varbinds.put(".1.3.6.1.4.1.32473.42.42.42", valueFactory.getInt32(42));
anticipateAndSend(false, true, "uei.opennms.org/IANA/Example/traps/exampleEnterpriseTrap", "v1", ".1.3.6.1.4.1.32473.42", 6, 5, varbinds);
}
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 */
}
}
}
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());
}
}
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 */
}
}
}
}
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 */
}
}
}
Aggregations