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