phpDocumentor TestlinkAPI
[ class tree: TestlinkAPI ] [ index: TestlinkAPI ] [ all elements ]

java client sample

  1. package org.testlink.api.client.sample;
  2.  
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.util.ArrayList;
  6. import java.util.Hashtable;
  7. import java.util.Map;
  8.  
  9. import org.apache.xmlrpc.XmlRpcException;
  10. import org.apache.xmlrpc.client.XmlRpcClient;
  11. import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
  12.  
  13. public class TestlinkAPIXMLRPCClient 
  14. {        
  15.     // Substitute your Dev Key Here
  16.     public static final String DEV_KEY =  "f2a979d533cdd9761434bba60a88e4d8";
  17.     // Substitute your Server URL Here
  18.     public static final String SERVER_URL = "http://qa/testlink_sandbox/api/xmlrpc.php";    
  19.     
  20.     /**
  21.      * report test execution to TestLink API
  22.      * 
  23.      * @param int tcid
  24.      * @param int tpid
  25.      * @param String status
  26.      */
  27.     public static void testLinkReport(int tcid, int tpid, String status)
  28.     {
  29.         try 
  30.         {
  31.             XmlRpcClient rpcClient;
  32.             XmlRpcClientConfigImpl config;
  33.             
  34.             config = new XmlRpcClientConfigImpl();
  35.             config.setServerURL(new URL(SERVER_URL));
  36.             rpcClient = new XmlRpcClient();
  37.             rpcClient.setConfig(config);        
  38.             
  39.             ArrayList<Object> params = new ArrayList<Object>();
  40.             Hashtable<String, Object> executionData = new Hashtable<String, Object>();                
  41.             executionData.put("devKey", DEV_KEY);
  42.             executionData.put("tcid", tcid);
  43.             executionData.put("tpid", tpid);
  44.             executionData.put("status", status);
  45.             params.add(executionData);
  46.             
  47.             Object[] result = (Object[]) rpcClient.execute("tl.reportTCResult", params);
  48.  
  49.             // Typically you'd want to validate the result here and probably do something more useful with it
  50.             System.out.println("Result was:\n");                
  51.             for (int i=0; i< result.length; i++)
  52.             {
  53.                 Map item = (Map)result[i];
  54.                 System.out.println("Keys: " + item.keySet().toString() + " values: " + item.values().toString());
  55.             }
  56.         }
  57.         catch (MalformedURLException e)
  58.         {
  59.             e.printStackTrace();
  60.         }
  61.         catch (XmlRpcException e)
  62.         {
  63.             e.printStackTrace();
  64.         }
  65.     }
  66.         
  67.     public static void main(String[] args) 
  68.     {
  69.         // Substitute this for a valid tcid and tpid within your project
  70.         TestlinkAPIXMLRPCClient.testLinkReport(1132, 56646, "p");        
  71.     }
  72. }

Documentation generated on Fri, 17 Feb 2012 16:07:50 -0500 by phpDocumentor 1.4.4