How to test mobile applications with Rational Test Virtualization Server

Most of the mobile applications developed for enterprise use are distributed applications that integrate with back-end services. To test a mobile application end to end, you need to understand the back-end domains. IBM Rational Test Workbench helps simulate the back-end services you can use in integration testing. This capability eliminates the need to completely understand the back-end domains and makes it easier to test mobile applications.

Manjula Sogi (manjulasogi@in.ibm.com), Development Manager, IBM

Photo of Manjula SogiManjula R Sogi has worked for IBM for five years. She has managed teams that develop Rational Quality Manager, Rational Functional Tester, and Test Manager. Manjula has led the effort to build major features that involve offline execution, test automation APIs, clustering, process customization, and execution planning. She also developed a proof of concept to integrate Rational Quality Manager with Rational Test Virtualization Server



21 January 2014

Introduction

Learn how to use IBM® Rational® Test Virtualization Server to test mobile applications without modifying any code to use virtual services called stubs. To implement the stubs by simulating similar behaviors, you need to analyze the mobile application interface functions for input and output behaviors that are the actions typically performed by stubs. The mobile application connection configurations are changed to route through an HTTP proxy registered with Rational Test Virtualization Server.

This article introduces Rational Test Virtualization Server, IBM® Rational® Test Workbench and IBM® Worklight. This article describes how to develop stubs and virtual services in IBM Rational Integration Tester and how to integrate them with IBM Worklight Adapter.

Note: A good working knowledge of these products is necessary in order to understand this article in detail.


Why use test virtualization?

Several factors limit the ability to adequately test software: tight production schedules, security restrictions, costly usage fees for third-party software, and requirements to use hardware that isn't readily available. You can use test virtualization to create virtual services that simulate the behavior of an entire application or system and can run on any commodity hardware, private cloud, or public cloud. To implement test virtualization, use:

  • Rational Test Workbench to capture and model virtual services
  • Rational Test Virtualization Server to manage the virtual services.

Use IBM Worklight to develop mobile applications

IBM Worklight is a development environment for mobile applications. It includes Worklight Studio for code development, Worklight Server to integrate with back-end services, Worklight Runtime Components, and Worklight Console. Worklight adapters form the transport layer Worklight Server uses to connect to various back-end systems.

Each Worklight adapter consists of:

  • An XML file that describes the connectivity options and lists the procedures exposed to the application or to other adapters.
  • A JavaScript file that contains the implementation of procedures declared in the XML file.
  • Zero or more XSL files that contain a transformation scheme for retrieved raw XML data.

Data retrieved by an adapter is as raw data or as data that is preprocessed by the adapter itself. In both cases, it is presented to the application as a JSON object.


Develop a scenario with Rational Quality Manager mobile client

An IBM® Rational® Quality Manager mobile client is a mobile application developed using the Worklight Integrated Development Environment (IDE). The mobile client has two components: a user interface and a Worklight adapter.

With the user interface, a tester can log in to the Rational Quality Manager server and get the project areas and retrieve the test execution records for a chosen project. In this case, the project is Testing Purposes Only 2 – CLM 2012 (Quality Management). The user interface connects to the Rational Quality Manager server through an adapter running on the Worklight server. This adapter uses REST APIs to communicate with the Rational Quality Manager server to retrieve data and to channel the data to the user interface.

The Rational Quality Manager Worklight adapter is a transport layer that you can use to configure the connection details and methods to retrieve the required data. These details are provided in a configuration file called adapter.xml. In this case, the file name is RQMAdapter.xml.

Specify configuration details in the file RQMAdapter.xml

The usual configuration details for the adapter are shown in Listing 1:

Listing 1. Configuration details for RQMAdapter.xml
	<displayName>RQMAdapter</displayName>
	<description>HTTP type Worklight Adapter for jazz server</description>
		<connectivity>
		<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
		<protocol>https</protocol>
		<domain>jazz.net</domain>
		<port>443</port>
	   	</connectionPolicy>
	<loadConstraints maxConcurrentConnectionsPerNode="2" />
	</connectivity>

Update the following values to match your configuration:

  • jazz.net: Public URI where the Rational Quality Manager and Jazz servers are deployed.
  • https: https: Secured http protocol used for authentication
  • 443: Secured port used by the Jazz server

Capture procedure details in the file RQMAdapter.xml

The RQMAdapter.xml file captures procedures to authenticate to the Rational Quality Manager server, to get the project areas from the service catalog, and to get the test execution records for a specified project, as shown in Listing 2:

Listing 2. Procedure details in RQMAdapter.xml
<procedure name="loginToRQM" />
<procedure name="fetchServiceCatalogXML" />
<procedure name="getAllTERs" />

Authenticate with the function loginToRQM

The first step is to authenticate to the Rational Quality Manager server with a username and password. Listing 3, the loginToRQM procedure posts these credentials for Jazz authentication to the URL jazz/auth/j_security_check using the POST method.

Listing 3. loginToRQM function
function loginToRQM(username, passwd) {                                                                
	var lpath = 'jazz/auth/j_security_check';
	var input = {
		method : 'post',
		returnedContentType : 'html',
		path : lpath,
		parameters : {
			j_password : passwd,
			j_username : username
		};
}

Retrieve project areas with the function fetchServiceCatalogXML

After you have successfully authenticated, use the fetchServiceCatalologXML function to retrieve a list of project areas where the user, represented by the username, is a member. Listing 4, the fetchServiceCatalogXML function retrieves these project areas at the URL /qm/oslc_qm/catalog using the GET method.

Listing 4. fetchServiceCatalogXML function
function fetchServiceCatalogXML(catalogPath) {
// catalogPath = '/qm/oslc_qm/catalog'
            var input = {
		method : 'get',
		returnedContentType : 'xml',
		path : catalogPath,
	};
	var response = WL.Server.invokeHttp(input);
	return response;
}

Retrieve test execution records with the function getAllTERs

The getAllTERS function uses the GET method to retrieve the test execution records in the project area Testing+Purposes+Only+2+-+CLM+2012 at the URL qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Testing+Purposes+Only+2+-+CLM+2012/executionworkitem/, as shown in Listing 5.

Listing 5. getALLTERs function

Click to see code listing

Listing 5. getALLTERs function

function getAllTERs() {
	var cpath = 	"qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Testing+Purposes+Only+2+-+CLM+2012/executionworkitem/";
	var input = {
		method : 'get',
		path : cpath
	 body : {
	contentType : 'text/xml; charset=utf-8'
	}
	};
	return WL.Server.invokeHttp(input);
}

Get data from back-end services with RQMLight.js

The Rational Quality Manager mobile client user interface is a mobile application that invokes functions to log in to back-end services and to get the data from back-end services. The client is implemented using JavaScript -- RQMLight.js in this case, which has functions similar to RQMadapter, as shown in Listing 6.

Listing 6. RQMLight.js functions

Click to see code listing

Listing 6. RQMLight.js functions

//Function to login to Rational Quality Manager Server
function loginToRQM(uname, pword, adapterName) {
	/* set adapter for RQM repository */
	RQM_ADAPTER = adapterName;
 	var invocationData = {
		adapter : RQM_ADAPTER,
		procedure : ADAPTER_PROC1,
		parameters : [ uname, pword ]
	};

	WL.Client.invokeProcedure(invocationData, {
		onSuccess : loginFormSuccessHandler.bind(this),
		onFailure : loginFormFailureHandler.bind(this),
		timeout : 50000
	});

//Function to get the service catalog that contains the project areas
function discoverServices() {
	var cmCatalogURL = "/qm/oslc_qm/catalog";
	var invocationData = {
		adapter : RQM_ADAPTER,
		procedure : ADAPTER_PROC6,
		parameters : [ cmCatalogURL ]
	};

	WL.Client.invokeProcedure(invocationData, {
		onSuccess : discoverServicesSuccessHandler.bind(this),
		onFailure : discoverServicesFailureHandler.bind(this),
		timeout : 30000
	});
}

//Function to parse service catalog
function serviceCatalogSuccessHandler(response) {
	var serviceProviderURLPattern = /(_.+?)\/?$/;
	var serviceProviderURLMatcher;
	var serviceCatalogJsonObj = response.invocationResult;
	var serviceCatalogEntryArr = serviceCatalogJsonObj['ServiceProviderCatalog']['entry'];
	for ( var iter = 0; iter < serviceCatalogEntryArr.length; iter++) {
		var serviceProviderMap = serviceCatalogEntryArr[iter]['ServiceProvider'];
		var serviceProviderTitle = serviceProviderMap['title'];
		var serviceProviderURL = serviceProviderMap['details']['resource'];
		serviceProviderURLMatcher = serviceProviderURLPattern
				.exec(serviceProviderURL);
		projectAreaInfoMap[serviceProviderTitle] = serviceProviderURLMatcher[1];
jq("#projectAreas").append(
				"<option value=\"" + serviceProviderTitle + "\" >"
						+ serviceProviderTitle + "</option>");

//Function to get the test execution records in a specified project area
function getAllTERs() {
	var cpath = "qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Testing+Purposes+Only+2+-+CLM+2012/executionworkitem/";
	var winput = {
		method : 'get',
		path : cpath
	body : {
	contentType : 'text/xml; charset=utf-8'
	 }
	};
	return WL.Server.invokeHttp(winput);
}

Figure 1 shows the interactions between the Rational Quality Manager client, the Rational Quality Manager adapter, and the Rational Quality Manager server.

Figure 1. Rational Quality Manager client, server, and adapter interactions
Workflow across clients and servers

Build the scenario in IBM Rational Test Workbench

The first step is to design a service component in Rational Integration Tester with two operations: discoverServices and getAllTERs. Using these operations, the virtual services called stubs are created and published to Rational Test Virtualization Server and deployed into a specific domain. When the stubs start with the Rational Test Control Panel, they are available to applications.

Design a service component in Rational Integration Tester

Figure 2 shows the service component and the respective physical view in Rational Integration Tester.

Figure 2. Rational Quality Manager service component and physical view in Rational Integration Tester
discoverServices and getALLTERs feed into localhost

Run the stubs over an HTTP proxy in Rational Integration Tester

The HTTP proxy provided with Rational Integration Tester runs the stubs over HTTP. The proxy can be viewed as an agent in Rational Control Panel, registered with port 3128. Applications that send messages to stubs must be configured to go through the proxy. If you use Rational Integration Tester to test the stubs, enter the HTTP proxy settings in the Client tab of the HTTP connection for the web server. To get to these settings, right-click localhost or your web server. Enter the details for the server and client in the dialog boxes, as shown in Figure 3.

Figure 3. Configure the proxy settings for httpclient
Specify proxy host and port on the Client tab

Configure the discoverServices operation

To configure the properties for the discoverServices operation, double-click discoverServices from within the service component. As shown in Figure 4, on the Message Exchange Pattern tab, the Pattern field should be set to Request/Reply. On the Request line, click Browse to open the Select Schema dialog. Select a schema for messages.

Figure 4. Configure the schema and pattern for discoverServices
Select schema with REST schemas to choose from

In the Select a Schema dialog, select the REST option and click the new URL button (highlighted in red on the toolbar) to import a REST schema. When the URL dialog opens, click Import URL Template and enter /qm/oslc_qm/catalog as the Importing URL, as shown in Figure 5.

Figure 5. Import URL template for the schema for discoverServices
Fields to specify URLs and literals to separate on

After you specify the importing URL, click OK. The Edit URL Template dialog opens. In the Template Name field, type discoverServices, as shown in Figure 6.

Figure 6. Edit URL Template dialog box
Fields for template name, parameterized URL, path segments

To add discoverServices as a new schema name, click OK, as shown in Figure 7.

Figure 7. discoverServices added as an internal schema
REST schemas now include discoverServices

To add discoverServices as a schema name in the Request field, click Finish. In the Reply field, select xml:Element in the Root field, as shown in Figure 8.

Figure 8. Configure Request and Reply fields for discoverServices
Message exchange pattern tab of discoverServices

Using the same process, add a schema for the getAllTERs operation using the URL, qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/Testing+Purposes+Only+2+-+CLM+2012/executionworkitem/, as shown in Figure 9.

Figure 9. Configure properties for getALLTERs
Specify getALLTERs for Request and xml.Element for Reply

Develop the discoverServices stub

In the Test Factory Logical view of Rational Integration Tester, right click discoverServices. Select New>Stubs>Stub using MEP. In the Create new Stub dialog that opens, specify the name for the stub as discoverServicesStub, as shown in Figure 10.

Figure 10. Create new Stub from MEP dialog box
Type discoverServicesStub in Name field

Open the stub editor for discoverServices and the Input Message Body is set as /qm/oslc_qm/catalog. Enter /qm/oslc_qm/catalog as the URL in the Message Header, as shown in Figure 11.

Figure 11. Specify the message header and message body for discoverServices
discoverServices stub Input tab

In the stub editor for discoverServices, copy the XML that contains the catalog details of the Rational Quality Manager server to the Output tab under the Message section, as shown in Figure 12. This message is returned by the stub when the request for Catalog is received.

Figure 12. Output tab of discoverServicesStub
Messages and values for output
Listing 7. Example of discoverServicesStub message output

Click to see code listing

Listing 7. Example of discoverServicesStub message output

<?xml version="1.0" encoding="UTF-8"?><oslc_disc:ServiceProviderCatalog xmlns:oslc_disc="http://open-services.net/xmlns/discovery/1.0/" rdf:about="https://jazzdev.torolab.ibm.com:9443/qm/oslc_qm/catalog" xmlns="http://purl.org/dc/elements/1.1/" xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/" xmlns:dc="http://purl.org/dc/terms/" xmlns:jpres="http://jazz.net/xmlns/prod/jazz/presentation/1.0/" xmlns:jproc="http://jazz.net/xmlns/prod/jazz/process/1.0/" xmlns:ns3="http://open-services.net/ns/core#" xmlns:ns5="http://open-services.net/ns/qm#" xmlns:ns8="http://jazz.net/ns/qm/rqm#" xmlns:oslc_qm="http://open-services.net/xmlns/qm/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   <dc:title>RQM Quality Management Service Provider Catalog</dc:title>
   <oslc_disc:entry>
      <oslc_disc:ServiceProvider>
         <dc:title>Jazz Collaborative ALM (QM)</dc:title>
         <oslc_disc:details rdf:resource="https://jazz.net/qm/process/project-areas/_lOUgkJ5fEd-SNKZzk9mZxQ"/>
         <oslc_disc:services rdf:resource="https://jazz.net/qm/oslc_qm/contexts/_lOUgkJ5fEd-SNKZzk9mZxQ/services.xml"/>
         <jproc:consumerRegistry rdf:resource="https://jazz.net/qm/process/project-areas/_lOUgkJ5fEd-SNKZzk9mZxQ/links"/>
      </oslc_disc:ServiceProvider>
   </oslc_disc:entry>
   <oslc_disc:entry>
      <oslc_disc:ServiceProvider>
         <dc:title>Rational Team Concert (QM)</dc:title>
         <oslc_disc:details rdf:resource="https://jazz.net/qm/process/project-areas/_e2-coJ5iEd-SNKZzk9mZxQ"/>
         <oslc_disc:services rdf:resource="https://jazz.net/qm/oslc_qm/contexts/_e2-coJ5iEd-SNKZzk9mZxQ/services.xml"/>
         <jproc:consumerRegistry rdf:resource="https://jazz.net/qm/process/project-areas/_e2-coJ5iEd-SNKZzk9mZxQ/links"/>
      </oslc_disc:ServiceProvider>
   </oslc_disc:entry>
   <oslc_disc:entry>
      <oslc_disc:ServiceProvider>
         <dc:title>Jazz Foundation (QM)</dc:title>
         <oslc_disc:details rdf:resource="https://jazz.net/qm/process/project-areas/_op9jIJ8yEd-SNKZzk9mZxQ"/>
         <oslc_disc:services rdf:resource="https://jazz.net/qm/oslc_qm/contexts/_op9jIJ8yEd-SNKZzk9mZxQ/services.xml"/>
         <jproc:consumerRegistry rdf:resource="https://jazz.net/qm/process/project-areas/_op9jIJ8yEd-SNKZzk9mZxQ/links"/>
      </oslc_disc:ServiceProvider>
   </oslc_disc:entry>
   <oslc_disc:entry>
      <oslc_disc:ServiceProvider>
         <dc:title>Testing Purposes Only 2 - CLM 2012 (Quality Management)</dc:title>
         <oslc_disc:details rdf:resource="https://jazz.net/qm/process/project-areas/_C1_L14ZiEeGGGbas5O0s4A"/>
         <oslc_disc:services rdf:resource="https://jazz.net/qm/oslc_qm/contexts/_C1_L14ZiEeGGGbas5O0s4A/services.xml"/>
         <jproc:consumerRegistry rdf:resource="https://jazz.net/qm/process/project-areas/_C1_L14ZiEeGGGbas5O0s4A/links"/>
      </oslc_disc:ServiceProvider>
   </oslc_disc:entry>
</oslc_disc:ServiceProviderCatalog>

Now publish the stubs to the Rational Test Virtualization Server. Right-click the Stubs folder and select Publish stub. The Publish Stubs dialog opens, with the default domain and the environment RQMEnv selected. Click Publish to publish to the server, as shown in Figure 13. Follow similar steps to create the getAllTERs stub.

Figure 13. Publish Stubs dialog box
RQMEnv environment checked, 1 stub to be published

Run stubs in Rational Test Virtualization Server

Start the browser and connect to http://localhost:7819/RTCP. Click the VIE menu to display the stubs under the RQM Service Component, as shown in Figure 14. To run the stub, right-click the stub, and select Start stub.

Figure 14. RQMEnv tab in the Rational Test Control Panel
discoverServices and getALLTERs stubs in the list

Modify the Worklight Rational Quality Manager adapter connectivity option

The stubs are now ready to integrate with the Worklight Rational Quality Manager adapter. You need to modify the connectivity options to include the HTTP proxy details. This is shown in Listing 8.

Listing 8. RQMAdapter connectivity options
<displayName>RQMAdapter</displayName>
	<description>HTTP type Worklight Adapter for jazz server</description>
	<connectivity>
		<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
			<protocol>http</protocol>
			<domain>localhost</domain>
			<proxy>
			<protocol>http</protocol>
			<domain>localhost</domain>
			<port>3128</port>
			</proxy>
	    </connectionPolicy>
		<loadConstraints maxConcurrentConnectionsPerNode="2" />
	</connectivity>

Replace the following values:

  • localhost: localhost or URI where the HTTP proxy is deployed
  • http: HTTP protocol used for connecting to the HTTP proxy
  • 3128: Port used by the HTTP proxy

Redeploy the Worklight Rational Quality Manager adapter in the Worklight console. Refresh the Worklight console to view the updated connection details for the HTTP proxy. The mobile application is now integrated with the stubs. Rerun the mobile application and you can log into Rational Quality Server to retrieve project areas and test execution records.


Summary

The process to develop stubs is labor intensive. This article provided you with simple steps to implement and deploy stubs for REST APIs. The steps are illustrated with a scenario using Rational Quality Manager REST APIs to retrieve project areas and associated test execution. Similar processes can be used for any other REST services.

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, Mobile development
ArticleID=960348
ArticleTitle=How to test mobile applications with Rational Test Virtualization Server
publish-date=01212014