Search in sources :

Example 1 with OnmsWbemObjectBiosStub

use of org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub 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);
}
Also used : OnmsWbemObjectSetBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectSetBiosStub) OnmsWbemPropBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemPropBiosStub) OnmsWbemObjectBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub) WmiParams(org.opennms.protocols.wmi.WmiParams) OnmsWbemPropSetBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemPropSetBiosStub) OnmsWbemObjectSet(org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet) WmiException(org.opennms.protocols.wmi.WmiException) WmiManager(org.opennms.protocols.wmi.WmiManager)

Example 2 with OnmsWbemObjectBiosStub

use of org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub in project opennms by OpenNMS.

the class WmiManagerTest method testPerformOpInvalidObject.

/**
 * Test the performOp method with an valid WMI class and invalid 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 testPerformOpInvalidObject() throws WmiException {
    // 
    // Create parameter holder.
    WmiParams params = new WmiParams(WmiParams.WMI_OPERATION_INSTANCEOF, "2/12/2004 00:00:00", "EQ", "Win32_BIOS", "RelDate");
    // 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.
        wmiManager.performOp(params);
    } catch (WmiException e) {
        assertTrue("Exception missing message: Unknown name: " + e, e.getMessage().contains("Unknown name"));
    }
    verify(m_WmiMock);
    reset(m_WmiMock);
}
Also used : OnmsWbemObjectSetBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectSetBiosStub) OnmsWbemPropBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemPropBiosStub) OnmsWbemObjectBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub) WmiParams(org.opennms.protocols.wmi.WmiParams) OnmsWbemPropSetBiosStub(org.opennms.protocols.wmi.test.stubs.OnmsWbemPropSetBiosStub) OnmsWbemObjectSet(org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet) WmiException(org.opennms.protocols.wmi.WmiException) WmiManager(org.opennms.protocols.wmi.WmiManager)

Aggregations

WmiException (org.opennms.protocols.wmi.WmiException)2 WmiManager (org.opennms.protocols.wmi.WmiManager)2 WmiParams (org.opennms.protocols.wmi.WmiParams)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 OnmsWbemObjectSet (org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet)2