Search in sources :

Example 16 with WmiException

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);
}
Also used : WmiException(org.opennms.protocols.wmi.WmiException) WmiManager(org.opennms.protocols.wmi.WmiManager)

Example 17 with WmiException

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);
}
Also used : WmiParams(org.opennms.protocols.wmi.WmiParams) WmiException(org.opennms.protocols.wmi.WmiException) WmiManager(org.opennms.protocols.wmi.WmiManager)

Aggregations

WmiException (org.opennms.protocols.wmi.WmiException)17 WmiManager (org.opennms.protocols.wmi.WmiManager)9 JIException (org.jinterop.dcom.common.JIException)7 IJIComObject (org.jinterop.dcom.core.IJIComObject)7 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)7 WmiParams (org.opennms.protocols.wmi.WmiParams)5 JIArray (org.jinterop.dcom.core.JIArray)4 IJIEnumVariant (org.jinterop.dcom.impls.automation.IJIEnumVariant)4 WmiResult (org.opennms.protocols.wmi.WmiResult)3 OnmsWbemObjectSet (org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet)3 WmiAgentConfig (org.opennms.netmgt.config.wmi.WmiAgentConfig)2 OnmsWbemObjectBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub)2 OnmsWbemObjectSetBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectSetBiosStub)2 OnmsWbemPropBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemPropBiosStub)2 OnmsWbemPropSetBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemPropSetBiosStub)2 OnmsWbemObject (org.opennms.protocols.wmi.wbem.OnmsWbemObject)2 OnmsWbemProperty (org.opennms.protocols.wmi.wbem.OnmsWbemProperty)2 InetAddress (java.net.InetAddress)1 JIVariant (org.jinterop.dcom.core.JIVariant)1 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)1