use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class WmiManagerTest method testCloseWithInvalidSession.
/**
* Test an attempt to close the client before the client has been
* initialized. This should throw a new exception stating that WmiClient
* hasn't been properly initialized.
*
* Test method for {@link org.opennms.protocols.wmi.WmiManager#close()}.
*
* @throws WmiException if there is a problem with the mock object.
*/
public final void testCloseWithInvalidSession() throws WmiException {
// Set up WMI mock client.
replay(m_WmiMock);
try {
// Create a manager.
WmiManager wmiManager = new WmiManager("127.0.0.1", "Administrator", "password");
// Disconnect without initializing/connecting.
wmiManager.close();
} catch (WmiException e) {
assertTrue("Exception missing message: WmiClient was not initialized: " + e, e.getMessage().contains("WmiClient was not initialized"));
}
verify(m_WmiMock);
reset(m_WmiMock);
}
use of org.opennms.protocols.wmi.WmiException in project opennms by OpenNMS.
the class WmiManagerTest method testPerformOpInvalidClass.
/**
* Test the performOp method with an invalid 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 testPerformOpInvalidClass() throws WmiException {
// Create parameter holder.
WmiParams params = new WmiParams(WmiParams.WMI_OPERATION_INSTANCEOF, "2/12/2004 00:00:00", "EQ", "Win32_BISO", "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.
m_WmiMock.connect("127.0.0.1", "Administrator", "password", WmiParams.WMI_DEFAULT_NAMESPACE);
m_WmiMock.performInstanceOf("Win32_BISO");
expectLastCall().andThrow(new WmiException("Failed to perform WMI operation: Exception occurred. [0x80020009] ==> Message from Server: SWbemServicesEx Invalid class"));
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.
wmiManager.performOp(params);
} catch (WmiException e) {
assertTrue("Exception missing message: SWbemServicesEx Invalid class: " + e, e.getMessage().contains("SWbemServicesEx Invalid class"));
}
verify(m_WmiMock);
reset(m_WmiMock);
}
Aggregations