When I use the getTestCase method I can’t get the custom fields of the test case:
This is what I get:
TestCase [id=134, name=CdP-OPE06, testSuiteId=6, testProjectId=null, authorLogin=null, summary=<p>prueba</p>, steps=[TestCaseStep [id=136, testCaseVersionId=null, number=1, actions=Go to login screen and enter user credentials., expectedResults=User name appeared in top menu., active=true, executionType=1]], preconditions=<p>prueba</p>, testImportance=null, executionType=1, executionOrder=null, order=10, internalId=null, fullExternalId=Z-51, checkDuplicatedName=null, actionOnDuplicatedName=null, versionId=null, version=1, parentId=null, customFields=[], executionStatus=n, platform=null, featureId=null]
And you can see, in the testlink I have two design custom fields set (Prueba,Prueba2)
Then I found you have comment in the testlinkjava API 1.9.5-0 in the Util.class all the custom fields part:
testCase.setExecutionStatus(executionStatus);
testCase.setTestProjectId(getInteger(map, TestLinkParams.TEST_PROJECT_ID.toString()));
testCase.setTestSuiteId(getInteger(map, TestLinkParams.TEST_SUITE_ID2.toString()));
// inconsistent
// parameter
// name
// TODO: check if TL 2.0 allows it
// CustomField[] customFields = (CustomField[])getArray(map,
// TestLinkResponseParams.customFields.toString());
// if ( customFields != null )
// {
// for (int i = 0; i < customFields.length; i++)
// {
// CustomField customField = customFields[i];
// testCase.getCustomFields().add( customField );
// }
// }
Object[] stepsArray = (Object[]) getArray(map, TestLinkResponseParams.STEPS.toString());
if (stepsArray != null && stepsArray.length > 0) {
for (Object stepObject : stepsArray) {
Map<String, Object> stepMap = (Map<String, Object>) stepObject;
TestCaseStep step = Util.getTestCaseStep(stepMap);
testCase.getSteps().add(step);
}
}
}
So I try do discommended this part and make my own Util.class put it didn’t work, jejejejej.
Then I may be found another bug, it is for getTestCaseCustomFieldDesignValue, it don’t get the value inside the customfield object:
But when I discommended the part inside the util.class, for my surprise I can get the value... see
This is my TestlinkAPI.class:
package com.testselenium.subirtest;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import br.eti.kinoshita.testlinkjavaapi.TestLinkAPI;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkMethods;
import br.eti.kinoshita.testlinkjavaapi.constants.TestLinkParams;
import br.eti.kinoshita.testlinkjavaapi.model.TestCase;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import br.eti.kinoshita.testlinkjavaapi.util.Util;
public class A extends TestLinkAPI {
public A(URL url, String devKey) throws TestLinkAPIException {
super(url, devKey);
}
/**
* Get a test case
*
* @param testCaseId
* @param testCaseExternalId
* @param version
* @return Test Case.
* @throws TestLinkAPIException
*/
public TestCase getTestCase(Integer testCaseId, Integer testCaseExternalId, Integer version, Integer projectId)
throws TestLinkAPIException {
TestCase testCase = null;
try {
Map<String, Object> executionData = new HashMap<String, Object>();
executionData.put(TestLinkParams.TEST_PROJECT_ID.toString(), projectId);
executionData.put(TestLinkParams.TEST_CASE_ID.toString(), testCaseId);
executionData.put(TestLinkParams.TEST_CASE_EXTERNAL_ID.toString(), testCaseExternalId);
executionData.put(TestLinkParams.VERSION.toString(), version);
Object response = this.executeXmlRpcCall(TestLinkMethods.GET_TEST_CASE.toString(), executionData);
// Object response = this.executeXmlRpcCall(TestLinkMethods.GET_TEST_CASE_CUSTOM_FIELD_DESIGN_VALUE.toString(), executionData);
Object[] responseArray = Util.castToArray(response);
Map<String, Object> responseMap = (Map<String, Object>) responseArray[0];
testCase = Util_A.getTestCase(responseMap);
} catch (XmlRpcException xmlrpcex) {
throw new TestLinkAPIException("Error getting test case info : " + xmlrpcex.getMessage(), xmlrpcex);
}
return testCase;
}
}
This is my Testlink util.class
package com.testselenium.subirtest;
import java.util.HashMap;
import java.util.Map;
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.CustomField;
import br.eti.kinoshita.testlinkjavaapi.model.Platform;
import br.eti.kinoshita.testlinkjavaapi.model.TestCase;
import br.eti.kinoshita.testlinkjavaapi.model.TestCaseStep;
import br.eti.kinoshita.testlinkjavaapi.util.Util;
public class Util_A {
public static final Object[] EMPTY_ARRAY = new Object[0];
public static final Map<String, Object> EMPTY_MAP = new HashMap<String, Object>();
/**
* @param map
* @return Test Case.
*/
@SuppressWarnings("unchecked")
public static final TestCase getTestCase(Map<String, Object> map) {
TestCase testCase = null;
if (map != null && map.size() > 0) {
// IMPORTANT: http://mantis.testlink.org/view.php?id=4784
// Different methods to recover test cases use different parameter
// names for the id, some uses "id" and others "testcase_id".
Object o = map.get(TestLinkResponseParams.TEST_CASE_ID.toString());
if (o == null) {
o = map.get(TestLinkResponseParams.ID.toString());
}
if (o != null) {
Integer id = Integer.parseInt(o.toString());
if (id > 0) {
testCase = new TestCase();
testCase.setId(id);
testCase.setVersionId(getInteger(map, TestLinkResponseParams.TEST_CASE_VERSION_ID.toString()));
testCase.setVersion(getInteger(map, TestLinkResponseParams.VERSION.toString()));
testCase.setPreconditions(getString(map, TestLinkResponseParams.PRECONDITIONS.toString()));
testCase.setSummary(getString(map, TestLinkResponseParams.SUMMARY.toString()));
testCase.setParentId(getInteger(map, TestLinkResponseParams.PARENT_ID.toString()));
testCase.setOrder(getInteger(map, TestLinkResponseParams.ORDER.toString()));
testCase.setExecutionOrder(getInteger(map, TestLinkResponseParams.EXECUTION_ORDER.toString()));
testCase.setName(getString(map, TestLinkResponseParams.NAME.toString()));
Platform platform = null;
String platformName = getString(map, TestLinkResponseParams.PLATFORM_NAME.toString());
Integer platformId = getInteger(map, TestLinkResponseParams.PLATFORM_ID.toString());
if (platformName != null || platformId != null) { // sometimes
// TL
// may
// return
// only
// one
// or
// the
// other
platform = new Platform();
platform.setId(platformId);
platform.setName(platformName);
}
testCase.setPlatform(platform);
testCase.setFeatureId(getInteger(map, TestLinkResponseParams.FEATURE_ID.toString()));
// IMPORTANT: the full external id (composed by
// prefix-external_id) come on
// different parameters depending of what methods was used.
//
// In 'getTestCase' -> 'full_tc_external_id'
// In 'getTestCasesForTestSuite' -> 'external_id'
// In 'getTestCasesForTestPlan' does not come (ToDo: add)
String fullExternalId = getString(map, TestLinkResponseParams.FULL_TEST_CASE_EXTERNAL_ID.toString());
if (fullExternalId == null) {
fullExternalId = getString(map, TestLinkResponseParams.FULL_TEST_CASE_EXTERNAL_ID2.toString());
if (fullExternalId == null) {
fullExternalId = getString(map, TestLinkResponseParams.EXTERNAL_ID.toString());
}
}
testCase.setFullExternalId(fullExternalId);
Integer executionTypeValue = getInteger(map, TestLinkResponseParams.EXECUTION_TYPE.toString());
ExecutionType execution = ExecutionType.getExecutionType(executionTypeValue);
testCase.setExecutionType(execution);
ExecutionStatus executionStatus = ExecutionStatus.NOT_RUN;
String executionStatusText = getString(map, TestLinkResponseParams.EXEC_STATUS.toString());
if (StringUtils.isNotBlank(executionStatusText)) {
executionStatus = ExecutionStatus.getExecutionStatus(executionStatusText.charAt(0));
}
testCase.setExecutionStatus(executionStatus);
testCase.setTestProjectId(getInteger(map, TestLinkParams.TEST_PROJECT_ID.toString()));
testCase.setTestSuiteId(getInteger(map, TestLinkParams.TEST_SUITE_ID2.toString()));
// inconsistent
// parameter
// name
// TODO: check if TL 2.0 allows it
CustomField[] customFields = (CustomField[]) getArray(map,
com.testselenium.subirtest.TestLinkResponseParams.CUSTOM_FIELDS.toString());
if (customFields != null) {
for (int i = 0; i < customFields.length; i++) {
CustomField customField = customFields[i];
testCase.getCustomFields().add(customField);
}
}
Object[] stepsArray = (Object[]) getArray(map, TestLinkResponseParams.STEPS.toString());
if (stepsArray != null && stepsArray.length > 0) {
for (Object stepObject : stepsArray) {
Map<String, Object> stepMap = (Map<String, Object>) stepObject;
TestCaseStep step = Util.getTestCaseStep(stepMap);
testCase.getSteps().add(step);
}
}
}
}
}
return testCase;
}
/**
* @param map
* @param key
* @return Integer value.
*/
public static final Integer getInteger(Map<String, Object> 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 map
* @param key
* @return String value.
*/
public static final String getString(Map<String, Object> 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 Array of objects.
*/
public static Object[] getArray(Map<String, Object> map, String key) {
Object[] array = null;
if (map != null && map.size() > 0) {
Object o = map.get(key);
array = castToArray(o);
}
return array;
}
/**
*
* @param object
* @return Array of objects
*/
public static Object[] castToArray(Object object) {
Object[] array = null;
if (object != null) {
if (object instanceof String) {
array = EMPTY_ARRAY;
} else {
array = (Object[]) object;
}
}
return array;
}
I Hope this can help you to fix it, I wil still trying to update design customfields…..
sorry but i cant attach the pics...