* @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()));
// the name of the test case is not always in the same parameter
String testCaseName = getString(map, TestLinkResponseParams.TCASE_NAME.toString());
if (testCaseName == null) {
testCaseName = getString(map, TestLinkResponseParams.NAME.toString());
}
testCase.setName(testCaseName);
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,
// 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);
}
}
}
}