All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.eti.kinoshita.testlinkjavaapi.TestPlanService Maven / Gradle / Ivy

There is a newer version: 1.9.20-1
Show newest version
/*
 * The MIT License
 *
 * Copyright (c) <2010> 
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package br.eti.kinoshita.testlinkjavaapi;

import java.util.HashMap;
import java.util.Map;

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

import br.eti.kinoshita.testlinkjavaapi.model.Platform;
import br.eti.kinoshita.testlinkjavaapi.model.TestLinkMethods;
import br.eti.kinoshita.testlinkjavaapi.model.TestLinkParams;
import br.eti.kinoshita.testlinkjavaapi.model.TestLinkResponseParams;
import br.eti.kinoshita.testlinkjavaapi.model.TestPlan;
import br.eti.kinoshita.testlinkjavaapi.util.Util;

/**
 * @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
 * @since 1.9.0-1
 */
class TestPlanService 
extends BaseService
{

	/**
	 * @param xmlRpcClient XML RPC Client.
	 * @param devKey TestLink User DevKey.
	 */
	protected TestPlanService( XmlRpcClient xmlRpcClient, String devKey ) 
	{
		super( xmlRpcClient, devKey );
	}

	@SuppressWarnings("unchecked")
	protected TestPlan createTestPlan(
			String planName,
			String projectName,
			String notes, 
			Boolean isActive,  
			Boolean isPublic) 
	throws TestLinkAPIException
	{
		TestPlan testPlan = null;
		
		Integer id = 0;
		
		testPlan = new TestPlan(
				id,
				planName, 
				projectName, 
				notes, 
				isActive, 
				isPublic);
		
		try
		{
			Map executionData = Util.getTestPlanMap(testPlan);
			Object response = this.executeXmlRpcCall(
					TestLinkMethods.createTestPlan.toString(), executionData);
			Object[] responseArray = (Object[])response;
			Map responseMap = (Map)responseArray[0];
			
			id = Util.getInteger(responseMap, TestLinkResponseParams.id.toString());
			testPlan.setId( id );
		} 
		catch ( XmlRpcException xmlrpcex )
		{
			throw new TestLinkAPIException(
					"Error creating test plan: " + xmlrpcex.getMessage(), xmlrpcex);
		}
		
		return testPlan;
	}
	
	/**
	 * Retrieves a Test Plan by its name. 
	 * 
	 * @param planName Test Plan name.
	 * @param projectName Test Project name.
	 * @return Test Plane.
	 * @throws TestLinkAPIException
	 */
	@SuppressWarnings("unchecked")
	protected TestPlan getTestPlanByName(String planName, String projectName) 
	throws TestLinkAPIException 
	{
		TestPlan testPlan = null;
		
		try
		{
			Map executionData = new HashMap();
			executionData.put(TestLinkParams.testPlanName.toString(), planName);
			executionData.put(TestLinkParams.testProjectName.toString(), projectName);
			Object response = this.executeXmlRpcCall(
					TestLinkMethods.getTestPlanByName.toString(), executionData);
			Object[] responseArray = (Object[])response;
			Map responseMap = (Map)responseArray[0];
			//TBD: check with TL team if we can change it there.
			responseMap.put(TestLinkResponseParams.projectName.toString(), projectName);
			testPlan = Util.getTestPlan( responseMap );
		}
		catch ( XmlRpcException xmlrpcex )
		{
			throw new TestLinkAPIException(
					"Error creating test project: " + xmlrpcex.getMessage(), xmlrpcex);
		}
		
		return testPlan;
	}

	/**
	 * @param planId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected Platform[] getTestPlanPlatforms(Integer planId)
	throws TestLinkAPIException
	{
		Platform[] platforms = null;
		
		try
		{
			Map executionData = new HashMap();
			executionData.put(TestLinkParams.testPlanId.toString(), planId);
			Object response = this.executeXmlRpcCall(
					TestLinkMethods.getTestPlanPlatforms.toString(), executionData);
			Object[] responseArray = (Object[])response;
			platforms = new Platform[responseArray.length];
			for (int i = 0; i < responseArray.length; i++)
			{
				Map projectMap = (Map)responseArray[i];
				Platform platform = Util.getPlatform(projectMap);
				platforms[i] = platform;
			}
			
		}
		catch ( XmlRpcException xmlrpcex )
		{
			throw new TestLinkAPIException(
					"Error retrieving platforms: " + xmlrpcex.getMessage(), xmlrpcex);
		}
		
		return platforms;
	}

	/**
	 * @param testPlanId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	protected Map getTotalsForTestPlan( Integer testPlanId ) 
	throws TestLinkAPIException
	{
		
		Map responseMap = null;
		
		try
		{
			Map executionData = new HashMap();
			executionData.put(TestLinkParams.testPlanId.toString(), testPlanId);
			Object response = this.executeXmlRpcCall(
					TestLinkMethods.getTotalsForTestPlan.toString(), executionData);
			if ( response instanceof Object[] )
			{
				Object[] responseArray = (Object[])response;
				responseMap = ( Map ) responseArray[0];
			} 
			else if ( response instanceof Map )
			{
				responseMap = ( Map ) response;
			}
		}
		catch ( XmlRpcException xmlrpcex )
		{
			throw new TestLinkAPIException(
					"Error retrieving platforms: " + xmlrpcex.getMessage(), xmlrpcex);
		}
		
		return responseMap;
		
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy