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 */
}
}
}
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 */
}
}
}
Aggregations