Skip to content

Commit

Permalink
ZEPHYR-28162
Browse files Browse the repository at this point in the history
  • Loading branch information
pv-smartbear committed Jan 23, 2020
1 parent 56f578b commit 6b51f5f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/thed/service/TestStepService.java
Expand Up @@ -11,6 +11,14 @@
*/
public interface TestStepService extends BaseService {

/**
* Get testStep for for given testcaseVersionId.
* @param testcaseVersionId
* @return
* @throws URISyntaxException
*/
TestStep getTestStep(Long testcaseVersionId) throws URISyntaxException;

/**
* Add testStep to single testcase.
* @param testStep
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/thed/service/ZephyrRestService.java
Expand Up @@ -186,6 +186,14 @@ public interface ZephyrRestService {
*/
List<Attachment> addAttachment(List<Attachment> attachments) throws URISyntaxException;

/**
* Get testStep for for given testcaseVersionId.
* @param testcaseVersionId
* @return
* @throws URISyntaxException
*/
TestStep getTestStep(Long testcaseVersionId) throws URISyntaxException;

/**
* Add testStep to single testcase.
* @param testStep
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/thed/service/impl/TestStepServiceImpl.java
Expand Up @@ -16,6 +16,11 @@ public TestStepServiceImpl() {
super();
}

@Override
public TestStep getTestStep(Long testcaseVersionId) throws URISyntaxException {
return zephyrRestService.getTestStep(testcaseVersionId);
}

@Override
public TestStep addTestStep(TestStep testStep) throws URISyntaxException {
return zephyrRestService.addTestStep(testStep);
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/thed/service/impl/ZephyrRestServiceImpl.java
Expand Up @@ -52,8 +52,9 @@ public class ZephyrRestServiceImpl implements ZephyrRestService {
public static final String UPLOAD_ATTACHMENT_URL = "/flex/upload/document/genericattachment";
public static final String ADD_ATTACHMENT_URL = "/flex/services/rest/{restVersion}/attachment/list";

public static final String ADD_TESTSTEP_URL = "/flex/services/rest/{restVersion}/testcase/{testcaseVersionId}/teststep/{tctId}";
public static final String ADD_TESTSTEP_RESULT_URL = "/flex/services/rest/{restVersion}/execution/teststepresult/saveorupdate";
public static final String GET_TEST_STEP_URL = "/flex/services/rest/{restVersion}/testcase/{testcaseVersionId}/teststep";
public static final String ADD_TEST_STEP_URL = "/flex/services/rest/{restVersion}/testcase/{testcaseVersionId}/teststep/{tctId}";
public static final String ADD_TEST_STEP_RESULT_URL = "/flex/services/rest/{restVersion}/execution/teststepresult/saveorupdate";

public static final String GET_ALL_PARSER_TEMPLATES_URL = "/flex/services/rest/{restVersion}/parsertemplate/";
public static final String GET_PARSER_TEMPLATE_BY_ID_URL = "/flex/services/rest/{restVersion}/parsertemplate/{id}";
Expand Down Expand Up @@ -396,19 +397,28 @@ public List<Attachment> addAttachment(List<Attachment> attachments) throws URISy
return gson.fromJson(res, type);
}

@Override
public TestStep getTestStep(Long testcaseVersionId) throws URISyntaxException {
Map<String, String> pathParams = new HashMap<>();
pathParams.put("testcaseVersionId", testcaseVersionId.toString());
String url = buildUrl(prepareUrl(GET_TEST_STEP_URL), pathParams, null);
String res = httpClientService.getRequest(url);
return gson.fromJson(res, TestStep.class);
}

@Override
public TestStep addTestStep(TestStep testStep) throws URISyntaxException {
Map<String, String> pathParams = new HashMap<>();
pathParams.put("testcaseVersionId", testStep.getTcId().toString());
pathParams.put("tctId", testStep.getTctId().toString());
String url = buildUrl(prepareUrl(ADD_TESTSTEP_URL), pathParams, null);
String url = buildUrl(prepareUrl(ADD_TEST_STEP_URL), pathParams, null);
String res = httpClientService.postRequest(url, gson.toJson(testStep));
return gson.fromJson(res, TestStep.class);
}

@Override
public List<TestStepResult> addTestStepsResults(List<TestStepResult> testStepResults) throws URISyntaxException {
String url = buildUrl(prepareUrl(ADD_TESTSTEP_RESULT_URL), null, null);
String url = buildUrl(prepareUrl(ADD_TEST_STEP_RESULT_URL), null, null);
String res = httpClientService.postRequest(url, gson.toJson(testStepResults));
Type type = new TypeToken<List<TestStepResult>>(){}.getType();
return gson.fromJson(res, type);
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/thed/zephyr/jenkins/reporter/ZeeDescriptor.java
Expand Up @@ -395,10 +395,23 @@ public ListBoxModel doFillCycleDurationItems(

public ListBoxModel doFillParserTemplateKeyItems(@QueryParameter String parserTemplateKey) throws URISyntaxException {
ListBoxModel listBoxModel = new ListBoxModel();
List<ParserTemplate> templates = parserTemplateService.getAllParserTemplates();
for (ParserTemplate template : templates) {
listBoxModel.add(template.getName(), template.getId().toString());
}

//todo: uncomment these changes before release
// List<ParserTemplate> templates = parserTemplateService.getAllParserTemplates();
// for (ParserTemplate template : templates) {
// listBoxModel.add(template.getName(), template.getId().toString());
// }

listBoxModel.add("JUnit", "0");
listBoxModel.add("Cucumber", "1");
listBoxModel.add("TestNG", "2");
listBoxModel.add("Eggplant", "3");
listBoxModel.add("Selenium", "4");
listBoxModel.add("TestComplete", "5");
listBoxModel.add("SoapUI", "6");
listBoxModel.add("Tosca", "7");
listBoxModel.add("UFT", "8");

return listBoxModel;
}

Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/thed/zephyr/jenkins/reporter/ZeeReporter.java
Expand Up @@ -75,6 +75,7 @@ public class ZeeReporter extends Notifier implements SimpleBuildStep {
private ExecutionService executionService = new ExecutionServiceImpl();
private AttachmentService attachmentService = new AttachmentServiceImpl();
private ParserTemplateService parserTemplateService = new ParserTemplateServiceImpl();
private TestStepService testStepService = new TestStepServiceImpl();

@DataBoundConstructor
public ZeeReporter(String serverAddress, String projectKey,
Expand Down Expand Up @@ -114,6 +115,18 @@ public boolean perform(final Run build, final TaskListener listener) throws IOEx
requirementService = new RequirementServiceImpl();
attachmentService = new AttachmentServiceImpl();

String[] parserTemplateArr = new String[] {
"[{ \"status\": \"$testsuite.testcase.failure\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure\", \"statusPassAttachment\": \"classname: $testsuite.testcase:classname \nname: $testsuite.testcase:name \ntime: $testsuite.testcase:time\", \"packageName\": \"$testsuite.testcase:classname\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]",//junit
"[{ \"status\": \"$testsuite.testcase.failure\", \"system-out\": \"$testsuite.testcase.system-out\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure\", \"statusPassAttachment\": \"classname: $testsuite.testcase:classname \nname: $testsuite.testcase:name \ntime: $testsuite.testcase:time\", \"packageName\": \"$testsuite.testcase:classname\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]", //cucumber
"[{ \"status\": \"$testng-results.suite.test.class.test-method:status\", \"statusExistPass\": true, \"statusString\": \"PASS\", \"packageName\": \"$testng-results.suite.test.class:name\", \"skipTestcaseNames\": \"afterMethod,beforeMethod,afterClass,beforeClass,afterSuite,beforeSuite\", \"testcase\" : {\"name\": \"$testng-results.suite.test.class.test-method:name\"}}]", //testng
"[{ \"status\": \"$testsuite.testcase:successes\", \"statusExistPass\": true, \"statusString\": \"1\", \"statusPassAttachment\": \"name: $testsuite.testcase:name \nassertions: $testsuite.testcase:assertions \nsuccesses: $testsuite.testcase:successes \nerrors: $testsuite.testcase:errors \ntime: $testsuite.testcase:time \", \"packageName\": \"$testsuite:name\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}]}]", //eggplant
"[{ \"status\": \"$testsuite.testcase.failure\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure\", \"statusPassAttachment\": \"classname: $testsuite.testcase:classname \nname: $testsuite.testcase:name \ntime: $testsuite.testcase:time\", \"packageName\": \"$testsuite.testcase:classname\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]",//selenium
"[{ \"status\": \"$testsuite.testcase.failure:message\", \"system-out\": \"$testsuite.testcase.system-out\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure:message\", \"statusPassAttachment\": \"classname: $testsuite.testcase:classname \nname: $testsuite.testcase:name \ntime: $testsuite.testcase:time\", \"packageName\": \"$testsuite.testcase:classname\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]", //testcomplete
"[{ \"status\": \"$testsuite.testcase.failure\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure\", \"statusPassAttachment\": \"name: $testsuite.testcase:name \ntime: $testsuite.testcase:time\", \"packageName\": \"$testsuite:name\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite:name.$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]",//soapui
"[{ \"status\": \"$testsuite.testcase.failure\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure\", \"statusPassAttachment\": \"name: $testsuite.testcase:name \ntime: $testsuite.testcase:time \ntimestamp: $testsuite.testcase:timestamp \nlog: $testsuite.testcase:log \", \"packageName\": \"$testsuite:name\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]",//tosca
"[{ \"status\": \"$testsuite.testcase.failure:message\", \"statusExistPass\": false, \"statusString\": null, \"statusFailAttachment\": \"$testsuite.testcase.failure:message\", \"statusPassAttachment\": \"name: $testsuite.testcase:name \nreport: $testsuite.testcase:report \ntime: $testsuite.testcase:time \nclassname: $testsuite.testcase:classname \nstatus: $testsuite.testcase:status \", \"packageName\": \"$testsuite:package\" , \"skipTestcaseNames\": \"\", \"testcase\" : {\"name\": \"$testsuite.testcase:name\"}, \"requirements\": [{\"id\": \"$testsuite.testcase.requirements.requirement\"}], \"attachments\": [{\"filePath\": \"$testsuite.testcase.attachments.attachment\"}]}]"//uft
};

if (!validateBuildConfig()) {
logger.println("Cannot Proceed. Please verify the job configuration");
return false;
Expand All @@ -127,7 +140,9 @@ public boolean perform(final Run build, final TaskListener listener) throws IOEx
zephyrConfigModel.setZephyrProjectId(Long.parseLong(getProjectKey()));
zephyrConfigModel.setReleaseId(Long.parseLong(getReleaseKey()));
zephyrConfigModel.setParserTemplateId(Long.parseLong(getParserTemplateKey()));
zephyrConfigModel.setJsonParserTemplate(parserTemplateService.getParserTemplateById(zephyrConfigModel.getParserTemplateId()).getJsonTemplate());
String jsonTemplate = parserTemplateArr[(int)zephyrConfigModel.getParserTemplateId()];
// zephyrConfigModel.setJsonParserTemplate(parserTemplateService.getParserTemplateById(zephyrConfigModel.getParserTemplateId()).getJsonTemplate());
zephyrConfigModel.setJsonParserTemplate(jsonTemplate);

if (cycleKey.equalsIgnoreCase(NEW_CYCLE_KEY)) {
zephyrConfigModel.setCycleId(NEW_CYCLE_KEY_IDENTIFIER);
Expand Down Expand Up @@ -280,6 +295,11 @@ else if(zephyrConfigModel.getCycleDuration().equals("7 days")) {
TCRCatalogTreeTestcase tcrTestCase = caseEntry.getKey();

//testStepResult handled here
if(tcrTestCase.getTestcase().getTestSteps() == null && testcaseValueMap.containsKey("stepList")) {
//testcase contains no teststeps but we have parsed from xml, this testcase existed before and the teststeps weren't fetched, fetching now
tcrTestCase.getTestcase().setTestSteps(testStepService.getTestStep(tcrTestCase.getTestcase().getId()));
}

if(tcrTestCase.getTestcase().getTestSteps() != null && tcrTestCase.getTestcase().getTestSteps().getSteps() != null) {
List<Map<String, String>> stepList = (List<Map<String, String>>)testcaseValueMap.get("stepList");

Expand Down Expand Up @@ -322,6 +342,10 @@ else if(zephyrConfigModel.getCycleDuration().equals("7 days")) {
//todo:handle exceptions gracefully
e.printStackTrace();
logger.printf("Error uploading test results to Zephyr");
logger.printf(e.getMessage()+"\n");
for(StackTraceElement stackTraceElement : e.getStackTrace()) {
logger.printf(stackTraceElement.toString()+"\n");
}
return false;
}

Expand Down

0 comments on commit 6b51f5f

Please sign in to comment.