use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class OnmsWbemObjectImpl method getWmiMethods.
/**
* <p>getWmiMethods</p>
*
* @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemMethodSet} object.
* @throws org.opennms.protocols.wmi.WmiException if any.
*/
@Override
public OnmsWbemMethodSet getWmiMethods() throws WmiException {
try {
// Get the WbemMethodSet dispatcher.
final IJIComObject methodComObject = wbemObjectDispatch.get("Methods_").getObjectAsComObject();
final IJIDispatch methodsSet_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(methodComObject);
return new OnmsWbemMethodSetImpl(methodsSet_dispatch);
} catch (final JIException e) {
throw new WmiException("Failed to retrieve list of methods: " + e.getMessage(), e);
}
}
use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class OnmsWbemPropertySetImpl method get.
/**
* {@inheritDoc}
*/
@Override
public OnmsWbemProperty get(final Integer idx) throws WmiException {
try {
final IJIComObject enumComObject = wbemPropertySetDispatch.get("_NewEnum").getObjectAsComObject();
final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
OnmsWbemProperty wbemObj;
IJIDispatch wbemProperty_dispatch = null;
for (int i = 0; i < (idx + 1); i++) {
final Object[] values = enumVariant.next(1);
final JIArray array = (JIArray) values[0];
final Object[] arrayObj = (Object[]) array.getArrayInstance();
for (int j = 0; j < arrayObj.length; j++) {
wbemProperty_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
}
}
wbemObj = new OnmsWbemPropertyImpl(wbemProperty_dispatch);
return wbemObj;
} catch (final JIException e) {
throw new WmiException("Failed to enumerate WbemProperty variant: " + e.getMessage(), e);
}
}
use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class WmiManagerTest method testPerformOpValidObject.
/**
* Test the performOp method with a valid WMI class and valid WMI object.
*
* Test method for
* {@link org.opennms.protocols.wmi.WmiManager#performOp(org.opennms.protocols.wmi.WmiParams)}.
*
* @throws WmiException if there is a problem with the mock object.
*/
public final void testPerformOpValidObject() throws WmiException {
//
// Create parameter holder.
WmiParams params = new WmiParams(WmiParams.WMI_OPERATION_INSTANCEOF, "2/12/2004 00:00:00", "EQ", "Win32_BIOS", "ReleaseDate");
// Set up WMI mock client.
// 1) Expect a call to connect() with a bad hostname.
// 2) Throw a new WmiException indictating a bad hostname.
OnmsWbemObjectSet wos = new OnmsWbemObjectSetBiosStub(new OnmsWbemObjectBiosStub(new OnmsWbemPropSetBiosStub(new OnmsWbemPropBiosStub())));
m_WmiMock.connect("127.0.0.1", "Administrator", "password", WmiParams.WMI_DEFAULT_NAMESPACE);
expect(m_WmiMock.performInstanceOf("Win32_BIOS")).andReturn(wos);
replay(m_WmiMock);
try {
// Create a manager.
WmiManager wmiManager = new WmiManager("127.0.0.1", "Administrator", "password");
// Initialize
wmiManager.init(m_WmiMock);
// Perform an operation.
// WmiResult res =
wmiManager.performOp(params);
// assertTrue(res)
} catch (WmiException e) {
// assertTrue("Exception missing message: Unknown name: " + e, e
// .getMessage().contains("Unknown name"));
}
verify(m_WmiMock);
reset(m_WmiMock);
}
use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class WmiManagerTest method testInitBadUserPass.
/**
* Test that the WMI manager handles invalid username or password exceptions
* properly from the WMI client.
*
* Test method for {@link org.opennms.protocols.wmi.WmiManager#init()}.
*
* @throws WmiException if there is a problem with the mock object.
*/
public final void testInitBadUserPass() throws WmiException {
// Set up WMI mock client.
// 1) Expect a call to connect() with a bad hostname.
// 2) Throw a new WmiException indictating a user or password.
m_WmiMock.connect("127.0.0.1", "Administrator", "wrongpassword", WmiParams.WMI_DEFAULT_NAMESPACE);
expectLastCall().andThrow(new WmiException("Failed to connect to host '127.0.0.1': The attempted logon is invalid. This is either due to a bad username or authentication information. [0xC000006D]"));
replay(m_WmiMock);
try {
// Create a manager.
WmiManager wmiManager = new WmiManager("127.0.0.1", "Administrator", "wrongpassword");
// Initialize
wmiManager.init(m_WmiMock);
} catch (WmiException e) {
assertTrue("Exception missing message: The attempted logon is invalid: " + e, e.getMessage().contains("The attempted logon is invalid"));
}
verify(m_WmiMock);
reset(m_WmiMock);
}
use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class WmiManagerTest method testInitBadHostname.
/**
* Test that the WMI manager properly handles invalid host exceptions
* from the WMI client.
*
* Test method for {@link org.opennms.protocols.wmi.WmiManager#init()}.
*
* @throws WmiException if there is a problem with the mock object.
*/
public final void testInitBadHostname() throws WmiException {
// Set up WMI mock client.
// 1) Expect a call to connect() with a bad hostname.
// 2) Throw a new WmiException indictating a bad hostname.
m_WmiMock.connect("bad-hostname", "Administrator", "password", WmiParams.WMI_DEFAULT_NAMESPACE);
expectLastCall().andThrow(new WmiException("Unknown host 'bad-hostname'. Failed to connect to WMI agent."));
replay(m_WmiMock);
try {
// Create a manager.
WmiManager wmiManager = new WmiManager("bad-hostname", "Administrator", "password");
// Initialize
wmiManager.init(m_WmiMock);
} catch (WmiException e) {
assertTrue("Exception missing message: Unknown host: " + e, e.getMessage().contains("Unknown host"));
}
verify(m_WmiMock);
reset(m_WmiMock);
}
Aggregations