Writing your own tests: Sample 4

The following source code is an example of a diagnostic tool. Use this code in place of real test code to write to the console the objects that will be accessed by the real test code.

/*
 * Licensed Materials - Property of IBM
 * 
 * 63H9336
 * (c) Copyright IBM Corp. 2005, 2020. All Rights Reserved.
 * 
 * disclosure restricted by GSA ADP Schedule Contract with
 * IBM Corp.
 */
package com.ibm.mq.explorer.tests.sample;

/**
 * List all the context objects provided to standard out
 */
public class WMQTestSimple extends WMQTest {
  
  /*
   * (non-Javadoc)
   * 
   * @see com.ibm.mq.explorer.tests.WMQTest#runTest(com.ibm.mq.explorer.tests.internal.actions.WMQTestEngine,
   * org.eclipse.core.runtime.IProgressMonitor, com.ibm.mq.explorer.ui.extensions.MQExtObject[],
   * java.lang.String)
   */  
   public void runTest(WMQTestEngine callback, IProgressMonitor guimonitor,
      MQExtObject[] contextObjects, TreeNode treenodeId) {

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

    // prepare space to store test results
    ArrayList testresults = new ArrayList();

    // Loop through all supplied MQExtObjects and output them to the console
    System.out.println("Objects supplied to this test:"); //$NON-NLS-1$
    for (int k = 0; k < contextObjects.length; k++) {
      if (contextObjects[k] != null) {
        System.out.println(contextObjects[k].getName());
      }
    }

    // Output the tree node ID to the console
    System.out.println("tree node ID supplied to this test: " + treenodeId); //$NON-NLS-1$

    // Add a test result
    testresults.add(new WMQTestResult(IMarker.SEVERITY_WARNING,
        "SAMPLE: Listing context completed", //$NON-NLS-1$
        "Object name", getTestSubCategory())); //$NON-NLS-1$

    // package up results and return - test complete.
    testComplete((WMQTestResult[]) testresults.toArray(new WMQTestResult[testresults.size()]));
  }
}
Parent topic: Adding new tests