Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;
import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus;
import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionType;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkParams;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkResponseParams;
import br.eti.kinoshita.testlinkjavaapi.model.Attachment;
import br.eti.kinoshita.testlinkjavaapi.model.Build;
import br.eti.kinoshita.testlinkjavaapi.model.CustomField;
import br.eti.kinoshita.testlinkjavaapi.model.Execution;
import br.eti.kinoshita.testlinkjavaapi.model.Platform;
import br.eti.kinoshita.testlinkjavaapi.model.ReportTCResultResponse;
import br.eti.kinoshita.testlinkjavaapi.model.Requirement;
import br.eti.kinoshita.testlinkjavaapi.model.Role;
import br.eti.kinoshita.testlinkjavaapi.model.TestCase;
import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep;
import br.eti.kinoshita.testlinkjavaapi.model.TestPlan;
import br.eti.kinoshita.testlinkjavaapi.model.TestProject;
import br.eti.kinoshita.testlinkjavaapi.model.TestSuite;
import br.eti.kinoshita.testlinkjavaapi.model.User;
/**
* Utility class with methods to handle the response or prepare the request to the PHP XML-RPC API. This class is able
* to convert from a Map to an Object and vice-versa.
*
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 1.9.0-1
*/
public final class Util {
private static final Logger LOG = Logger.getLogger(Util.class.getName());
public static final Object[] EMPTY_ARRAY = new Object[0];
public static final Map EMPTY_MAP = new HashMap();
private Util() {
}
/**
* @param project
* @return Map of Test Project
*/
public static final Map getTestProjectMap(TestProject project) {
Map executionData = new HashMap();
executionData.put(TestLinkParams.TEST_PROJECT_NAME.toString(), project.getName());
executionData.put(TestLinkParams.TEST_CASE_PREFIX.toString(), project.getPrefix());
executionData.put(TestLinkParams.NOTES.toString(), project.getNotes());
Map options = new HashMap();
options.put(TestLinkParams.ENABLE_REQUIREMENTS.toString(), project.isEnableRequirements());
options.put(TestLinkParams.ENABLE_TEST_PRIORITY.toString(), project.isEnableTestPriority());
options.put(TestLinkParams.ENABLE_AUTOMATION.toString(), project.isEnableAutomation());
options.put(TestLinkParams.ENABLE_INVENTORY.toString(), project.isEnableInventory());
executionData.put(TestLinkParams.OPTIONS.toString(), options);
executionData.put(TestLinkParams.ACTIVE.toString(), project.isActive());
executionData.put(TestLinkParams.PUBLIC.toString(), project.isPublic());
return executionData;
}
/**
* Extracts a Test Project from a Map.
*
* @param map Map with properties of a Test Project.
* @return Test Project.
*/
@SuppressWarnings("unchecked")
public static final TestProject getTestProject(Map map) {
TestProject testProject = null;
if (map != null && map.size() > 0) {
Object o = map.get(TestLinkResponseParams.ID.toString());
if (o != null) {
Integer id = Integer.parseInt(o.toString());
if (id > 0) {
testProject = new TestProject();
testProject.setId(id);
testProject.setName(getString(map, TestLinkResponseParams.NAME.toString()));
testProject.setPrefix(getString(map, TestLinkResponseParams.PREFIX.toString()));
testProject.setNotes(getString(map, TestLinkResponseParams.NOTES.toString()));
Map optMap = (Map) map.get(TestLinkResponseParams.OPT.toString());
testProject.setEnableAutomation(getBoolean(optMap,
TestLinkResponseParams.AUTOMATION_ENABLED.toString()));
testProject.setEnableRequirements(getBoolean(optMap,
TestLinkResponseParams.REQUIREMENTS_ENABLED.toString()));
testProject.setEnableTestPriority(getBoolean(optMap,
TestLinkResponseParams.TEST_PRIORITY_ENABLED.toString()));
testProject.setEnableInventory(getBoolean(optMap,
TestLinkResponseParams.INVENTORY_ENABLED.toString()));
testProject.setActive(getBoolean(map, TestLinkResponseParams.ACTIVE.toString()));
testProject.setPublic(getBoolean(map, TestLinkResponseParams.IS_PUBLIC.toString()));
}
}
}
return testProject;
}
/**
* @param map
* @param key
* @return Boolean value.
*/
public static Boolean getBoolean(Map map, String key) {
Boolean booleanObj = null;
Integer integer = getInteger(map, key);
if (integer != null) {
if (integer == 0) {
booleanObj = Boolean.FALSE;
} else {
booleanObj = Boolean.TRUE;
}
}
return booleanObj;
}
/**
* @param map
* @param key
* @return String value.
*/
public static final String getString(Map map, String key) {
String string = null;
if (map != null && map.size() > 0) {
Object o = map.get(key);
if (o != null) {
string = o.toString();
}
}
return string;
}
/**
* @param map
* @param key
* @return Integer value.
*/
public static final Integer getInteger(Map map, String key) {
Integer integer = null;
if (map != null && map.size() > 0) {
Object o = map.get(key);
if (o != null) {
try {
integer = Integer.parseInt(o.toString());
} catch (NumberFormatException nfe) {
integer = null;
}
}
}
return integer;
}
/**
* @param plan
* @return Map of Test Plan.
*/
public static final Map getTestPlanMap(TestPlan plan) {
Map executionData = new HashMap();
executionData.put(TestLinkParams.TEST_PLAN_NAME.toString(), plan.getName());
executionData.put(TestLinkParams.TEST_PROJECT_NAME.toString(), plan.getProjectName());
executionData.put(TestLinkParams.NOTES.toString(), plan.getNotes());
executionData.put(TestLinkParams.ACTIVE.toString(), plan.isActive());
executionData.put(TestLinkParams.PUBLIC.toString(), plan.isPublic());
return executionData;
}
/**
* @param map
* @return Test Plan.
*/
public static final TestPlan getTestPlan(Map map) {
TestPlan testPlan = null;
if (map != null && map.size() > 0) {
Object o = map.get(TestLinkResponseParams.ID.toString());
if (o != null) {
Integer id = Integer.parseInt(o.toString());
if (id > 0) {
testPlan = new TestPlan();
testPlan.setId(id);
testPlan.setName(getString(map, TestLinkResponseParams.NAME.toString()));
testPlan.setProjectName(getString(map, TestLinkResponseParams.PROJECT_NAME.toString()));
testPlan.setNotes(getString(map, TestLinkResponseParams.NOTES.toString()));
testPlan.setActive(getBoolean(map, TestLinkResponseParams.ACTIVE.toString()));
testPlan.setPublic(getBoolean(map, TestLinkResponseParams.IS_PUBLIC.toString()));
}
}
}
return testPlan;
}
/**
* @param map
* @return Platform.
*/
public static final Platform getPlatform(Map map) {
Platform platform = null;
if (map != null && map.size() > 0) {
Object o = map.get(TestLinkResponseParams.ID.toString());
if (o != null) {
Integer id = Integer.parseInt(o.toString());
if (id > 0) {
platform = new Platform();
platform.setId(id);
platform.setName(getString(map, TestLinkResponseParams.NAME.toString()));
platform.setNotes(getString(map, TestLinkResponseParams.NOTES.toString()));
}
}
}
return platform;
}
/**
* @param testCase
* @return Map of Test Case.
*/
public static final Map getTestCaseMap(TestCase testCase) {
Map executionData = new HashMap();
executionData.put(TestLinkParams.TEST_CASE_NAME.toString(), testCase.getName());
executionData.put(TestLinkParams.TEST_SUITE_ID.toString(), testCase.getTestSuiteId());
executionData.put(TestLinkParams.TEST_PROJECT_ID.toString(), testCase.getTestProjectId());
executionData.put(TestLinkParams.AUTHOR_LOGIN.toString(), testCase.getAuthorLogin());
executionData.put(TestLinkParams.SUMMARY.toString(), testCase.getSummary());
List