IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Services and service-related functions > Access external services with adapters > Configure and using adapters > IBM WebSphere Adapters > Adapter Toolkit > Validating the code > Testing the adapter in unmanaged mode

Developing JUnit tests

You can unit test outbound and inbound processing by creating and specifying JCA contracts and operations. You then test and compare data before and after applying the tests. The EIS Simulator Adapter code sample illustrates these steps.


Outbound

The Java EE Connector Architecture (JCA) specification defines an unmanaged mode for running adapters. This means running the adapter outside of a JCA container and in process with the caller. This is the environment for developing JUnit tests.

Through a series of common client interface (CCI) and service provider interface (SPI) calls, you can force the adapter to perform an operation you want to test. First create instances of ManagedConnectionFactory and ResourceAdapter then set the appropriate properties in the client code.

Your adapter cannot be dependent on "live" data inside the EIS. If so, you must either return the data to a known state after every test, or create a mock implementation of the EIS API so that EIS data remains untouched.


setUp()

In the setup method for outbound, perform the following step:

  1. Load any schemas (if necessary)


Test

When you have completed the steps for setting up the test, you are ready to call the CCI interaction and validate the result. The following procedure creates an object, retrieves it, and validates its content.

In the test method, you need to do the following things:

These tasks can be delegated to helper methods

  1. Create the data and metadata you can work with (JavaBeans, SDO, or other format).

  2. Create a DataExchangeFactory for this data type, set the data as the bound object

  3. Create a StructuredRecord and initialize it, with the Data Exchange Factory and the metadata

  4. Invoke the adapter interaction.execute() using JCA CCI semantics

  5. Inspect the result of the output, by getting the bound object of the data exchange factory of the output record.

  1. Create a WBIRecord.

  2. Create a business object, populate it with data, and place it in WBIRecord.
  3. Set the appropriate verb in the business object.
  4. Call the interaction, capturing the output.

  5. Perform the assertion, which includes:

    • Retrieving the object
    • Validating the retrieved object against the original data


Inbound

In contrast to the outbound direction, inbound communication is not defined for unmanaged operation. To test the inbound capability of the adapter outside of a JCA container, you must implement some of the JCA container contracts. The following includes:

For more details on these contracts, study the EIS Simulator Adapter samples that are shipped with WebSphere Adapter Toolkit.


setUp()

The setUp() method for inbound is like that for outbound. You can, however, not need an outbound connection through the adapter. Accordingly, you only need to perform the following tasks:

  1. Create an adapter instance and set its properties

  2. Start the resource adapter.


Test

The test methods for inbound must do the following:

  1. Prepare the data inside the EIS. In a polling adapter, this would cause the triggers to fire, populating the event table.

  2. Create a MockEndpointFactory, and an ActivationSpecWithXid.
  3. Call endpointActivation() on the adapter.
  4. Wait for the event to arrive.

  5. Assert the correctness of the data after it is sent to the endpoint.

You can group your inbound and outbound tests into a single suite, and run them at once, getting instant feedback in your development environment.

For more details on the procedures described in this topic, study the EIS Simulator Adapter samples that are shipped with WebSphere Adapter Toolkit.

Testing the adapter in unmanaged mode