+

Search Tips | Advanced Search

Writing your own tests: Sample 3

The following source code is an example of a test that shows an asynchronous approach to requesting data and processing data.

/*                                                    
 * Licensed Materials - Property of IBM
 *  
 * 5724-H72, 5655-L82, 5724-L26, 5655R3600
 * 
 * (c) Copyright IBM Corp. 2005, 2020
 * 
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */
package com.ibm.mq.explorer.tests.sample;

/**
 * Pseudo-code sample demonstrating an asynchronous approach to implementing a
 * Test. 
 */
public class QueuesTest extends WMQTest implements SomeListener {

    /** Used to store test results. */
    private ArrayList testresults = new ArrayList();

    /**
     * Used to start the test.
     * <p>
     * @param callback      handle to the test engine running the test
     * @param guimonitor    a handle to the object monitoring the test, 
     *                          provided to allow the test to periodically check
     *                          if the user has tried to cancel the test running    
     */
    public void runTest(WMQTestEngine callback, IProgressMonitor guimonitor, MQExtObject[] contextObjects, TreeNode  treenodeId) {

        super.runTest(callback, guimonitor, contextObjects, treenodeId);

        // reset all test stores
        testresults = new ArrayList();

        // initialise the progress bar part of the GUI used to show progress of
        //  this test
        guimonitor.beginTask(getTestName(), numqmgrs);

        // start the test!

        // send query
        PseudoQueueManager qmgrHandle = pseudoGetQueueManager();
        submitQmgrQuery(qmgrHandle, this, query);
        
        // note that the runTest method is now finished, but the test is not over!                
    }


    /**
     * Used to process results received in response to the query submitted by
     * runTest.
     * <p>
     * @param objects          data received 
     */
    public void dataReponseReceived(ArrayList objects) {

        // analyse each of the replies in the collection received in the reply
        for ( int i = 0; i < objects.size(); i++ ) {
            PseudoQueue nxtQueue = (PseudoQueue) objects.get(i);
            analyseQueue(nxtQueue);

            // increment GUI progress bar used to show progress of this test
            getGUIMonitor().worked(1);
        }

        // return the completed results
        WMQTestResult[] finalresults = (WMQTestResult[]) testresults.toArray(new WMQTestResult[0]);
        testComplete(finalresults);
    }



    /**
     * Analyse the given queue. If any potential problems are found, a problem 
     * marker is added to the testresults collection.
     * <p>
     * @param queue       queue to analyse
     */
    private void analyseQueue(PseudoQueue queue) {

        // do something

        // add a problem marker to the collection
        if (problemFound) {
            testresults.add(new WMQTestResult(IMarker.SEVERITY_WARNING,
                                              "A problem was found with " 
                                                + queueName,
                                              getQueueManagerName(queue),
                                              getTestSubCategory()));
        }
    }    
}
Parent topic: Adding new tests

Last updated: 2020-10-04