From ad3c81f96416af37d9ce901466aa5072e5523d4f Mon Sep 17 00:00:00 2001 From: Maria Pedro Sales Date: Wed, 4 Nov 2020 15:14:51 +0100 Subject: [PATCH] Remove environment. Add env variables Removed environment. Added env variables for TestExecutionId and TestExecutionSummary. --- README.md | 10 +++++++++- src/main/java/org/gauge/xray/ReportGenerator.java | 11 +++++------ src/main/java/org/gauge/xray/Reporter.java | 7 +++++-- src/main/java/org/gauge/xray/report/Info.java | 11 ----------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9339e53..563243b 100755 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ jira_authentication = cookie/basic > Default jira_authentication is cookie if property not provided. +The following env variables are optional, and allow to configure a specific testExecutionId and summary: + +```properties +jira_testExecutionId = JIRA_ID +jira_testExecutionSummary = Expected JIRA issue summary +``` + #### Add **TestCaseId:\** tag to scenarios ```markdown @@ -63,7 +70,8 @@ Tags: TestCaseId:PROJECT-1 #### Reuse Test Execution -In order to avoid creating a new test execution for each run, add **TestExecutionId:\** tag to spec +In order to avoid creating a new test execution for each run, add **TestExecutionId:\** tag to spec. +Note: TestExecutionId defined in the tag will only be used if there was none set in the env variables. ```markdown # Spec diff --git a/src/main/java/org/gauge/xray/ReportGenerator.java b/src/main/java/org/gauge/xray/ReportGenerator.java index 381fda5..8611620 100644 --- a/src/main/java/org/gauge/xray/ReportGenerator.java +++ b/src/main/java/org/gauge/xray/ReportGenerator.java @@ -24,12 +24,12 @@ public final class ReportGenerator { private ReportGenerator() { } - public static List generate(Messages.SuiteExecutionResult suite, String environment) { + public static List generate(Messages.SuiteExecutionResult suite, String jiraTestExecutionId, String jiraTestExecutionSummary) { List reports = new ArrayList(); for (Spec.ProtoSpecResult spec : suite.getSuiteResult().getSpecResultsList()) { Report report = new Report(); - report.setInfo(createInfo(suite.getSuiteResult(), environment)); - report.setTestExecutionKey(getTestExecutionKey(spec)); + report.setInfo(createInfo(suite.getSuiteResult(), jiraTestExecutionSummary)); + report.setTestExecutionKey(jiraTestExecutionId != null ? jiraTestExecutionId : getTestExecutionKey(spec)); for (Spec.ProtoItem scenario : spec.getProtoSpec().getItemsList()) { Test test = createTest(scenario); if (test != null) { @@ -61,11 +61,10 @@ private static Test createTest(Spec.ProtoItem scenario) { return test; } - private static Info createInfo(Spec.ProtoSuiteResult spec, String environment) { + private static Info createInfo(Spec.ProtoSuiteResult spec, String jiraTestExecutionSummary) { Info info = new Info(); - info.setSummary(spec.getProjectName()); + info.setSummary(jiraTestExecutionSummary != null ? jiraTestExecutionSummary : spec.getProjectName()); info.setTestEnvironments(Arrays.asList(spec.getEnvironment().split(","))); - info.setEnvironment(environment); return info; } diff --git a/src/main/java/org/gauge/xray/Reporter.java b/src/main/java/org/gauge/xray/Reporter.java index 01069a3..eed1f98 100644 --- a/src/main/java/org/gauge/xray/Reporter.java +++ b/src/main/java/org/gauge/xray/Reporter.java @@ -56,8 +56,11 @@ public static void main(String[] args) { Message message = Message.parseDelimitedFrom(socket.getInputStream()); if (message.getMessageType() == Message.MessageType.SuiteExecutionResult) { SuiteExecutionResult result = message.getSuiteExecutionResult(); - String environment = getProperty("GAUGE_ENVIRONMENT"); - List reports = ReportGenerator.generate(result, environment); + + String jiraTestExecutionId = getProperty("jira_testExecutionId"); + String jiraTestExecutionSummary = getProperty("jiraTestExecutionSummary"); + + List reports = ReportGenerator.generate(result, jiraTestExecutionId, jiraTestExecutionSummary); Gson gson = new GsonBuilder() .disableHtmlEscaping() .setPrettyPrinting() diff --git a/src/main/java/org/gauge/xray/report/Info.java b/src/main/java/org/gauge/xray/report/Info.java index eeaa6a5..b3f21b6 100644 --- a/src/main/java/org/gauge/xray/report/Info.java +++ b/src/main/java/org/gauge/xray/report/Info.java @@ -39,9 +39,6 @@ public class Info { @SerializedName("testEnvironments") @Expose private List testEnvironments = new ArrayList(); - @SerializedName("environment") - @Expose - private String environment; public String getProject() { return project; @@ -169,13 +166,5 @@ public Info withTestEnvironments(List testEnvironments) { public void addTestEnvironments(String testEnvironment) { this.testEnvironments.add(testEnvironment); } - - public void setEnvironment(String environment) { - this.environment = environment; - } - - public String getEnvironment() { - return environment; - } }