Add a listener to the stop-button

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
Hello,

I have a test scenario at which I start a SOAP request and check the response via the Call Back Tool. Afterwards I start a Java method with the help of the method tool. This Java class checks another message queue for a correct further processing of my SOAP request. This is done by a repeated lookup at the queue at a regular interval (some while-loops and thread-sleeps).

If somehow I would like to stop my test, I push the stop-button at SOAtest. However, this stop-trigger is not forwarded to the method tool and does not interrupt the Java-process.

Is there a way to add a listener to the stop-button, so I can interrupt the queue lookup for myself? Alternatively, is there a flag that I can check on a regular basis determining whether the test is running or not?

Thanks in advance!
-ajh-
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Hi ajh,

    This can be done, but it requires some extra work in your Java class. First, you need to create a Java Runnable - then, attach it to the proper listener list.
    Here is a simple example .java file, which demonstrates how this is done. The tst file to run this example is trivial.

    CODE
    /*
    * This class file is a simple example of a method which can be called from a SOAtest
    * Method Tool, and can be interrupted by the stop button.
    */

    package com.parasoft.examples;

    import webtool.app.*;
    import com.parasoft.api.*;
    import com.parasoft.app.Lock;

    public class InterruptMethodExample {

    private boolean _stop = false;

    public void doSomeLongProcess(Object input, Context context) {
    WebtoolApp app = WebtoolApp.getWebtoolApp();
    Lock lock = app.getLock();
    if (lock != null) {
    lock.addInterruptAction(getInterruptAction());
    }

    while (true) {
    if (_stop) {
    break;
    }
    }
    }

    private Runnable getInterruptAction() {
    return new Runnable() {
    public void run() {
    _stop = true;
    }
    };
    }
    }


    This works by creating a Runnable, which sets a flag inside your class. You can then poll the flag to determine when to stop your loop. The Runnable is then passed to the Lock.addInterruptAction() function. Once this is done, your Runnable will be invoked if the stop button is clicked.
    Note that, to compile this source, you need to have the parasoft.jar and Webking.jar files included in your project setup.

    Also note that, although this has been tested with 5.5.3 and 6.1, I cannot guarantee that this will work for any other specific version.
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Works like a charme (using 5.5.3) - Thanks!

    -ajh-
Sign In or Register to comment.