Testopia:Documentation:XMLRPC: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
__NOEDITSECTION__
__NOEDITSECTION__
Back to [[IS&T Engineering Tools]]
Back to the [[Testopia |Testopia Main Page]]


==What's New!==
==What's New!==
{| border=1 cellpadding=4
{| border=1 cellpadding=4
| 2006-09-21 ||  
| 2006-09-21 ||  
* Current "test" environment is https://bugzilla.innerwebtest.novell.com/tr_xmlrpc.cgi
* Added code for <b>SSL (https)</b> access to the Java client (not necessary for Perl client)
* Added code for <b>SSL (https)</b> access to the Java client (not necessary for Perl client)
|-
|-
Line 257: Line 256:
===Objects===
===Objects===


* [[Bugzilla_XML-RPC_API_TestPlan |TestPlan]]
* [[Testopia:Documentation:XMLRPC:TestPlan |TestPlan]]
* [[Bugzilla_XML-RPC_API_TestCase |TestCase]]
* [[Testopia:Documentation:XMLRPC:TestCase |TestCase]]
* [[Bugzilla_XML-RPC_API_TestRun |TestRun]]
* [[Testopia:Documentation:XMLRPC:TestRun |TestRun]]
* [[Bugzilla_XML-RPC_API_TestCaseRun |TestCaseRun]]
* [[Testopia:Documentation:XMLRPC:TestCaseRun |TestCaseRun]]




Line 266: Line 265:


# Where can I find more coding examples?
# Where can I find more coding examples?
#* [[Bugzilla_XML-RPC_API_Code_Examples |Here]].
#* [[Testopia:Documentation:XMLRPC:Code_Examples |Here]].
# Where can I find the query examples again?
# Where can I find the query examples again?
#* [[Bugzilla_XML-RPC_API_Query_Examples |Here]].
#* [[Testopia:Documentation:XMLRPC:Query_Examples |Here]].




 
<br>Back to the [[Testopia |Testopia Main Page]]
 
<br>Back to the [[Wiki_Main_Page#IS&T |Wiki Main Page]]

Revision as of 17:06, 2 October 2006

Back to the Testopia Main Page

What's New!

2006-09-21
  • Added code for SSL (https) access to the Java client (not necessary for Perl client)
2006-09-20
  • Added code for Basic Authorization to the sample clients

Project Description

Provide a means for the programmatic creation, modification, and reporting of inherent Bugzilla Testopia objects, such as test plans, test cases, and test runs. Scope will later expand to cover actual bugs and products.

The API is accessed through XML Remote Procedure Calls (XML-RPC). Bascially, a client creates an XML document and sends it to the Bugzilla server via an HTTP post.

An example of an XML request:

<?xml version="1.0" encoding="UTF-8"?>
   <methodCall>
      <methodName>TestPlan.get</methodName>
      <params>
         <param>
            <value>
               <int>1</int>
            </value>
         </param>
      </params>
   </methodCall> 

An exmple of an XML response:

<?xml version="1.0" encoding="UTF-8"?>
   <methodResponse>
      <params>
         <param>
            <value>
               <struct>
                  <member>
                     <name>author</name>
                     <value>
                        <string>user@company.com</string>
                     </value>
                  </member>
                  <member>
                     <name>editor</name>
                     <value>
                        <string>user@company.com</string>
                     </value>
                  </member>
                  <member>
                     <name>name</name>
                     <value>
                        <string>A Test Plan</string>
                     </value>
                  </member>
                  <member>
                     <name>default_product_version</name>
                     <value>
                        <string>other</string>
                     </value>
                  </member>
                  <member>
                     <name>plan_id</name>
                     <value>
                        <int>1</int>
                     </value>
                  </member>
                  <member>
                     <name>product</name>
                     <value>
                        <string>TestProduct</string>
                     </value>
                  </member>
                  <member>
                     <name>creation_date</name>
                     <value>
                        <string>2006-08-03 13:20:53</string>
                     </value>
                  </member>
                  <member>
                     <name>type</name>
                     <value>
                        <string>Unit</string>
                     </value>
                  </member>
                  <member>
                     <name>isactive</name>
                     <value>
                        <int>1</int>
                     </value>
                  </member>
               </struct>
            </value>
         </param>
      </params>
   </methodResponse>

Getting Started

Requirements

The examples for this project use the following libraries:

Programming Language Software
Perl SOAP::Lite
Java Apache XML-RPC

You can, of course, code the XML document via strings or the Document Object Model (DOM) and then maually do a HTTP post, but why?

Sample Clients

Perl

use SOAP::Transport::HTTP;  # Need for Basic Authorization subroutine
use XMLRPC::Lite;           # From the SOAP::Lite Module
 
my $proxy = XMLRPC::Lite->proxy("http://company.com/bugzilla/tr_xmlrpc.cgi");

# Result is a hash map
my $soapresult = $proxy->call('TestPlan.get', 1);

# Error checking
die_on_fault($soapresult);

# Print each key/value pair 
foreach (keys(%$soapresult)) 
{
	print "$_: $$soapresult{$_}\n";
}

# Add the following subroutine to submit a userid/password for basic authorization
sub SOAP::Transport::HTTP::Client::get_basic_credentials 
{ 
	return 'userid' => 'password';
}

sub die_on_fault 
{
	my $soapresult = shift;

	if ($soapresult->fault) 
	{
		die $soapresult->faultcode . ' ' . $soapresult->faultstring;
	}
}

Java

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

import java.net.URL;
import java.util.HashMap;
import java.util.ArrayList;

// Needed for SSL
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

public class RPCClient
{
 	// 
 	// Trust All Certificates - Needed for SSL Client
 	// 
	private static void TrustAllCerts()
		throws java.security.NoSuchAlgorithmException,
		       java.security.KeyManagementException  
	{
		// Create a trust manager that does not validate certificate chains

		TrustManager[] trustAllCerts = new TrustManager[] 
	    {
	        new X509TrustManager() 
	        {
	            public X509Certificate[] getAcceptedIssuers() 
	            {
	                return null;
	            }
	 
	            public void checkClientTrusted(X509Certificate[] certs, String authType) 
	            {
	                // Trust always
	            }
	 
	            public void checkServerTrusted(X509Certificate[] certs, String authType) 
	            {
	                // Trust always
	            }
	        }
	    };
	 
	    // Install the all-trusting trust manager
	    SSLContext sc = SSLContext.getInstance("SSL");
	    
	    // Create empty HostnameVerifier
	    HostnameVerifier hv = new HostnameVerifier() 
	    {
	    	public boolean verify(String arg0, SSLSession arg1) 
	    	{
	    		return true;
	        }
	    };

	    sc.init(null, trustAllCerts, new java.security.SecureRandom());
	    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
	    HttpsURLConnection.setDefaultHostnameVerifier(hv);
	}
 
	public static void main(String[] args)
	{
 		try
		{
		    TrustAllCerts();

		    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		    config.setServerURL(new URL("http://company.com/bugzilla/tr_xmlrpc.cgi"));
		    config.setBasicUserName("userid");
		    config.setBasicPassword("password");

		    XmlRpcClient client = new XmlRpcClient();
		    client.setConfig(config);

		    ArrayList<Object> params = new ArrayList<Object>();
		    params.add(1);

		    HashMap result = (HashMap) client.execute("TestPlan.get", params);

		    System.out.println(result);
		}
 		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

API Documentation

All XML-RPC requests are sent to a single Bugzilla CGI called tr_xmlprc.cgi. Its locations will be based on your specific Bugzilla installation. Normally the CGI will be found at the root URL of Bugzilla, for example, http://company.com/bugzilla/tr_xmlrpc.cgi

Objects


FAQ

  1. Where can I find more coding examples?
  2. Where can I find the query examples again?



Back to the Testopia Main Page