Testing JMS with soapUI

We have already seen soapUI being used for Web Services testing. In this recipe, we will demonstrate how soapUI can also be used for testing JMS-based interfaces.

We will use the solution from the recipe Accessing JMS Transport message headers and properties in message flow, which implemented a proxy service consuming from the SourceQueue of the OSB Cookbook standard environment. In that recipe, we have used the WebLogic console and replace it now in this recipe by soapUI.

Testing JMS with soapUI

The advantage of using soapUI for testing is the persistence of the different test cases and by that the possibility to automate tests. This is not achievable through the console, and also QBrowser shown in the previous recipe cannot be used for automating tests.

Getting ready

Download and install the latest version of soapUI ( soapUI 4.0 at the time of writing) from here: http://www.soapui.org. Make sure that you also select and install HermesJMS when asked by the soapUI installer.

Import the finished solution from the previous recipe into Eclipse from chapter-3solutionaccessing-jms-transport-headers-in-message-flow.

How to do it...

Before we can use soapUI for testing JMS, we need to configure JMS. This is done in HermesJMS, another external tool for working with JMS, which is used behind the scenes by soapUI. Perform the following steps to configure HermesJMS:

  1. Navigate to the installation folder of HermesJMS nested in the soapUI installation.
  2. Make sure that HermesJMS is using the same JVM as the WLS we want to connect to. Open <HERMES_HOME>inhermes.bat and add the following JAVA_HOME and PATH variable right at the beginning:
    SET JAVA_HOME=[FMW_HOME]jrockit_160_22_D1.1.1-3
    SET PATH=%JAVA_HOME%in
    
  3. Start soapUI.
  4. Click the Tools menu and select HermesJMS.
  5. In the Sessions tree on the left side, right-click on the sessions node and select New | New session.
  6. Navigate to the Providers tab.
  7. Right-click and select Add Group.
  8. Enter Weblogic into the Classpath group name field and click OK.
  9. Right-click on Library and select Add JAR(s).
  10. Navigate to the weblogic.jar in: <WEBLOGIC_HOME>serverlibweblogic.jar and click Open.
  11. Click Don't scan when asked and click Apply.
    How to do it...
  12. Navigate to the Sessions tab.
  13. Enter OsbCookbook into the Session field.
  14. Select Weblogic for the Loader drop-down listbox.
  15. Select BEA WebLogic for the Plugin in drop-down listbox.
  16. Select hermes.JNDIConnectionFactory for the Class drop-down listbox.
  17. For the Connection Factory, add the following properties through Add property.

    Property

    Value

    binding

    javax/jms/QueueConnectionFactory

    initialContextFactory

    weblogic.jndi.WLInitialConetxtFactory

    providerURL

    t3://<managedServer>:<port-number>

    securityCredentials

    weblogic

    securityPrincipal

    <password-of-weblogic>

  18. Click Apply and then click OK.
    How to do it...
  19. Right-click on the newly created session OsbCookbook and select Discover....
  20. After a while a pop-up window will show up stating Discovered # destinations.
  21. Click Yes to confirm.

    HermesJMS is now ready and can be used to administer the JMS server. The configuration is stored in the .hermes/hermes-config.xml file.

    Now we can go back to soapUI and use the HermesJMS configuration to send a message to a queue through a soapUI request. In soapUI perform the following steps:

  22. Right-click on the Projects tree node and select New soapUI Project.
  23. Enter SendToSourceQueue into the Project Name field and enable the Add REST Service option and click OK.
  24. Enter SendToSourceQueueService into the Service Name, enable the Create Resource option and click OK.
  25. Enter SourceQueue into the Resource Name field and click OK.
  26. Enter send into the Method Name and select POST for the HTTP Method drop-down listbox.
  27. Click OK.

    We have added a RESTful interface with one method SendMessage. To be able to use JMS, we have to add a JMS endpoint:

  28. Right-click on SendToSourceQueueService and select Add JMS endpoint.
  29. Click on Browse and navigate to the folder where the hermes-config.xml created previously can be found (c:.hermes on my machine).
  30. Select OsbCookbook for the Session.
  31. Select jms/SourceQueue for the Send/Publish destination.
  32. Click OK.

    Now the interface to the queue is defined in soapUI and we can finally execute a test and send a message to the SourceQueue. In soapUI, perform the following steps:

  33. Open Request 1 of the send method if not yet opened.
  34. Select the created endpoint jms://OsbCookbook::queue_jms/SourceQueue form the drop-down listbox.
  35. Enter This is a text message! into the field below the Media Type drop-down listbox.
  36. Navigate to the JMS Header settings and properties tab and enter 6 into the JMSPriority field.
    How to do it...
  37. Navigate to the JMS Property tab and click on the + button to add a new user-defined JMS property.
  38. Enter myProperty into the Specify name of JMS Property to add field of the pop-up window. Click OK.
  39. Enter red into the Value cell for the value of myProperty.
    How to do it...
  40. Click on the green arrow on the upper-left corner to execute the test.
  41. An empty response <xml/> will be shown in the response window indicating that the message has been sent.
  42. The OSB console should show some new log messages indicating that the proxy service has consumed and processed the message successfully.
    How to do it...

A high priority message has been consumed because we have set the JMSPriority to a value greater than 6 and the myProperty had the value red in the proxy service (remember the behavior of the previous recipe). This shows that the soapUI test was successful.

How it works...

SoapUI supports SOAP-based as well as RESTful requests. Because we don't want to send a SOAP message to our queue, we have used the REST features and configured a RESTful request. By adding a JMS endpoint we made sure that the request is not sent through HTTP, which is the default protocol soapUI uses, but through JMS. Adding a JMS endpoint is only possible if the JMS server has been previously setup in HermesJMS. SoapUI uses the HermesJMS configuration to communicate with the JMS server. In this recipe, we have configured HermesJMS to work with WebLogic JMS, but any other JMS-compliant server would work as well.

There's more...

SoapUI can also be used to do request/reply messaging through JMS, where the request queue and response queue are different. Just specify the second queue in the Receive/Subscribe destination.

There's more...

SoapUI can also be used to test SOAP over JMS. The usage of SOAP over JMS will be shown in Chapter 10, Sending SOAP over JMS.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset