LSPS documentation logo
LSPS Documentation
Tests

The LSPS Application contains the testing project with sample JUnit tests.

The API is provided by the packages in com.whitestein.lsps.test.

The API for web tests (clicker GUI tests) is provided in the com.whitestein.lsps.test.web packages

Important: To use the API of com.whitestein.lsps.test.web, purchase the Vaadin TestBench license.

For detailed documentation, refer to the Javadoc documentation in the documentation/apidocs directory in PDS or the Javadoc online documentation.

JUnit Tests

The LSPS Application provides API for testing of modules as well as for clicker tests of the GUI and forms, both ui and forms.

Creating JUnit Tests for Modules

The generated LSPS Application comes with example JUnit tests SampleModelIT.java, with a test class that uploads a model, creates its instance and evaluates an expression in the context of the model instance

To create your own JUnit test, do the following:

  1. Open the workspace with the source of the application.
  2. In the generated LSPS Application, adjust the JUnit testing resources if applicable:
    • test.properties: relative path to the tested model and to the Standard Library Modules (Standard Library resources are dependencies of the LSPS test classes)
    • pom.xml: Maven POM file with dependencies

      Since the tests need a running LSPS Server, Maven compilation does not run the tests by default. The pom.xml file therefore defines the lsps.tester parameter, which allows you to run the JUnit tests on compilation:

      mvn clean install -Dlsps.tester
  3. Modify or create a new testing class in the src/test/java:
    • To establish and manage the connection to the LSPS Server, use the LspsRemote methods.
    • The testing classes are JUnit 4 tests and hence require annotations, such as @Before. You can access only the model context: Data from child contexts, such as Sub-Process variables, are not available.
public class MyTestsIT {
 
  private LspsRemote remote;
  private String moduleName;
  private File moduleFile;
  private Module module;
 
  @Before
  public void lspsRemote() {
    remote = LspsRemote.ADMIN; //create("admin", "admin", "http://localhost:8080");
    moduleName = "myTestModule";
    moduleFile = new File("src/modules").getAbsoluteFile();
 
    //Since uploadModule is an expensive operation,
    //we check if the module are uploaded already before upload:
    ModuleCriteria criteria = new ModuleCriteria();
    criteria.setNamePattern(moduleName);
    if (remote.findModules(criteria).isEmpty()) {
      remote.unloadAllModules();
      module = remote.uploadModule(moduleName, "1.0", moduleFile);
    } else {
      module = remote.getLatestModule(moduleName);
    }
  }
 
  @Test
  public void myTestNoUI() throws Exception {
    ModelInstance mi = module.startModelInstance();
    String logMessage = mi.getLogs().get(0).getDescription();
    assertTrue(logMessage.equals("My message"));
  }
}

Testing Record Values in JUnit Tests

When testing record values, consider returning preferably value of simple types from tested expressions.

Instead of

String patientName = (String) modelInstance.execute(getJohnDoe().name).toObject();
assertEquals("John", patientName);
String patientSurname = (String) modelInstance.execute(getJohnDoe().surname).toObject();

move the logic to the expression:

Boolean arePatientDetailsCorrect = (Boolean) modelInstance.execute(
    "def Patient john := getJohnDoe(); john.name==\"John" and john.surname=="Doe"").toObject();
)
assertEquals(true, arePatientDetailsCorrect)

Alternatively, you can store the returned object as RecordValue:

RecordValue rec = (RecordValue) modelInstance.execute("getMyRecordById(1)").toObject();

Creating JUnit Tests for GUI and Forms

The generated LSPS Application comes with example JUnit tests for both implementations of forms in the tester project:

  • SampleUIIT.java: a sample test class that tests the UI form
  • SampleFormsIT.java: a sample test class that test the Forms forms

Before creating and running your clicker tests to test the GUI and forms in the LSPS Process Application, do the following:

  • Purchase the Vaadin TestBench license and copy the license to your home directory (on Windows to c:\Users\<USERNAME>\).
  • Enable the modeling IDs so you can identify form components by their modeling ID on runtime: run the LSPS Server with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.

    To add the property to the SDK Embedded Server, in the Java perspective of PDS, go to Run > Run Configurations; select the configuration under Java Application and add the property on the Arguments tab to Program Arguments).

To create your own JUnit test, do the following:

  1. Download the ChromeDriver for your OS.
  2. Copy the extracted chrome driver to <YOUR_APP>/tester.
    chromedriverinexplorer.png
    Alternatively, run your server with the testbench_chromedriver property with the path to the ChromeDriver.
  3. Modify (SampleUIIT or SampleFormsIT) or create a testing class in the src/test/java.
  4. Modify or create a UIDefaultAppTester member that will govern the browser: with the ChromeDriver.
    //setting chrome driver for JUnit tests:
    protected UIDefaultAppTester app = new UIDefaultAppTester(SetupUtils.createChromeDriver(), VAADIN_APP_CONTEXT_ROOT);
    //setting firefox driver for JUnit tests:
    //protected UIDefaultAppTester app = new UIDefaultAppTester(SetupUtils.createFirefoxDriver(), VAADIN_APP_CONTEXT_ROOT);
    When testing in Firefox, make sure to use Firefox Portable. not newer than version 46 (released in 2016) and run your server with the testbench_firefox property set to the path to your Firefox, for example, -Dtestbench_firefox="C:\Users\John\Firefox_46\"
    • To establish and manage the connection to the LSPS Server, use the LspsRemote methods.
    • The testing classes are JUnit 4 tests and hence require annotations, such as @Before.

Searching for Form Components in JUnit Tests

To get a form component, use of the following methods on the application tester (IUDefaultAppTester) to search in the entire form tree or on a component to search in the component subtree:

  • findByLspsId() with the ID of the component you set in the ID property
  • findByFormId() with the modeling ID of the component
  • findById() with the HTML ID of the component: This is identical to the modeling id assuming the component is rendered only once.

Mind that the methods return a UIComponent object: to cast it to a component type, call the as() method; for example, app.findByLspsId("my_vl").as().verticalLayout();

Testing a Forms::Reusable Form in JUnit Tests

To work with the content inserted by a reusable form component, get the root of the tree with the findByFormId() method on the application helper class.

  @Test
  public void findFormComponentByID() {
 
    remote().uploadModule("module", "1.0", PATH_TO_MODEL);
 
    app.loginAndWait("admin", "admin");
    app.openDocument("My Document");
 
    //passing the modeling id of the Reusable Form component
    //defined in the calling form:
    assertNotNull(app.findByFormId("child__PrCxYARREemLruQ6nAkFiw"));
 
  }

Running JUnit Tests

If you plan to run the tests on a remote server, edit the JVM parameters:

  1. Go to Run > Run Configurations
  2. Double-click JUnit and create your configuration for the target JUnit class with the JVM arguments -Dselenium.host=<SERVER_IP> and -Dselenium.port=<SERVER_PORT>. Make sure you enabled the modeling IDs, that is, your server is running with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.

To run JUnit tests of a model, do the following:

  1. If you have modified the pom.xml file or provided paths to custom libraries in test.properties, open a terminal/command line and go to the location of the test project:
    1. Synchronize maven and eclipse: run mvn eclipse:eclipse
    2. Re-build the maven artifact to acquire the dependencies: run mvn clean install.
  2. Refresh the GO-BPMN Explorer.
  3. Run or connect PDS to your LSPS Server (typically, you will run the SDK Embedded Server with your application using the launcher).
  4. Run the test:
    • In PDS, right-click the tester project or the Java test class, then Run As > JUnit Test.

      Alternatively, on the command line, go to the location of the application tester project and run mvn clean install -Dlsps.tester.

    • To run the tests on other than the localhost server with port 8080, edit the JVM parameters:
      1. Go to Run > Run Configurations
      2. Double-click JUnit and create your configuration for the target JUnit class with the JVM arguments -Dselenium.host=<SERVER_IP> and -Dselenium.port=<SERVER_PORT>. Make sure you enabled the modeling IDs, that is, your server is running with the -Dcom.whitestein.lsps.vaadin.ui.debug=true property.