diff --git a/CHANGELOG.md b/CHANGELOG.md index bf3f821..8a58387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- added "verbose" mode, to debug API requests/responses + ### Fixed ## [0.6.0] - 2022-06-08 diff --git a/README.md b/README.md index 7c47b83..aa7c42e 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ For Xray server/datacenter users (i.e., using Xray on Jira server/datacenter): | `jiraToken` | `xray.jiraToken` | Jira PAT (Personal Access Token) used instead of username/password | | `ignoreSslErrors` | `xray.ignoreSslErrors` | ignore SSL errors, e.g., expired certificate (default: false) | | `timeout` | `xray.timeout` | connection timeout in seconds (default: 50) | +| `verbose` | `xray.verbose` | set to true to enable verbose mode (default: false); information will be visible if running mvn with debug output by using `-X` or `--debug` | true | For Xray cloud users (i.e., using Xray on Jira cloud): @@ -73,6 +74,7 @@ For Xray cloud users (i.e., using Xray on Jira cloud): | `clientId` | `xray.clientId` | client id of the API key configured on Xray Cloud | xxxx... | | `clientSecret` | `xray.clientSecret` | client id of the API key configured on Xray Cloud | xxxx... | | `timeout` | `xray.timeout` | connection timeout in seconds (default: 50) | 50 | +| `verbose` | `xray.verbose` | set to true to enable verbose mode (default: false); information will be visible if running mvn with debug output by using `-X` or `--debug` | true | In order to obtain the API key (client id + client secret pair) please ask you Jira admin (see reference at bottom). There are also task specific configurations. More info ahead, on the respective task section. diff --git a/pom.xml b/pom.xml index 3c99b1b..b677ad1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 app.getxray xray-maven-plugin - 0.6.0 + 0.7.0-SNAPSHOT maven-plugin xray-maven-plugin Maven plugin for interacting with Xray (server/datacenter and cloud), used in CI/CD for assisting in test automation flows, such as reporting test results back to Xray and, by consequence, Jira. diff --git a/src/main/java/app/getxray/maven/plugin/xray/ExportFeaturesMojo.java b/src/main/java/app/getxray/maven/plugin/xray/ExportFeaturesMojo.java index 7d15bdc..94d061c 100644 --- a/src/main/java/app/getxray/maven/plugin/xray/ExportFeaturesMojo.java +++ b/src/main/java/app/getxray/maven/plugin/xray/ExportFeaturesMojo.java @@ -63,6 +63,9 @@ public class ExportFeaturesMojo extends AbstractMojo { @Parameter(property = "xray.timeout", required = false, defaultValue = "50") private Integer timeout; + @Parameter(property = "xray.verbose", required = false) + private Boolean verbose; + /** * Scope to filter the dependencies. */ @@ -88,6 +91,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withIssueKeys(issueKeys) .withFilterId(filterId) .build(); @@ -98,6 +103,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withIssueKeys(issueKeys) .withFilterId(filterId) .build(); @@ -106,6 +113,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withIssueKeys(issueKeys) .withFilterId(filterId) .build(); diff --git a/src/main/java/app/getxray/maven/plugin/xray/ImportFeaturesMojo.java b/src/main/java/app/getxray/maven/plugin/xray/ImportFeaturesMojo.java index c5b7ef0..a3761df 100644 --- a/src/main/java/app/getxray/maven/plugin/xray/ImportFeaturesMojo.java +++ b/src/main/java/app/getxray/maven/plugin/xray/ImportFeaturesMojo.java @@ -83,6 +83,9 @@ public class ImportFeaturesMojo extends AbstractMojo { @Parameter(property = "xray.timeout", required = false, defaultValue = "50") private Integer timeout; + @Parameter(property = "xray.verbose", required = false) + private Boolean verbose; + /** * Scope to filter the dependencies. */ @@ -121,6 +124,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withProjectKey(projectKey) .withProjectId(projectId) .withSource(source) @@ -132,6 +137,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withProjectKey(projectKey) .withupdateRepository(updateRepository) .build(); @@ -140,6 +147,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose) .withProjectKey(projectKey) .withupdateRepository(updateRepository) .build(); diff --git a/src/main/java/app/getxray/maven/plugin/xray/ImportResultsMojo.java b/src/main/java/app/getxray/maven/plugin/xray/ImportResultsMojo.java index 3d88b3c..48d764b 100644 --- a/src/main/java/app/getxray/maven/plugin/xray/ImportResultsMojo.java +++ b/src/main/java/app/getxray/maven/plugin/xray/ImportResultsMojo.java @@ -93,6 +93,9 @@ public class ImportResultsMojo extends AbstractMojo { @Parameter(property = "xray.timeout", required = false, defaultValue = "50") private Integer timeout; + @Parameter(property = "xray.verbose", required = false) + private Boolean verbose; + /** * Scope to filter the dependencies. */ @@ -173,7 +176,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { app.getxray.xray.XrayResultsImporter.CloudBuilder xrayImporterBuilder = new XrayResultsImporter.CloudBuilder(clientId, clientSecret) .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) - .withTimeout(timeout); + .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose); if (testInfoJson==null && testExecInfoJson==null) { if (XrayResultsImporter.XRAY_FORMAT.equals(reportFormat) || XrayResultsImporter.CUCUMBER_FORMAT.equals(reportFormat) || XrayResultsImporter.BEHAVE_FORMAT.equals(reportFormat)) { xrayImporter = xrayImporterBuilder.build(); @@ -218,12 +223,16 @@ public void execute() throws MojoExecutionException, MojoFailureException { xrayImporterBuilder = new XrayResultsImporter.ServerDCBuilder(jiraBaseUrl, jiraToken) .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) - .withTimeout(timeout); + .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose); } else { xrayImporterBuilder = new XrayResultsImporter.ServerDCBuilder(jiraBaseUrl, jiraUsername, jiraPassword) .withInternalTestProxy(useInternalTestProxy) .withIgnoreSslErrors(ignoreSslErrors) - .withTimeout(timeout); + .withTimeout(timeout) + .withLogger(getLog()) + .withVerbose(verbose); } if (testInfoJson==null && testExecInfoJson==null) { diff --git a/src/main/java/app/getxray/xray/CommonUtils.java b/src/main/java/app/getxray/xray/CommonUtils.java index cf9cdd7..571c8a9 100644 --- a/src/main/java/app/getxray/xray/CommonUtils.java +++ b/src/main/java/app/getxray/xray/CommonUtils.java @@ -1,5 +1,6 @@ package app.getxray.xray; +import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; import java.util.concurrent.TimeUnit; @@ -9,9 +10,49 @@ import javax.net.ssl.X509TrustManager; import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.ResponseBody; + +import org.apache.maven.plugin.logging.Log; public class CommonUtils { + public static void logRequest(Log logger, Request request) { + if (logger != null) { + logger.debug("REQUEST_URL: " + request.url().toString()); + logger.debug("REQUEST_METHOD: " + request.method()); + + Request copy = request.newBuilder().build(); + RequestBody body = copy.body(); + if (body != null) { + logger.debug("REQUEST_CONTENT_TYPE: " + body.contentType().toString()); + } + } + } + + public static void logResponse(Log logger, Response response) { + logResponse(logger, response, true); + } + + public static void logResponse(Log logger, Response response, boolean logBody) { + if (logger != null) { + logger.debug("RESPONSE_CONTENT_TYPE:" + response.header("Content-Type")); + logger.debug("RESPONSE_HTTP_STATUS: " + response.code()); + if (logBody) { + logger.debug("RESPONSE_BODY:"); + logger.debug("======================="); + + try (ResponseBody responseBody = response.peekBody(1024 * 1024)) { + logger.debug(responseBody.string()); + } catch (IOException e) { + //e.printStackTrace(); + } + } + } + } + public static boolean isTrue(Boolean bool) { return (bool!=null && bool); } diff --git a/src/main/java/app/getxray/xray/XrayFeaturesExporter.java b/src/main/java/app/getxray/xray/XrayFeaturesExporter.java index 6086e0d..c1bf5d3 100644 --- a/src/main/java/app/getxray/xray/XrayFeaturesExporter.java +++ b/src/main/java/app/getxray/xray/XrayFeaturesExporter.java @@ -17,6 +17,8 @@ import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.maven.plugin.logging.Log; + // https://docs.getxray.app/display/XRAYCLOUD/Exporting+Cucumber+Tests+-+REST+v2 // https://docs.getxray.app/display/XRAY/Exporting+Cucumber+Tests+-+REST @@ -40,6 +42,8 @@ public class XrayFeaturesExporter { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; private XrayFeaturesExporter(ServerDCBuilder builder) { this.jiraBaseUrl = builder.jiraBaseUrl; @@ -53,6 +57,8 @@ private XrayFeaturesExporter(ServerDCBuilder builder) { this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } private XrayFeaturesExporter(CloudBuilder builder) { @@ -65,6 +71,8 @@ private XrayFeaturesExporter(CloudBuilder builder) { this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } public static class ServerDCBuilder { @@ -80,6 +88,8 @@ public static class ServerDCBuilder { private Boolean useInternalTestProxy = false; private Boolean ignoreSslErrors = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public ServerDCBuilder(String jiraBaseUrl, String jiraUsername, String jiraPassword) { this.jiraBaseUrl = jiraBaseUrl; @@ -107,6 +117,16 @@ public ServerDCBuilder withTimeout(Integer timeout) { return this; } + public ServerDCBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public ServerDCBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public ServerDCBuilder withIssueKeys(String issueKeys) { this.issueKeys = issueKeys; return this; @@ -134,6 +154,8 @@ public static class CloudBuilder { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public CloudBuilder(String clientId, String clientSecret) { this.clientId = clientId; @@ -155,6 +177,16 @@ public CloudBuilder withTimeout(Integer timeout) { return this; } + public CloudBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public CloudBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public CloudBuilder withIssueKeys(String issueKeys) { this.issueKeys = issueKeys; return this; @@ -204,9 +236,10 @@ public String submitStandardServerDC(String outputPath) throws Exception { } request = new Request.Builder().url(builder.build()).get().addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); try { response = client.newCall(request).execute(); - // String responseBody = response.body().string(); + CommonUtils.logResponse(logger, response); if (response.isSuccessful()) { unzipContentsToFolder(response.body().byteStream(), outputPath); return ("ok"); @@ -226,10 +259,13 @@ public String submitStandardCloud(String outputPath) throws Exception { + "\" }"; RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON); Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build(); + CommonUtils.logRequest(logger, request); + Response response = null; String authToken = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response, false); String responseBody = response.body().string(); if (response.isSuccessful()) { authToken = responseBody.replace("\"", ""); @@ -255,9 +291,10 @@ public String submitStandardCloud(String outputPath) throws Exception { } request = new Request.Builder().url(builder.build()).get().addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); try { response = client.newCall(request).execute(); - // String responseBody = response.body().string(); + CommonUtils.logResponse(logger, response); if (response.isSuccessful()) { unzipContentsToFolder(response.body().byteStream(), outputPath); return ("ok"); diff --git a/src/main/java/app/getxray/xray/XrayFeaturesImporter.java b/src/main/java/app/getxray/xray/XrayFeaturesImporter.java index 09ee6e6..3a0bd97 100644 --- a/src/main/java/app/getxray/xray/XrayFeaturesImporter.java +++ b/src/main/java/app/getxray/xray/XrayFeaturesImporter.java @@ -23,6 +23,8 @@ import okhttp3.Response; import okhttp3.MultipartBody.Builder; +import org.apache.maven.plugin.logging.Log; + // https://docs.getxray.app/display/XRAYCLOUD/Importing+Cucumber+Tests+-+REST+v2 // https://docs.getxray.app/display/XRAY/Importing+Cucumber+Tests+-+REST @@ -50,6 +52,8 @@ public class XrayFeaturesImporter { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; private XrayFeaturesImporter(ServerDCBuilder builder) { this.jiraBaseUrl = builder.jiraBaseUrl; @@ -65,6 +69,8 @@ private XrayFeaturesImporter(ServerDCBuilder builder) { this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } private XrayFeaturesImporter(CloudBuilder builder) { @@ -78,6 +84,8 @@ private XrayFeaturesImporter(CloudBuilder builder) { this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } public static class ServerDCBuilder { @@ -95,6 +103,8 @@ public static class ServerDCBuilder { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public ServerDCBuilder(String jiraBaseUrl, String jiraUsername, String jiraPassword) { this.jiraBaseUrl = jiraBaseUrl; @@ -122,6 +132,16 @@ public ServerDCBuilder withTimeout(Integer timeout) { return this; } + public ServerDCBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public ServerDCBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public ServerDCBuilder withProjectKey(String projectKey) { this.projectKey = projectKey; return this; @@ -150,6 +170,8 @@ public static class CloudBuilder { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public CloudBuilder(String clientId, String clientSecret) { this.clientId = clientId; @@ -171,6 +193,16 @@ public CloudBuilder withTimeout(Integer timeout) { return this; } + public CloudBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public CloudBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public CloudBuilder withProjectKey(String projectKey) { this.projectKey = projectKey; return this; @@ -274,8 +306,10 @@ public JSONArray importServerDC(String inputPath, JSONObject testInfo, JSONObjec } Request request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONArray responseObj = new JSONArray(responseBody); @@ -297,10 +331,13 @@ public JSONArray importCloud(String inputPath, JSONObject testInfo, JSONObject p String authenticationPayload = "{ \"client_id\": \"" + clientId +"\", \"client_secret\": \"" + clientSecret +"\" }"; RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON); Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build(); + CommonUtils.logRequest(logger, request); + Response response = null; String authToken = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response, false); String responseBody = response.body().string(); if (response.isSuccessful()){ authToken = responseBody.replace("\"", ""); @@ -362,8 +399,10 @@ public JSONArray importCloud(String inputPath, JSONObject testInfo, JSONObject p } request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONArray responseObj = new JSONArray(); diff --git a/src/main/java/app/getxray/xray/XrayResultsImporter.java b/src/main/java/app/getxray/xray/XrayResultsImporter.java index 9c9307b..1fc1072 100644 --- a/src/main/java/app/getxray/xray/XrayResultsImporter.java +++ b/src/main/java/app/getxray/xray/XrayResultsImporter.java @@ -15,6 +15,8 @@ import okhttp3.RequestBody; import okhttp3.Response; +import org.apache.maven.plugin.logging.Log; + public class XrayResultsImporter { private final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json"); private final MediaType MEDIA_TYPE_XML = MediaType.parse("application/xml"); @@ -49,6 +51,8 @@ public class XrayResultsImporter { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; private XrayResultsImporter(ServerDCBuilder builder){ this.jiraBaseUrl = builder.jiraBaseUrl; @@ -56,10 +60,17 @@ private XrayResultsImporter(ServerDCBuilder builder){ this.jiraPassword = builder.jiraPassword; this.jiraPersonalAccessToken = builder.jiraPersonalAccessToken; this.projectKey = builder.projectKey; + this.fixVersion = builder.fixVersion; + this.revision = builder.revision; + this.testPlanKey = builder.testPlanKey; + this.testExecKey = builder.testExecKey; + this.testEnvironment = builder.testEnvironment; this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } private XrayResultsImporter(CloudBuilder builder){ @@ -75,6 +86,8 @@ private XrayResultsImporter(CloudBuilder builder){ this.ignoreSslErrors = builder.ignoreSslErrors; this.useInternalTestProxy = builder.useInternalTestProxy; this.timeout = builder.timeout; + this.verbose = builder.verbose; + this.logger = builder.logger; } public static class ServerDCBuilder { @@ -94,6 +107,8 @@ public static class ServerDCBuilder { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public ServerDCBuilder(String jiraBaseUrl, String jiraUsername, String jiraPassword) { this.jiraBaseUrl = jiraBaseUrl; @@ -121,6 +136,16 @@ public ServerDCBuilder withTimeout(Integer timeout) { return this; } + public ServerDCBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public ServerDCBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public ServerDCBuilder withProjectKey(String projectKey) { this.projectKey = projectKey; return this; @@ -172,6 +197,8 @@ public static class CloudBuilder { private Boolean ignoreSslErrors = false; private Boolean useInternalTestProxy = false; private Integer timeout = 50; + private Boolean verbose = false; + private Log logger; public CloudBuilder(String clientId, String clientSecret) { this.clientId = clientId; @@ -193,6 +220,16 @@ public CloudBuilder withTimeout(Integer timeout) { return this; } + public CloudBuilder withVerbose(Boolean verbose) { + this.verbose = verbose; + return this; + } + + public CloudBuilder withLogger(Log logger) { + this.logger = logger; + return this; + } + public CloudBuilder withProjectKey(String projectKey) { this.projectKey = projectKey; return this; @@ -292,9 +329,11 @@ public String submitMultipartServerDC(String format, String reportFile, JSONObje } Request request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); Response response = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONObject responseObj = new JSONObject(responseBody); @@ -316,10 +355,13 @@ public String submitMultipartCloud(String format, String reportFile, JSONObject String authenticationPayload = "{ \"client_id\": \"" + clientId +"\", \"client_secret\": \"" + clientSecret +"\" }"; RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON); Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build(); + CommonUtils.logRequest(logger, request); + Response response = null; String authToken = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response, false); String responseBody = response.body().string(); if (response.isSuccessful()){ authToken = responseBody.replace("\"", ""); @@ -370,9 +412,11 @@ public String submitMultipartCloud(String format, String reportFile, JSONObject } request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); response = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONObject responseObj = new JSONObject(responseBody); @@ -451,10 +495,11 @@ public String submitStandardServerDC(String format, String reportFile) throws Ex builder.addQueryParameter("testExecKey", this.testExecKey); } if (testEnvironment != null) { - builder.addQueryParameter("testEnvironment", this.testEnvironment); + builder.addQueryParameter("testEnvironments", this.testEnvironment); } request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); } + CommonUtils.logRequest(logger, request); } catch (Exception e1) { e1.printStackTrace(); throw e1; @@ -463,6 +508,7 @@ public String submitStandardServerDC(String format, String reportFile) throws Ex Response response = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONObject responseObj = new JSONObject(responseBody); @@ -484,10 +530,13 @@ public String submitStandardCloud(String format, String reportFile) throws Excep String authenticationPayload = "{ \"client_id\": \"" + clientId +"\", \"client_secret\": \"" + clientSecret +"\" }"; RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON); Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build(); + CommonUtils.logRequest(logger, request); + Response response = null; String authToken = null; try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response, false); String responseBody = response.body().string(); if (response.isSuccessful()){ authToken = responseBody.replace("\"", ""); @@ -550,12 +599,14 @@ public String submitStandardCloud(String format, String reportFile) throws Excep builder.addQueryParameter("testExecKey", this.testExecKey); } if (testEnvironment != null) { - builder.addQueryParameter("testEnvironment", this.testEnvironment); + builder.addQueryParameter("testEnvironments", this.testEnvironment); } request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build(); + CommonUtils.logRequest(logger, request); try { response = client.newCall(request).execute(); + CommonUtils.logResponse(logger, response); String responseBody = response.body().string(); if (response.isSuccessful()){ JSONObject responseObj = new JSONObject(responseBody); diff --git a/src/test/java/app/getxray/xray/it/import_results/XrayCloudIT.java b/src/test/java/app/getxray/xray/it/import_results/XrayCloudIT.java index b35d15c..c4c5642 100644 --- a/src/test/java/app/getxray/xray/it/import_results/XrayCloudIT.java +++ b/src/test/java/app/getxray/xray/it/import_results/XrayCloudIT.java @@ -11,6 +11,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.soebes.itf.jupiter.extension.MavenGoal; import com.soebes.itf.jupiter.extension.MavenJupiterExtension; +import com.soebes.itf.jupiter.extension.MavenOption; import com.soebes.itf.jupiter.extension.MavenTest; import com.soebes.itf.jupiter.extension.SystemProperty; import com.soebes.itf.jupiter.maven.MavenExecutionResult; @@ -123,6 +124,45 @@ private static void setupStub() { .willReturn(okJson("{ \"id\": \"10200\", \"key\": \"CALC-1\", \"self\": \"http://127.0.0.1/jira/rest/api/2/issue/10200\" }"))); } + @MavenTest + @MavenGoal("xray:import-results") + @SystemProperty(value = "xray.cloud", content = "true") + @SystemProperty(value = "xray.clientId", content = CLIENT_ID) + @SystemProperty(value = "xray.clientSecret", content = CLIENT_SECRET) + @SystemProperty(value = "xray.reportFormat", content = "xray") + @SystemProperty(value = "xray.reportFile", content = "xray.json") + @SystemProperty(value = "xray.useInternalTestProxy", content = "true") + @SystemProperty(value = "xray.verbose", content = "true") + @MavenOption("--debug") + void xray_standard_with_verbose_mode(MavenExecutionResult result) throws IOException { + /* + String report = CommonUtils.readResourceFileForImportResults("XrayCloudIT/xray_standard/xray.json"); + + wm.verify( + postRequestedFor(urlPathEqualTo("/api/v2/import/execution")) + .withHeader("Content-Type", containing("application/json")) + .withRequestBody(equalToJson(report)) + ); + */ + assertThat(result).isSuccessful(); + assertThat(result) + .out() + .debug() + .containsOnlyOnce("REQUEST_URL: https://xray.cloud.getxray.app/api/v2/authenticate"); + assertThat(result) + .out() + .debug() + .containsOnlyOnce("REQUEST_URL: https://xray.cloud.getxray.app/api/v2/import/execution"); + assertThat(result) + .out() + .debug() + .contains("REQUEST_METHOD: POST"); + assertThat(result) + .out() + .debug() + .contains("REQUEST_CONTENT_TYPE: application/json; charset=utf-8"); + } + @MavenTest @MavenGoal("xray:import-results") @SystemProperty(value = "xray.cloud", content = "true") @@ -183,6 +223,11 @@ void xray_multipart(MavenExecutionResult result) throws IOException { @SystemProperty(value = "xray.reportFormat", content = "junit") @SystemProperty(value = "xray.reportFile", content = "junit.xml") @SystemProperty(value = "xray.projectKey", content = "CALC") + @SystemProperty(value = "xray.testExecKey", content = "CALC-2") + @SystemProperty(value = "xray.testPlanKey", content = "CALC-3") + @SystemProperty(value = "xray.version", content = "1.0") + @SystemProperty(value = "xray.revision", content = "123") + @SystemProperty(value = "xray.testEnvironment", content = "chrome") @SystemProperty(value = "xray.useInternalTestProxy", content = "true") void junit_standard(MavenExecutionResult result) throws IOException { String report = CommonUtils.readResourceFileForImportResults("XrayCloudIT/junit_standard/junit.xml"); @@ -191,6 +236,11 @@ void junit_standard(MavenExecutionResult result) throws IOException { postRequestedFor(urlPathEqualTo("/api/v2/import/execution/junit")) .withHeader("Content-Type", containing("application/xml")) .withQueryParam("projectKey", equalTo("CALC")) + .withQueryParam("testExecKey", equalTo("CALC-2")) + .withQueryParam("testPlanKey", equalTo("CALC-3")) + .withQueryParam("fixVersion", equalTo("1.0")) + .withQueryParam("revision", equalTo("123")) + .withQueryParam("testEnvironments", equalTo("chrome")) .withRequestBody(equalToXml(report)) ); assertThat(result).isSuccessful(); diff --git a/src/test/java/app/getxray/xray/it/import_results/XrayDatacenterIT.java b/src/test/java/app/getxray/xray/it/import_results/XrayDatacenterIT.java index e5c6f25..158a64f 100644 --- a/src/test/java/app/getxray/xray/it/import_results/XrayDatacenterIT.java +++ b/src/test/java/app/getxray/xray/it/import_results/XrayDatacenterIT.java @@ -11,6 +11,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.soebes.itf.jupiter.extension.MavenGoal; import com.soebes.itf.jupiter.extension.MavenJupiterExtension; +import com.soebes.itf.jupiter.extension.MavenOption; import com.soebes.itf.jupiter.extension.MavenTest; import com.soebes.itf.jupiter.extension.SystemProperty; import com.soebes.itf.jupiter.maven.MavenExecutionResult; @@ -96,6 +97,42 @@ public static void setupStub() { System.out.println("setting up stubs - done."); } + @MavenTest + @MavenGoal("xray:import-results") + @SystemProperty(value = "xray.cloud", content = "false") + @SystemProperty(value = "xray.jiraBaseUrl", content = "http://127.0.0.1:18080") + @SystemProperty(value = "xray.jiraUsername", content = "username") + @SystemProperty(value = "xray.jiraPassword", content = "password") + @SystemProperty(value = "xray.reportFormat", content = "xray") + @SystemProperty(value = "xray.reportFile", content = "xray.json") + @SystemProperty(value = "xray.verbose", content = "true") + @MavenOption("--debug") + void xray_standard_with_verbose_mode(MavenExecutionResult result) throws IOException { + /* + String report = CommonUtils.readResourceFileForImportResults("XrayDatacenterIT/xray_standard/xray.json"); + + wm.verify( + postRequestedFor(urlPathEqualTo("/rest/raven/2.0/import/execution")) + .withBasicAuth(new BasicCredentials("username", "password")) + .withHeader("Content-Type", containing("application/json")) + .withRequestBody(equalToJson(report)) + ); + */ + assertThat(result).isSuccessful(); + assertThat(result) + .out() + .debug() + .containsOnlyOnce("REQUEST_URL: http://127.0.0.1:18080/rest/raven/2.0/import/execution"); + assertThat(result) + .out() + .debug() + .containsOnlyOnce("REQUEST_METHOD: POST"); + assertThat(result) + .out() + .debug() + .containsOnlyOnce("REQUEST_CONTENT_TYPE: application/json; charset=utf-8"); + } + @MavenTest @MavenGoal("xray:import-results") @SystemProperty(value = "xray.cloud", content = "false") @@ -158,6 +195,11 @@ void xray_multipart(MavenExecutionResult result) throws IOException { @SystemProperty(value = "xray.reportFormat", content = "junit") @SystemProperty(value = "xray.reportFile", content = "junit.xml") @SystemProperty(value = "xray.projectKey", content = "CALC") + @SystemProperty(value = "xray.testExecKey", content = "CALC-2") + @SystemProperty(value = "xray.testPlanKey", content = "CALC-3") + @SystemProperty(value = "xray.version", content = "1.0") + @SystemProperty(value = "xray.revision", content = "123") + @SystemProperty(value = "xray.testEnvironment", content = "chrome") void junit_standard(MavenExecutionResult result) throws IOException { String report = CommonUtils.readResourceFileForImportResults("XrayDatacenterIT/junit_standard/junit.xml"); @@ -166,6 +208,11 @@ void junit_standard(MavenExecutionResult result) throws IOException { .withBasicAuth(new BasicCredentials("username", "password")) .withHeader("Content-Type", containing("multipart/form-data;")) .withQueryParam("projectKey", equalTo("CALC")) + .withQueryParam("testExecKey", equalTo("CALC-2")) + .withQueryParam("testPlanKey", equalTo("CALC-3")) + .withQueryParam("fixVersion", equalTo("1.0")) + .withQueryParam("revision", equalTo("123")) + .withQueryParam("testEnvironments", equalTo("chrome")) .withAnyRequestBodyPart( aMultipart() .withName("file") diff --git a/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/pom.xml b/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/pom.xml new file mode 100644 index 0000000..92b4387 --- /dev/null +++ b/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + app.getxray + xray-maven-plugin-cloud-examples + 1.0-SNAPSHOT + + cloud-examples + https://github.com/Xray-App/xray-maven-plugin + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.13.1 + test + + + + + + + + app.getxray + xray-maven-plugin + @project.version@ + + true + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/xray.json b/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/xray.json new file mode 100644 index 0000000..1654c34 --- /dev/null +++ b/src/test/resources-its/app/getxray/xray/it/import_results/XrayCloudIT/xray_standard_with_verbose_mode/xray.json @@ -0,0 +1,20 @@ +{ + "info" : { + "summary" : "Execution of automated tests", + "description" : "This execution is automatically created when importing execution results from an external source", + "project" : "CALC", + "version" : "v1.0", + "revision" : "1234", + "startDate" : "2014-08-30T11:47:35+01:00", + "finishDate" : "2014-08-30T11:53:00+01:00", + "testEnvironments": ["Chrome"] + }, + "tests" : [ + { + "testKey" : "CALC-3", + "start" : "2014-08-30T11:47:35+01:00", + "finish" : "2014-08-30T11:50:56+01:00", + "status" : "PASSED" + } + ] +} \ No newline at end of file diff --git a/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/pom.xml b/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/pom.xml new file mode 100644 index 0000000..a5dcae4 --- /dev/null +++ b/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + app.getxray + xray-maven-plugin-datacenter-examples + 1.0-SNAPSHOT + + datacenter-examples + https://github.com/Xray-App/xray-maven-plugin + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.13.1 + test + + + + + + + + app.getxray + xray-maven-plugin + @project.version@ + + true + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/xray.json b/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/xray.json new file mode 100644 index 0000000..51d34d4 --- /dev/null +++ b/src/test/resources-its/app/getxray/xray/it/import_results/XrayDatacenterIT/xray_standard_with_verbose_mode/xray.json @@ -0,0 +1,20 @@ +{ + "info" : { + "summary" : "Execution of automated tests", + "description" : "This execution is automatically created when importing execution results from an external source", + "project" : "BOOK", + "version" : "1.0", + "revision" : "1234", + "startDate" : "2014-08-30T11:47:35+01:00", + "finishDate" : "2014-08-30T11:53:00+01:00", + "testEnvironments": ["Chrome"] + }, + "tests" : [ + { + "testKey" : "BOOK-14", + "start" : "2014-08-30T11:47:35+01:00", + "finish" : "2014-08-30T11:50:56+01:00", + "status" : "PASS" + } + ] +} \ No newline at end of file