Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Creating the Connector Plugin in Ready API
2.1.
Pre-preparation
2.2.
Creation of Connector Plugin
3.
Working with JMS in Ready API
3.1.
Editing Groove Test Step
3.2.
Property List
3.3.
Test Step Toolbar
3.4.
Debugging Groovy Scripts
3.5.
Logging
3.6.
Verifying
3.7.
Setting JMS Headers
4.
Frequently Asked Questions
4.1.
What skills should one possess to be able to use ReadyAPI?
4.2.
In which programming language do we write Ready API?
4.3.
Mention the uses of virtual services.
4.4.
How can one use API to call the virtual service? 
5.
Conclusion
Last Updated: Mar 27, 2024

Creating the Connector Plugin and working with JMS in Ready API

Author Rupal Saluja
0 upvote

Introduction

JMS stands for Java Message Service. It is an API used to exchange messages among applications. The ReadyAPI supports Java Message Service so that you can send and receive both text and binary messages. To understand JMS better, we need to understand every aspect of it.

logo of JMS

In this blog, we will discuss two important modules of JMS. These are creating the connector plugin and working with JMS in Ready API. So, without wasting time, let’s get started.

logo of smartbear

Creating the Connector Plugin in Ready API

As the name suggests, the connector plugin permits direct connections to JMS brokers. It serves as a way to provide the JMS client libraries to ReadyAPI. The plugins come with template values used to form connections with ReadyAPI. You can alter the template values but cannot change the initial context class in the UI.

two modules of creating connector plugin

Pre-preparation

You need to keep a check on the following items before you start the process of creation.

  • Java libraries to form a connection with the JMS provider
  • JDK installed and configured
  • Initial Context Class name
  • Provider URL
  • Connection Factory JNDI name

Creation of Connector Plugin

To create a connector plugin, follow these steps.

1. Create an empty folder in file explorer. This folder will become the root folder for the plugin.

2. Create a subfolder and name it lib in the created directory.

3. Copy all the JMS client libraries in the .jar format to the created subfolder. If the client libraries depend on other libraries, copy those libraries as well.

4. Now, download the jms-plugin.properties file from the official website.

5. Save the properties files to the root folder of the plugin. The file structure is given below for your reference.

<Plugin root folder>
|--lib
   |--<Provider’s jar files>
|--jms-plugin.properties

 

6. Open the properties file in any text editor to edit the default values. Use the comments in that file to understand the properties.

7. Some properties impact the plugin’s working and its representation in the interface. We will configure the properties. A brief description of these properties is given below in the table.

Property 

Description

plugin.name This property does not affect your tests. It is the name of the plugin displayed in the Plugin Manager.
plugin.version This property also does not affect your tests. It is the version of the plugin displayed in the Plugin Manager.
plugin.description It is the description of the plugin displayed in the Plugin Manager. Also, it does not affect your tests.
plugin.autodetect

It mandates ReadyAPI to look for plugin components used in Custom Plugins.

If true, you can add custom elements to the plugin along with loading client libraries.

If false, you will only be able to load JMS client libraries.

minimum.ready.version It shows the minimum supported version of ReadyAPI. All versions below to this are unsupported. You will not be able to load the plugin in such versions.
connector.label This property contains the label used to select the plugin in ReadyAPI Interface.

8. Also, there are a few properties that impact the working of the plugin with the JMS provider. While configuring those properties, you might need to add some values you got when configuring the JMS provider. A detailed description of these properties is given below.

  • initial.context.class.name

The plugin uses this property to form connections with the JMS provider. You can find the context factory property in the JMS provider documentation. Use the example classes name for JMS providers given below.

JMS providers

Classes

Oracle Weblogic weblogic.jndi.WLInitialContextFactory
TIBCO EMS com.tibco.tibjms.naming.TibjmsInitialContextFactory
Active MQ org.apache.activemq.jndi.ActiveMQInitialContextFactory
WebSphere MQ You will get this value from the Initial Context Factory property while configuring the WebSphere MQ installation.
  • provider.url.template

By default, this property specifies the URL of the service suggested by the plugin. You can change it at any point.

JMS providers

Classes

TIBCO EMS tcp://<hostname>:61616
Active MQ tibjmsnaming://<hostname>:7222
WebSphere MQ You will get this value from the Provider URL property while configuring the WebSphere MQ installation.
  • connection.factory.name.template

This property is used to form connections with the JMS broker.

JMS providers

Classes

Active MQ ConnectionFactory
WebSphere MQ You will get this value from the Connection Factory property while configuring the WebSphere MQ installation.

9. At last, build the plugin. There are two ways to do it.

By using JDK

Firstly, create a Java Archive (JAR) file using jar utility. Now, open the command prompt shell and move to the plugin’s root folder. Run the following command.

jar cvf my-jms-connector-plugin.jar *

 

By using a file archiver

Firstly, create a zip archive using jms-plugin.properties file and the lib folder. Note that you do not need to archive the root folder. This can lead to wrong structure and invalid plugins. An example of a valid plugin is given below.

my-jms-connector-plugin.zip
|--lib
   |--<Provider’s jar files>
|--jms-plugin.properties
Lastly, change the extension to .jar.


10. Once you have a final .jar file, install it as mentioned. 

Firstly, open the Integrations Tab. Click on the Install from file option and start browsing for the required plugin file. Select it, click Open and wait for the process to complete. A window appears; click Ok. If needed, restart the ReadyAPI.

Working with JMS in Ready API

A Groovy Script Test step works with queues, topics, and other JMS entities. It is used while executing Groovy or JavaScript tests code from tests. It eases the implementation of complex behavior of tests, such as modifying test step assertions during the test runs, complex validation of messages, triggering external actions or processes, integrating external systems, and much more.

notion of working with APIs

Editing Groove Test Step

You can edit groove test settings using the editor. Enter the script code in the editor and run it. Now, analyze the output to check if it is working as expected. Also, you can use a few objects mentioned in the table below, along with their descriptions.

Objects

Description

context It provides a scripting interface for the test case run.
log It provides a scripting interface to the Script log. You can use this object for debugging and logging purposes, such as posting and viewing data in the log.
testRunner It provides a scripting interface to the test runner object. This object executes the current test case and test step. Also, it exposes a few methods related to test execution and object models.

Use the Code Completion window to view these objects’ methods and properties. Type the object name and a period and press ctrl+space to invoke the window.

Property List

Other than the editor, you can use test step properties in the Groovy Script properties and Custom Groovy Script Test Step Properties panels to alter the test step’s behavior. You can find these options in the Navigator.

Groovy Script Properties

Name

Description

Name It contains the test step’s name.
Description It contains the text describing the test step.

Groovy Script Test Step Properties

Values under these properties under this tab are available for other test steps of your project. You can verify these property values with the Assertion test step. And check and alter the execution flow using the Conditional GoTo test step.

Also, you can modify, add, remove and change load values anytime from a file and save them to a file.

Name

Description

result It returns the result of the script execution. It is a read-only property.
script It returns the complete script code as a string.

Test Step Toolbar

The test step toolbar contains the commands that permit you to make changes with the test step or with the appearance of the test step editor.

Debugging Groovy Scripts

Debugging Scripts refers to stopping the test execution on a particular line, moving through the test stepwise, and stopping on operations and script lines. Every time the debugger stops, you are supposed to check the value of variables. This helps you track what your test is performing.

notion of debugging

During the process, a separate tab contains information about all variables known as Debug Info tab.

Requirements and Limitations

Certain requirements and limitations which can hamper the process are given below.

  • You can debug only Groovy scripts in the Groovy Script test step. Debugging of event handler scripts, setup, teardown and report scripts, script assertions, data source, data sink, and virtual service scripts is not allowed.
  • Also, debugging JavaScript scripts is not permitted.
  • Debugging one script only at a time is supported. You cannot debug multiple scripts parallelly.
  • You need a ReadyAPI test license to start debugging scripts.
list of limitations and requirements

Enabling the Debugger

By default, the debugger is disabled to save operating system resources. If you click in this state, you will be asked to restart ReadyAPI to enable it. You can use the groovy parameter to enable the debugger via a shell script (.bat or .sh file) while running ReadyAPI.

readyapi.bat groovy

 

If you want to enable the debugger permanently, open the vmoptions file. Add the lines given below and save the file.

-agentlib:jdwp=transport=dt_shmem,suspend=n,server=y
-Djdk.attach.allowAttachSelf=true


Start Debugging

Click on to start debugging. There are two ways to debug.

  • Using the Groovy test step

Only the particular script you are running it from gets executed.

  • Using a test suite, test case, or a project

The entire test gets executed in debug mode. The test will stop executing only if it encounters any breakpoint in the Groovy Script test steps.


Use breakpoints

A breakpoint is the location in your script where the execution of the script or test is paused. When the execution is paused, ReadyAPI will open the line with the breakpoint. This will help you check the state of the test, its output, and its variables.

To set a breakpoint, either click on the left margin of the source code line or right-click the source code line and select Toggle Line Breakpoint.


Step through tests

As soon as the test reaches a breakpoint, it stops. The ReadyAPI opens the Groovy Script editor and gives the user an option to run the following commands.

  • Step over

The execution moves with one statement or operation at a time within the script where the execution point is currently located. If the next statement calls any other script, the entire call is executed as a single step.

  • Step into

The execution moves with one statement or operation at a time, irrespective of where the execution point is currently located. While executing, if you enter any other function or script, the debugger will open it and continue stepwise execution.

  • Resume debugging

The execution continues till the next breakpoint, where it stops.

  • Continue to end

The execution continues till the end of the current script, irrespective of any breakpoint. If any other script exists with breakpoints in the test run, the execution will stop on them.

Logging

While logging, you must use the Log Output panel in the script editor for test runs. It contains some different script messages. You can post any message you want using the log.info method. Use the example below for your reference.

def tst = testRunner.runTestStepByName("Groovy Script")
log.info(tst.status)

Verifying

You can verify the response by performing assertions in the Groovy Script test step. The process is similar to performing assertions in the Groovy Script.

Setting JMS Headers

The following Python code specifies how to set the JMS header’s value in any test step.

def Example = testRunner.testCase.getTestStepByName("Example test step")
def msgID = "foo4711"// Specify the value for header
Example.testRequest.JMSHeaderConfig.messageSelector = "JMSCorrelationID = '${msgID}'"// Setting the header’s value

Frequently Asked Questions

What skills should one possess to be able to use ReadyAPI?

ReadyAPI simplifies the developing process by compressing complicated activities. These activities, which used to take hours, could now be done in a few clicks. That means it lets everybody of all skill levels work with it.

In which programming language do we write Ready API?

Ready API is written in the JAVA programming language. Its various modules and their counterparts were designed using JAVA.

Mention the uses of virtual services.

The most prominent uses of virtual services are users can tag processes or services on workloads, also known as bound services. And, you can utilize virtual services in rules. Also, you can use labels assigned to virtual assistants for writing rules.

How can one use API to call the virtual service? 

Virtual services are also known as virtual APIs, or web service mocks. These services mimic the API by defining the actions customers will call, simulating answers, and taking client requests.

Conclusion

To cut it short, we detailed the process of creating the connector plugin. We discussed various aspects related to it, such as its preparation and some properties which affect the whole process. We also learned what Groovy Test Script is and how it is used in working with JMS in Ready API.

We hope the above discussion helped you understand Creating the connector plugin and working with JMS in Ready API clearer and can be used for future reference whenever needed. To learn more about Ready API and its components, you can refer to blogs on Settings in Ready APIAuthentication of Ready APIIntroducing virtualization in the Ready APITest tiles in Ready API, and Virtualization project in Ready API.

Visit our website to read more such blogs. Make sure you enroll in our courses, take mock tests, solve problems, and interview puzzles. Also, you can pay attention to interview stuff- interview experiences and an interview bundle for placement preparations. Do upvote our blog to help fellow ninjas grow.

Happy Coding!

Live masterclass