use of org.opennms.netmgt.snmp.SnmpObjId 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);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgent method getFollowingObjId.
public SnmpObjId getFollowingObjId(SnmpObjId id) {
try {
SnmpObjId nextObjId = m_agentData.tailMap(SnmpObjId.get(id, SnmpInstId.INST_ZERO)).firstKey();
Object value = m_agentData.get(nextObjId);
if (value instanceof Redirect) {
Redirect redirect = (Redirect) value;
return redirect.getTargetObjId();
}
return nextObjId;
} catch (NoSuchElementException e) {
throw new AgentEndOfMibException();
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgent method generateException.
private void generateException(SnmpObjId id) {
if (m_agentData.isEmpty()) {
throw new AgentNoSuchObjectException();
}
SnmpObjId firstOid = m_agentData.firstKey();
SnmpObjId lastOid = m_agentData.lastKey();
if (id.compareTo(firstOid) < 0 || id.compareTo(lastOid) > 0)
throw new AgentNoSuchObjectException();
throw new AgentNoSuchInstanceException();
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgent method setAgentData.
public void setAgentData(Properties mibData) {
MockSnmpValueFactory factory = new MockSnmpValueFactory();
m_agentData = new TreeMap<SnmpObjId, Object>();
for (Entry<Object, Object> entry : mibData.entrySet()) {
SnmpObjId objId = SnmpObjId.get(entry.getKey().toString());
setAgentValue(objId, factory.parseMibValue(entry.getValue().toString()));
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method testAgentValueFor.
public void testAgentValueFor() {
SnmpObjId z1 = SnmpObjId.get(zeroInst1Base, "0");
SnmpObjId z2 = SnmpObjId.get(zeroInst2Base, "0");
assertEquals(getValueFor(z1).toString(), m_agent.getValueFor(z1).toString());
assertEquals(getValueFor(z2).toString(), m_agent.getValueFor(z2).toString());
// make sure they are not the same
assertFalse(getValueFor(z2).equals(m_agent.getValueFor(z1)));
// try a column
for (int i = 1; i <= columnLength; i++) {
SnmpObjId colOid = SnmpObjId.get(col2Base, "" + i);
assertEquals(getValueFor(colOid).toString(), m_agent.getValueFor(colOid).toString());
}
// what should it do if you ask for an invalid one - return null
try {
m_agent.getValueFor(SnmpObjId.get(".1.1.1.1.1"));
fail("expected an exception");
} catch (AgentNoSuchObjectException e) {
}
SnmpObjId objId = SnmpObjId.get(zeroInst1Base, "1");
try {
m_agent.getValueFor(objId);
fail("Expected no such instance exception");
} catch (AgentNoSuchInstanceException e) {
}
RuntimeException exception = m_agent.introduceGenErr(objId);
try {
m_agent.getValueFor(objId);
} catch (RuntimeException e) {
assertSame(exception, e);
}
}
Aggregations