WebMethods Unit Test Framework Help - Version 10.5 October 2019 - Software AG ...

Page created by Judy Mendoza
 
CONTINUE READING
WebMethods Unit Test Framework Help - Version 10.5 October 2019 - Software AG ...
webMethods Unit Test Framework Help

                            Version 10.5

                           October 2019
This document applies to webMethods Test Suite 10.5 and to all subsequent releases.
Specifications contained herein are subject to change and these changes will be reported in subsequent release notes or new editions.
Copyright © 2017-2021 Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries
and/or its affiliates and/or their licensors.
The name Software AG and all Software AG product names are either trademarks or registered trademarks of Software AG and/or
Software AG USA Inc. and/or its subsidiaries and/or its affiliates and/or their licensors. Other company and product names mentioned
herein may be trademarks of their respective owners.
Detailed information on trademarks and patents owned by Software AG and/or its subsidiaries is located at
https://softwareag.com/licenses/.
Use of this software is subject to adherence to Software AG's licensing conditions and terms. These terms are part of the product
documentation, located at https://softwareag.com/licenses/ and/or in the root installation directory of the licensed product(s).
This software may include portions of third-party products. For third-party copyright notices, license terms, additional rights or
restrictions, please refer to "License Texts, Copyright Notices and Disclaimers of Third Party Products". For certain specific third-party
license restrictions, please refer to section E of the Legal Notices available under "License Terms and Conditions for Use of Software
AG Products / Copyright and Trademark Notices of Software AG Products". These documents are part of the product documentation,
located at https://softwareag.com/licenses/ and/or in the root installation directory of the licensed product(s).
Document ID: GWM-WWST-105-20210818
Table of Contents

About this Guide........................................................................................................................................5
   Document Conventions.....................................................................................................................6

1 Unit Test Framework..............................................................................................................................9
    Overview...........................................................................................................................................10
    Terms and Concepts.........................................................................................................................10
    Capabilities........................................................................................................................................13
    Server Definition...............................................................................................................................14
    Environment......................................................................................................................................14
    What it is not.....................................................................................................................................15

2 Working with Unit Test Framework..................................................................................................17
    Opening the Unit Test Framework Perspective...........................................................................18
    Layout................................................................................................................................................18
    Test Suite Preferences.......................................................................................................................19

3 Creating a Test Suite.............................................................................................................................23
     Before You Begin...............................................................................................................................24
     To Create a Test Suite.......................................................................................................................24
     Creating a Sample Test Suite...........................................................................................................24

4 Adding Test Cases.................................................................................................................................27
    Adding a Test Case...........................................................................................................................28
    Test Details.........................................................................................................................................28
    Service Details...................................................................................................................................28
    Inputs.................................................................................................................................................28
    Expected Output...............................................................................................................................29
    Output Comparison.........................................................................................................................29

5 Generating Tests....................................................................................................................................31
    Generating Tests Suites using Service Execution Results...........................................................32

6 Mocks......................................................................................................................................................35
   Using Mocks......................................................................................................................................36
   Sample Mock Factory.......................................................................................................................37
   Mocks beyond Unit Testing............................................................................................................38

7 Advanced Options................................................................................................................................39
    Pipeline Filter....................................................................................................................................40
    Comparators......................................................................................................................................40
    Client Mock Factory.........................................................................................................................40

webMethods Unit Test Framework Help 10.5                                                                                                                     iii
Table of Contents

       XPath Expressions............................................................................................................................41

8 Test Suite Internals...............................................................................................................................43
     Test Suite Internals...........................................................................................................................44

9 Java Unit Tests........................................................................................................................................45
     Java Unit Tests...................................................................................................................................46

10 Executing Tests.....................................................................................................................................49
     Executing Test Cases........................................................................................................................50
     Executing Test Suites........................................................................................................................50
     Debugging Java Code......................................................................................................................50
     Continuous Integration...................................................................................................................51

11 Code Coverage Analysis....................................................................................................................55
    Running a Coverage Analysis........................................................................................................56
    Viewing Code Coverage Analysis.................................................................................................57
    Viewing Mock Event Details...........................................................................................................57
    Defining the Coverage Scope..........................................................................................................58
    Coverage Analysis in Headless Mode...........................................................................................59

12 Service Usage.......................................................................................................................................61
    WmServiceMock Services...............................................................................................................62
    References..........................................................................................................................................63

iv                                                                                                   webMethods Unit Test Framework Help 10.5
About this Guide
■     Document Conventions ....................................................................................................   6

webMethods Unit Test Framework Help 10.5                                                                                          5
This guide provides information on service testing options of Integration Server using webMethods
Test Suite. The scope of this document is to introduce the suite, design and execute test cases.

It is assumed that the user is familiar with the standard build and test tools such as, Ant and JUnit.

Document Conventions
Convention         Description

Bold               Identifies elements on a screen.

Narrowfont         Identifies service names and locations in the format folder.subfolder.service, APIs,
                   Java classes, methods, properties.

Italic             Identifies:

                   Variables for which you must supply values specific to your own situation or
                   environment.
                   New terms the first time they occur in the text.
                   References to other documentation sources.

Monospace font     Identifies:

                   Text you must type in.
                   Messages displayed by the system.
                   Program code.

{}                 Indicates a set of choices from which you must choose one. Type only the
                   information inside the curly braces. Do not type the { } symbols.

|                  Separates two mutually exclusive choices in a syntax line. Type one of these
                   choices. Do not type the | symbol.

[]                 Indicates one or more options. Type only the information inside the square
                   brackets. Do not type the [ ] symbols.

...                Indicates that you can type multiple options of the same type. Type only the
                   information. Do not type the ellipsis (...).

Online Information and Support

Software AG Documentation Website
You can find documentation on the Software AG Documentation website at http://
documentation.softwareag.com. The site requires credentials for Software AG's Product Support
site Empower. If you do not have Empower credentials, you must use the TECHcommunity
website.

6                                                                  webMethods Unit Test Framework Help 10.5
Software AG Empower Product Support Website
If you do not yet have an account for Empower, send an email to empower@softwareag.com with
your name, company, and company email address and request an account.

Once you have an account, you can open Support Incidents online via the eService section of
Empower at https://empower.softwareag.com/.

You can find product information on the Software AG Empower Product Support website at
https://empower.softwareag.com.

To submit feature/enhancement requests, get information about product availability, and download
products, go to Products.

To get information about fixes and to read early warnings, technical papers, and knowledge base
articles, go to the Knowledge Center.

If you have any questions, you can find a local or toll-free number for your country in our Global
Support Contact Directory at https://empower.softwareag.com/public_directory.asp and give us
a call.

Software AG TECHcommunity
You can find documentation and other technical information on the Software AG TECHcommunity
website at http://techcommunity.softwareag.com. You can:

    Access product documentation, if you have TECHcommunity credentials. If you do not, you
    will need to register and specify "Documentation" as an area of interest.

    Access articles, code samples, demos, and tutorials.

    Use the online discussion forums, moderated by Software AG professionals, to ask questions,
    discuss best practices, and learn how other customers are using Software AG technology.

    Link to external websites that discuss open standards and web technology.

webMethods Unit Test Framework Help 10.5                                                         7
8   webMethods Unit Test Framework Help 10.5
1 Unit Test Framework
■     Overview ........................................................................................................................    10

■     Terms and Concepts ......................................................................................................            10

■     Capabilities .....................................................................................................................   13

■     Server Definition .............................................................................................................      14

■     Environment ...................................................................................................................      14

■     What it is not ...................................................................................................................   15

webMethods Unit Test Framework Help 10.5                                                                                                    9
1 Unit Test Framework

Overview
Test Suite is an Eclipse based testing tool that allows developers to create unit tests for their
development. These tests improve the overall development quality and provide a mechanism to
create automated tools for continuous integration and delivery.

Test Suite provides the following functionalities:

     Provides service unit testing and regression testing tools that allows service developers to
     assemble unit tests without the need for additional development

     Enables integration with JUnit to leverage a standard unit testing framework, which already
     works well with Continuous Integration tools

     Enables ease of use for test development

     Provides a Java API for advanced users to create JUnit test cases

     Provides a user interface that is integrated in Software AG Designer. Software AG Designer
     ensures that users do not switch between tools for services development and corresponding
     test cases

     Provides a mechanism to repeatedly execute the service with same inputs and compare the
     results with an expected set of outputs

     Provides a framework for mocking service execution for steps that cannot be executed during
     the testing. For details, see “Using Mocks ” on page 36

Terms and Concepts
This section provides information on the terms and concepts used to understand Test Suite.

Services
The webMethods Integration Server hosts packages that contain services and related files. The
server contains several packages.

For example, Packages that contain built-in services, which can be invoked from services or client
applications and services that demonstrate features of the webMethods Integration Platform.

You can create additional packages to hold the services that your developers create. Developers
can create services that perform functions, such as, integrating your business systems with those
of your partners, retrieving data from legacy systems, and accessing and updating databases.

Integration Server provides an environment for the orderly, efficient, and secure execution of
services. It decodes client requests, identifies the requested services, invokes the services, passes
data to them in the expected format, encodes the output produced by the services, and returns
output to the clients.

10                                                                webMethods Unit Test Framework Help 10.5
1 Unit Test Framework

Pipeline
Pipeline refers to the data structure in which input and output values are maintained for a flow
service. It allows services in the flow to share data.

webMethods Unit Test Framework Help 10.5                                                          11
1 Unit Test Framework

Pipeline starts with the input to the flow service and collects inputs and outputs from subsequent
services in the flow. The service in the flow has access to all data in the pipeline at that point.

Unit Testing
Test Suite uses the concepts of service execution, pipeline data, and the open source JUnit testing
framework to provide unit testing functionality for Integration Server Flow and Java services. Test
Suite provides the ability to create a suite of tests consisting of individual test cases. Each test case
defines a service to be tested, the type of test to be performed, and provides a user interface to
define input data to the test case through the pipeline. When the service execution is completed,
the pipeline output is validated against the expected output defined in the test case.

Test Case
A test case is a unit of testing for a service that provides:

     service to be tested

     inputs to the service

     expected output from the service

A test case can also define expected output from a service as an exception or error. The service
returns the defined errors when incorrect data is sent to it.

Test Suite
A test suite is one or more test cases grouped together. Test suites are used to organize test cases
into sets of related tests. For example, a service may provide a variety of capabilities based upon
the inputs provided to it. A complete test suite should include test cases that provide inputs that
fully test all of the possible outputs of the service, including errors or exceptions.

Mock
Mocks provide a means of simulating interaction with resources that are unavailable or the data
provided by these resources or systems is not consistent for test purposes. Mocks also have a
lifetime that can either be limited to the test case in which they are defined or applied to all of the
test cases that follow within a test suite from the point of the definition.

Mock intercept can control the session, user, and server based on the scope setting. If the scope is
set to session, the test sessions will be affected by the mock. It is recommended to set the scope to
session for most users. If the scope is set to user, all the sessions for the particular user will be
affected by the mock. If the scope is set to server, all user sessions will be affected by the mock.
Mocks can be enabled or disabled for test case or test suite execution.

12                                                                  webMethods Unit Test Framework Help 10.5
1 Unit Test Framework

Service Mock
A service mock is used to replace the call to a service with a call to a different service. Any call to
the mocked service is intercepted and the alternate service defined in the mock is called instead.
The output of the mocked service is then returned to the calling service. This kind of mock is useful
when the output of the mocked service needs to be dynamic based on some logic that can be
created in the service.

Exception Mock
An exception mock is used to return an error or exception to the calling service and can be useful
for testing error handling in a service. As with the other mocks described, any call to the service
defined in the mock is intercepted and the exception defined in the mock is returned instead. This
kind of mock is useful to simulate behavior that can cause exceptions in the normal flow.

Factory Mock
A factory mock is used when a call to a service produce multiple different outputs based on the
provided input. A factory mock is implemented as a Java class. Any call to the class defined in a
factory mock is intercepted and the input is passed to the factory which evaluates the input and
returns the appropriate results. While both the factory mock and the service mock options provide
dynamic output simulation, the factory mock does not require an extra test service to be created
on the server and relies on a lightweight java implementation.

Capabilities
Test Suite has following capabilities:

    Unit testing

    Mock testing

    Regression testing

    Code coverage

Unit testing
Test Suite is a unit-testing tool. You can design, build, and execute unit test cases using Eclipse
User Interface. You can also execute the test cases externally using Ant scripts.

Mock testing
Mocking is a feature that mimics the functionality of services that are dependent on external
resources. When a test case encounters a service that is mocked, it executes the service.

webMethods Unit Test Framework Help 10.5                                                              13
1 Unit Test Framework

Regression testing
You can save the test cases, along with their inputs and outputs, in xml files. Run the reusable
artifacts to ensure that the latest changes do not reintroduce the errors fixed in the earlier versions.

Code coverage
Unit Test Framework records and analyzes the flow steps and map actions of your flow service(s)
that are executed during a test launch. It helps you to identify the untested steps and improve the
corresponding tests.

Server Definition
Integration Server preferences in Designer describe the connection to for Test Suite.

Designer always uses the active default Integration Server definition for Test Suite. Secure
connection option in default server definition indicates whether the session will be opened through
HTTP or HTTPS. In Designer, navigate to Window > Preferences > Software AG > Integration
Server to add, edit, and update connection configurations. For details, refer the webMethods Service
Development Help.

The editor does not always require an active connection to the test development. But some of the
introspection features that allow service lookup and service signature are not available if a
connection is not available and so, the user should enter them manually.

Environment
Option                  Description

Hardware                No additional hardware is required other than the ones that are already in
Requirements            use for Integration Server and Software AG Designer.

Software                Developer Installation Requirements
Requirements
                           Unit Test Framework Eclipse plug-in (Designer > Services > Unit Test
                           Framework)

                           WmServiceMock package for Integration Server (Integration Server or
                           Microservices Runtime Packages > Unit Test Framework)

                        Unit Test Framework Software AG Designer plug-in can work with both Local
                        and Remote Integration Server.

                        Continuous Integration Installation Requirements

                           WmServiceMock package for Integration Server (Integration Server or
                           Microservices Runtime Packages > Unit Test Framework)

14                                                                  webMethods Unit Test Framework Help 10.5
1 Unit Test Framework

Option                 Description

                            Unit Test Framework libraries (Infrastructure > Libraries > Unit Test
                            Framework Libraries)

                            Ant Build tool 1.7 (optional)

                            JDK 1.8 or later

Version                This suite depends on open source products like Ant and JUnit.
Compatibilities
                       Following are the supported versions:

                            Ant: 1.7

                            JUnit: 4.11

                       Unit Test Framework works with all the currently supported General
                       Availability (GA) versions of Integration Server and Software AG Designer.

What it is not
    Test Suite is not an integration or system test platform. However, this suite is used to mock
    the application dependencies and simulate the integration or system test.

    Test Suite is not a performance-testing tool. It cannot be used for performance, load, or volume
    testing.

webMethods Unit Test Framework Help 10.5                                                             15
1 Unit Test Framework

16                      webMethods Unit Test Framework Help 10.5
2 Working with Unit Test Framework
■     Opening the Unit Test Framework Perspective ...............................................................                            18

■     Layout .............................................................................................................................   18

■     Test Suite Preferences ...................................................................................................             19

webMethods Unit Test Framework Help 10.5                                                                                                     17
2 Working with Unit Test Framework

Opening the Unit Test Framework Perspective
Software AG Designer provides a Unit Test Framework perspective that contains the views, editors,
and tabs needed to build test suites and other supporting elements.

1. In Designer, select Windows > Open Perspective > Other.

2. In the Open Perspective dialog box, select Unit Test Framework and click OK.

     Designer switches to Unit Test Framework perspective.

Layout
The figure below shows various components of Software AG Designer with a test suite file open
for editing.

Use the following icons on the toolbar to tailor the layout.

Icon                     Description

                         Allows you to place the Master and Details views next to each other, master
                         on the right and details on the left.

                         Allows you make the master appear at the top of the display, and the details
                         view gets aligned underneath it.

                         Allows you to toggle the display between the master and details views, each
                         occupying the entire display. Click again to return to the original layout .

18                                                                  webMethods Unit Test Framework Help 10.5
2 Working with Unit Test Framework

Test Suite Preferences
To display the preferences dialog box, select Window>Preferences>Sotware AG>webMethods
TestSuite.

Advanced
The Advanced preferences control other behaviors of Test Suite.

Preference             Description

Use Relative           Makes file name references relative to the Eclipse project containing the test
Paths in               suite rather than using the full path. Using relative names helps in executing
Filenames              tests when the test suite and data files are moved between environments and
                       systems. This option is enabled by default.

Allow Comparator Controls the display of the field that allows the selection of the comparator
Configuration    and does not allow/disallow this during execution.

Allow client side Enables the option of creating client side factory object that do not need to be
mock factory      deployed on the server before executing test cases. This option controls the
objects           display of the field that controls whether the mock factory objects are needed
                  on the server or can be pushed during the execution of the tests.

Display all fields Enables additional fields in the Expected Output section of a test case. This
in the expression option is useful if you want to check several output conditions together.
editor

Allow editing of       Enables editing of the XML source for the test suite. This option requires that
XML (Effective         the open test suite file is closed and reopened before its behavior reflects in
after reopen)          the editor.

Allow scope            Enables scope selection for the mock. The default setting of unchecked is
selection for          appropriate for most test case scenarios.
mocks

Confirm delete of Enables the display of a confirmation dialog box for every mock service or
single objects    data entry delete.

Confirm delete of Enables the display of a confirmation dialog box when you delete multiple
multiple objects mock service or data entries.

Confirm service        Enables the display of a confirmation dialog box when you paste a test services.
paste

Code Coverage
The advanced code coverage preferences controls the behaviors of code coverage execution in
Test Suite.

webMethods Unit Test Framework Help 10.5                                                                  19
2 Working with Unit Test Framework

Preference               Description

Include Execution Generates an additional Execution Model report during code coverage
Model Report in execution in Test Suite.
Code Coverage
Execution

Include Service          Generates an additional Service Level Coverage report during code coverage
Level Covergae           execution in Test Suite.
Report in Code
Coverage
Execution

Include Launch           Enables you to debug a Java code during the code coverage execution in Test
Code Coverage            Suite.
Execution in
Debug Mode

License
The License preferences provide the license related information of Test Suite.

Preference               Description

License file             Allows you to select the license file for Test Suite.

Check License            Allows you to check the validity of the license file.

Editor
The Editor preference allows you to list the packages to load tot he service browser. connection
to webMethods Integration Server.

Preference               Description

Package Filter           Optional. Allows you to optionally enter a comma-separated list of packages
                         for Test Suite to load to the service browser. When a large number of packages
                         exist on the Integration Server, this feature loads only those services for which
                         test cases are developed and thereby conserves memory in Test Suite.

Validation
The Validation preferences describe when and how Test Suite should validate the information
that you enter.

20                                                                     webMethods Unit Test Framework Help 10.5
2 Working with Unit Test Framework

Preference             Description

Validate on Save Allows Test Suite to validate the test suite prior to saving it to the file system.
                 This option is enabled by default.

Validate before        Allows Test Suite to perform validation of the test suite prior to switching
switching mode         from the XML editor mode to the test suite editor.

Validate against       Allows Test Suite to validate the test suite against the XML schema. This is
schema                 useful if you use the XML Source tab to enter details of one or more test cases
                       in the suite. This option is enabled by default.

webMethods Unit Test Framework Help 10.5                                                                 21
2 Working with Unit Test Framework

22                                   webMethods Unit Test Framework Help 10.5
3 Creating a Test Suite
■     Before You Begin ............................................................................................................   24

■     To Create a Test Suite ....................................................................................................     24

■     Creating a Sample Test Suite .........................................................................................          24

webMethods Unit Test Framework Help 10.5                                                                                              23
3 Creating a Test Suite

Before You Begin
Before creating a test suite, ensure that you organize the required test cases and data files in a test
folder.

If the test cases are packaged in the Integration Server package, it provides a common source
location for all related assets. You can import the package on eclipse workspace.

Example: Consider that the test cases are created in the resources test folder of the Integration
Server package.

While any organizational structure that conforms to Integration Server package structure can be
used, the following example provides a useful approach for organizing test cases in your
environment. For ease of organization, follow the steps below:

1. Right click the Resources directory and create a subdirectory under it called test.

2. Right-click the test directory and create two additional folders data and setup.

3. Add the test suites to the setup directory and organize the data directory using subdirectories
   for each test suite to contain the input data files for the test cases comprising a test suite.

To Create a Test Suite
Follow the below steps to create a test suite:

1. Navigate to resources> test> setup folder.

2. Select File>New> Test Suite.

3. On the webMethods TestSuite screen, enter the folder path that contains the test suite setup
   files, provide a file name, and a suite name.

4. Click Finish.

     You can now start creating the test cases.

Creating a Sample Test Suite
Designer allows you to create sample Test Suite projects.

1. Navigate to resources> test> setup folder.

2. Select File>New> Test Suite Example.

3. On the Sample wmTestSuite Project screen, enter the project name and location. You can
   choose to use the default values.

24                                                                 webMethods Unit Test Framework Help 10.5
3 Creating a Test Suite

    This Test Suite familiarises you on building test cases.

webMethods Unit Test Framework Help 10.5                                           25
3 Creating a Test Suite

26                        webMethods Unit Test Framework Help 10.5
4 Adding Test Cases
■     Adding a Test Case ........................................................................................................             28

■     Test Details .....................................................................................................................      28

■     Service Details ...............................................................................................................         28

■     Inputs ..............................................................................................................................   28

■     Expected Output .............................................................................................................           29

■     Output Comparison ........................................................................................................              29

webMethods Unit Test Framework Help 10.5                                                                                                      27
4 Adding Test Cases

Adding a Test Case
Adding a test case involves the following steps:

1. Adding required test details. See “Test Details” on page 28.

2. Adding the required service details. See “Service Details” on page 28.

3. Defining inputs to services. See “Inputs” on page 28.

4. Defining the expected output. See “Expected Output” on page 29.

Test Details
To add test cases:

     Right click on the webMethods Test Suite section.

     The Test Details section appears in the details area to the right side of the display. Provide a
     name and description for the test case.

Service Details
After creating the test details, you can now select the service to be tested.

1. Click Browse in the Service Details section to enable searching for the service within the
   Integration Server.

     Note:
     You can narrow the search by entering a package name or service name and the service
     browser will restrict the display to only those packages or services matching the search
     criteria entered.

2. Click     to refresh or set additional options for service browser.

Inputs
Test Suite looks at the service signature for services in the Integration Server. When defining the
inputs to the service selected in “Service Details” on page 28

     Click Edit to modify the values of the input parameters and click OK to save the changes.

         Click Save... to save the file in the location designated for the input data after defining the
         input.

         Click Load to import a saved input data.

     Click Browse to add a saved file as the input to the service.

28                                                                   webMethods Unit Test Framework Help 10.5
4 Adding Test Cases

Expected Output
The final step in defining a test case is to complete the Expected Output section. Expected Output
can be in the form of data returned from the service or an exception returned from the service.

Use the class browser to define an exception or error output from the service. Click Browse to
display the classes and select the proper exception class to use.

To define the data output from the service, use the following methods:

    Use XPath expressions to define which data elements in the output data should be evaluated.

    1. Copy the XPath expressions from Software AG Designer. To copy the XPath expression,
       right click on the variable in the Results area when executing the service within Software
       AG Designer and select Copy.

    2. Click        ,     , or       and paste the copied value into the XPath field.

        An entry for the variable selected is created. However, it in most cases it is not required to
        edit them as the webMethods paths are 0 index based whereas XPath expressions are 1
        index based.

    3. Enter the expected output for the field in the Value field.

        You can select AND, OR, parentheses, and operators from the drop-down lists to create
        complex evaluations of the output.

    Use regular expressions to evaluate the output returned from the service. The regular expression
    should be placed in the Value field preceded and followed by "/" character.

Output Comparison
Unit Test Framework allows you to select predefined or customize the output comparison to
compare service results and check the destination table to confirm the operation executed
successfully.

  Prerequisite

    For the Output Comparison section to appear on the webMethods TestSuite screen, ensure
    that you select the Display all comparators option on the Preferences dialog box. To select
    Allow Comparator Configuration, navigate to Window > Preferences > Sotware AG >
    webMethods TestSuite > Advanced.

1. On the Output Comparison section, select Comparator Type.

2. Select one of the following options:

webMethods Unit Test Framework Help 10.5                                                                29
4 Adding Test Cases

Select...             To...

Default               Compare the actual and expected service result without any
                      filter.

Ignore Namespace      Ignore the namespace prefix from the service results.
Prefix
                      For example, for a field value demotest:employee in the actual
                      result, where demotest is the namespace prefix, Unit Test
                      Framework ignores the namespace and uses employee for
                      comparison.

Use Field Alias       Specify which fields in the service result should be compared.

                      You have to provide a field alias for the field in the actual
                      result that you want to Unit Test Framework to compare
                      against in the expected output.

                      For example, for a field value demotest:employee in the actual
                      result, you can assign a 1002 as the field alias. Then, Unit Test
                      Framework uses 1002 instead of demotest:employee for
                      comparison.

                      Click      to add the list of fields to compare.

                      Click     , or     to edit or delete the entries.

Custom                Specify a custom comparator for expected output other than
                      provided with the plug-in.

30                                                             webMethods Unit Test Framework Help 10.5
5 Generating Tests
■     Generating Tests Suites using Service Execution Results .............................................   32

webMethods Unit Test Framework Help 10.5                                                                      31
5 Generating Tests

Generating Tests Suites using Service Execution Results
Test Suite allows you to generate tests from the details of recently run services present in the Result
view. Using the Generate Test icon       on the Results view, you can export the available service
invoke or run details to form a unit test and save in a Test Suite.

Ensure that you have installed the Test Suite Designer plugin.

1. In the Service Development perspective, navigate to the Results view of recently run services
   and select the service for which you want to generate a test.

     Note:
     For details on viewing the Results view, see the Software AG Designer Online Help.

2. Click         .

3. In the Export Pipeline dialog box, provide the following details and click Finish.

     Type                                Function

     Container                           Specifies the project or directory location of the Test Suite.

                                         Ensure that you use an organizational structure that
                                         conforms to Integration Server package structure.

                                         Ensure that the specified project exists in the workspace.

     TestSuite                           Specifies the name of the TestSuite file.

                                         Use Overwrite to rebuilt the Test Suite. This overwrites the
                                         existing Test Suite.

                                         Use Append to append to the existing Test Suite.

                                         Note:
                                         Ensure that you provide the filename with the extension.
                                         For example, wmTestSuite.xml.

     Input                               Specifies the service input file location.

                                         Note:
                                         You can choose to retain the default value.

     Output                              Specifies the expected output file location.

                                         Note:
                                         You can choose to retain the default value.

     The Test Suite is created at the specified location.

32                                                                  webMethods Unit Test Framework Help 10.5
5 Generating Tests

4. Double click the newly created Test Suite.

    The test details are displayed. You can edit the test details. To edit the test details, see .

webMethods Unit Test Framework Help 10.5                                                                33
5 Generating Tests

34                   webMethods Unit Test Framework Help 10.5
6 Mocks
■     Using Mocks ...................................................................................................................   36

■     Sample Mock Factory .....................................................................................................         37

■     Mocks beyond Unit Testing .............................................................................................           38

webMethods Unit Test Framework Help 10.5                                                                                                35
6 Mocks

Using Mocks
Mocks are used when resources that a service may require to properly execute may not be available
when a test case or test suite is developed or executed. Mocks provide a means of simulating
interaction with resources that are unavailable.

     To create a mock

1. Expand the test case for which you want to define the mock, right click on Mocks and select
   Add.

2. Click Browse and use the Service Browser to select the service to be mocked.

3. Enter the first few characters of the service name to reduce the list. Click to refresh the list and
   access preferences for the Service Browser.

4. Select the required Lifetime.

      Valid selections are test (mock is effective only for the selected test case) and suite (mock will
      be effective for all of the test cases that follow in the test suite).

5. Select the required Type.

      Following are the valid selections:

Type                                   Function

pipeline                               Intercepts the service and returns the specified pipeline (for
                                       details on creating or editing pipeline data see “Inputs” on
                                       page 28).

service                                Intercepts the service and substitutes the selected service with
                                       a call (for details on working with the Service Browser, see
                                       “Service Details” on page 28).

exception                              Intercepts the service and returns an exception (for details on
                                       selecting exception classes, see “Expected Output” on
                                       page 29).

factory                                Intercepts a call to the mocked service and returns the data
                                       based on the input (for details on creating a mock factory, see
                                       “Sample Mock Factory” on page 37).

6. Select the scope.

      It is recommended to use the session scope for most purposes. To allow the scope selection,
      select the corresponding preference.

36                                                                  webMethods Unit Test Framework Help 10.5
6 Mocks

Sample Mock Factory
The following code snippet illustrates the minimum requirements for creating a mock factory.
The factory class and any other classes should be designed to evaluate the input data to the factory
and return data relevant to that input in an IData format. The example below returns static data.
package com.wm.ps.serviceMock.samples;
import com.wm.app.b2b.server.BaseService;
import com.wm.app.b2b.server.invoke.ServiceStatus;
import com.wm.data.IData;
import com.wm.data.IDataFactory;
import com.wm.ps.serviceMock.MockDataFactory;
public class SampleMockDataFactory implements MockDataFactory
{
  private static final long serialVersionUID = 2L;

    public IData createData(BaseService baseService, IData pipeline,
    ServiceStatus serviceStatus)
    {
      IData[] results = new IData[]{IDataFactory.create(new Object[][]{
          {"originationSource","W"},
             {"bizType","RT"},
             {"lockExpirationDate","20050427"},
             {"floatLoanIndicator","Y"},
             {"uwFinalDecisionCode","0"},
             {"uwDecisionExpiryDate","20050427"},
             {"canDate","20050427"},
             {"loanCloseStatusType","T"},
             {"fileReceivedAtRocDate","20050221"},
             {"loanReadyToFundIndicator","P"},
             {"regisDate","20051221"},
             {"loanSubmitToUwDate","20050427"},
             {"loanNumber","0000000001"},
             {"branch","TOTAL ADVANTEDGE LLC           "},
             {"underwritingDecisionCode","0"},
             {"underwritingDecisionExpirationDate","20050427"},
             {"lockDate","20051220"},
             {"lockIndicator","Y"},
             {"tmoLoanStageCode","3"},
             {"tmoLoanStageDate","20050427"},
             {"product","C30       "},
             {"borrowerFirstName",".           "},
             {"borrowerLastName","XX               "},
             {"propertyAddress","937 S MEYER                    "},
             {"propertyCity","TUCSON                     "},
             {"propertyState","AZ"},
             {"propertyZip","85701"}
        })};

        IData output = IDataFactory.create(new Object[][]{{"results", results}});
        return IDataFactory.create(new Object[][]{{"getPotentialDuplicatesOutput",
        output}});
    }
}

webMethods Unit Test Framework Help 10.5                                                          37
6 Mocks

Mocks beyond Unit Testing
Although Test Suite added the ability to mock service calls in Integration Server for unit testing,
the feature is so powerful that its use cannot be limited to unit testing alone. One common case is
to use the mocking capability to provide flow service instrumentation.

Using the wm.ps.serviceMock:loadMock service in the WmServiceMock package, any service can be
mocked with an alternate service or class. The new service or Java class code can invoke any
operations and then invoke the original mocked service. The mocking framework is intelligent
enough to detect recursion and, as such, provides an instrumentation capability.

Mocks can be used to design test cases. A service being tested can also itself be mocked with other
code. In such a scenario, the mocked test service can be replaced with other code that can execute
pre and post-test operations. This can provide some basic functional testing capabilities for Test
Suite.

38                                                              webMethods Unit Test Framework Help 10.5
7 Advanced Options
■     Pipeline Filter ..................................................................................................................   40

■     Comparators ...................................................................................................................      40

■     Client Mock Factory ........................................................................................................         40

■     XPath Expressions .........................................................................................................          41

webMethods Unit Test Framework Help 10.5                                                                                                   39
7 Advanced Options

Pipeline Filter
The execution of test cases is initiated as a client to the Integration Server hosting the services to
be tested. For this reason, the inputs supplied to the service during execution and the expected
outputs need to be serialized over the client-server interaction. If the input or output pipeline
contains non-serializable objects, these objects are either lost or seen incorrectly during test
execution. In addition, the service input needs to be more dynamic in nature than the static pipeline
setup in the test case. Pipeline Filter helps to resolve these issues.

The Pipeline Filter is set once for the entire suite and provides a callback mechanism for the test
developer to inject code that can modify various pipeline objects during execution. The Pipeline
Filter is a class that implements the com.wm.ps.test.PipelineFilter interface and enables a user to add,
remove, or change variables in the pipeline that are created from files, as pipelines created from
files may not be able to persist custom java objects. The output pipeline from a service can also be
filtered using the appropriate method. Only one such instance of the implementing class is created
for the test suite and the name of test case is passed as a parameter.

The pipeline filter can be setup for the test suite in the main panel for the suite parameters.

Comparators
Comparator provides an extension that can be used to extend, enhance, or replace the standard
comparison of expected output.

Each test suite can have its comparator that can be specified from the user interface.

Custom comparators are Java classes that implement the com.wm.ps.test.ResultsValidator interface.

Comparators also provide a mechanism to execute operations pre and post service execution.
Using comparators you can build some basic functional testing capability. For example, if a service
writes to a database table, a comparator can compare the results from the service and check the
destination table to confirm the operation executed successfully. You can also specify filters while
comparing.

Client Mock Factory
The benefit of using a mock factory object as opposed to a service is that it provides a light-weight
alternative that does not require the creation of a new service on the server.

Test Suite provides an option to dynamically push the classes needed for supporting the mock
factory on the server during test execution. This option can be used to avoid the need for frequent
restart when Java objects are changing. Once stabilized, it would be helpful to deploy the code to
the server as this feature is experimental in nature and will only work if the dependency tree is
not too complex. Using the user interface, you can set the option to dynamically push the objects
to the server.

If the option is disabled, enable the corresponding preference as discussed in the Advanced section.

40                                                                  webMethods Unit Test Framework Help 10.5
7 Advanced Options

webMethods expression                                                                      JXPath equivalent

PosRequest/ns:Log/ns:Transaction[0]/@Flag                                                  PosRequest[@name=n
                                                                                                            ' s:Log]'[@name=n
                                                                                                                            ' s:Transaction]'[1][@name=@
                                                                                                                                                       ' Flag]'

PosRequest/ns:Log/ns:Transaction[0]/ns:BUnit[0]/ns:ID/*body PosRequest[@name=n'sL
                                                                                :og][@
                                                                                     ' name=n'sT
                                                                                               :ransacto
                                                                                                       in][1'][@name=n'sB
                                                                                                                        :Un][1ti'][@name=n'sID
                                                                                                                                             : ][@
                                                                                                                                                 ' name=*b
                                                                                                                                                         ' ody]'

XPath Expressions
The XPath expressions used in the expected output panel are different from the usual webMethods
path expressions. As mentioned in the “Expected Output” on page 29 section, the indices start at
1 instead of the 0 based webMethods indices.

Test Suite uses JXPath for evaluating XPath expressions. For details on JXPath expressions, visit
http://commons.apache.org/jxpath/. Special characters such as '@' and ':' in the name have special
meaning in JXPath expressions hence, you should use special syntax variant to use these characters
in variable name.

webMethods Unit Test Framework Help 10.5                                                                                                                     41
7 Advanced Options

42                   webMethods Unit Test Framework Help 10.5
8 Test Suite Internals
■     Test Suite Internals .........................................................................................................   44

webMethods Unit Test Framework Help 10.5                                                                                               43
8 Test Suite Internals

Test Suite Internals
In Software AG Designer, test suite editor provides a user interface to graphically and quickly
develop test cases for Integration Server services. The test suite and the test cases are saved in an
XML file. The Software AG Designer editor allows editing the XML source directly, provided that
the user is aware of the format and the associated schema.

It is not recommended to edit the XML file as it is error-prone. It provides the option to automate
the creation of test cases automatically by using code to generate the XML file directly. One such
use case is the scenario where service inputs and outputs have been captured in an environment
and test cases have to be generated to use these files for regression testing.

A sample XML test suite file in its simplified form can be as shown in the figure below:

44                                                                webMethods Unit Test Framework Help 10.5
9 Java Unit Tests
■     Java Unit Tests ...............................................................................................................   46

webMethods Unit Test Framework Help 10.5                                                                                                45
9 Java Unit Tests

Java Unit Tests
Test Suite Java API allows you to create pure JUnit test cases that can provide the same features
that a user interface driven codeless test cases do.

The change when creating a Test Suite JUnit test case from the traditional test case is that the
implementing class extends com.wm.ps.test.WmTestCase instead of junit.framework.TestCase.
com.wm.ps.test.WmTestCase does extend the junit.framework.TestCase. The two important methods that
are needed for creating test cases using the java API are:

     invokeService – The method to invoke a service on the server

     mockService – There are various variants of this method that allow the user to setup a mock
     for a service on the server.

A sample JUnit test case is provided here:
package com.wm.ps.serviceMock.samples;
import com.wm.data.*;
import com.wm.ps.test.*;
public class DuplicateCheckTest extends WmTestCase
{
  public void testDupCheckCatchBlock() throws Exception
  {
    IData input = IDataFactory.create(new Object[][]{
        {"lienType", "1"},
        {"borrowerSSN", "111-11-1111"},
        {"propertyAddress", "937 S Meyer"},
        {"propertyZip", "85701"}
        });

    String exceptionText = "Bad argument";
    mockService("wmServiceMockSamples.data.services",
      "getPotentialDuplicates", new
IllegalArgumentException(exceptionText));
    try
    {
       invokeService("wmServiceMockSamples.services",
        "getDuplicateLoans", input);
       assertFalse(true); //Control getting here means failure
    }
    catch (Exception e)
    {
       assertTrue(e.getMessage().endsWith(exceptionText));
    }
  }
  public void testDupCheckSucessWithResults() throws Exception
  {
    IData input = IDataFactory.create(new Object[][]{
    {"lienType", "1"},
    {"borrowerSSN", "111-11-1111"},
    {"propertyAddress", "937 S Meyer"},
    {"propertyZip", "85701"}
    });

    IData mockOutput =
WmTestSuiteUtils.getIDataFromFile("resources/test/data/

46                                                              webMethods Unit Test Framework Help 10.5
9 Java Unit Tests

    mockDupCheckOutputResults.xml");
      mockService("wmServiceMockSamples.data.services", "getPotentialDuplicates",
      mockOutput);
      IData output = invokeService("wmServiceMockSamples.services",
       "getDuplicateLoans",
       input);
      IDataCursor outCursor = output.getCursor();
      IData response = IDataUtil.getIData(outCursor, "response");
      IDataCursor responseCursor = response.getCursor();
      String creationTime = IDataUtil.getString(responseCursor, "@creationTime");
      assertNotNull(creationTime);
      assertEquals(28, creationTime.length());
      IData[] duplicateLoans = IDataUtil.getIDataArray(responseCursor,
       "duplicateLoans");
      assertEquals(duplicateLoans.length, 1);
    }
}

webMethods Unit Test Framework Help 10.5                                                  47
9 Java Unit Tests

48                  webMethods Unit Test Framework Help 10.5
10 Executing Tests
■     Executing Test Cases .....................................................................................................    50

■     Executing Test Suites .....................................................................................................   50

■     Debugging Java Code ....................................................................................................      50

■     Continuous Integration ...................................................................................................    51

webMethods Unit Test Framework Help 10.5                                                                                            49
10 Executing Tests

Executing Test Cases
To execute test cases created with Test Suite, right click in the webMethods Tests section and select
one of the following options:

     Run Tests - executes the selected test case, using the mocks that are defined for the test case.

     Run Test with Mocks Disabled - executes the selected test case by disabling the mocks defined
     for the test case.

     Disable Test - marks test case as disabled. Tests are not executed until it is enabled again.

     Disable Mocking in Tests - marks mocks defined for selected test as disabled. Mocks are not
     executed until they are enabled again.

     Add - adds another test case to the suite.

     Insert - inserts another test case to the suite after the selected test case.

     Remove - removes the selected test case from the suite.

Executing Test Suites
To execute test suites created using Test Suite, right click in the webMethods Tests section and
select one of the following options:

     Run Suite - executes the selected test suite, using the mocks that are defined for the test suite.

     Run Suite with Mocks Disabled- executes the selected test suite by disabling the mocks
     de-fined for the test suite.

     Disable Suite - marks test suite as disabled. The test suite is not executed until it is enabled
     again.

     Disable Mocking in Suite - marks mocks defined for this suite as disabled. Mocks are not
     executed until they are enabled again.

     Shift Up or Shift Down - changes the order of test cases in the test suite by shifting the selected
     test case up or down in the test suite.

Debugging Java Code
Various components in Test Suite rely on Java code.

Example: Java mock factory and pipeline filter classes.

Use the Debug menu to debug a Java code. The support library jar files also have source code
associated with them. Debugging into the source can be helpful to understand the internals of the
test execution or to enhance capabilities new features like custom comparators.

50                                                                    webMethods Unit Test Framework Help 10.5
You can also read