Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.pdsl</groupId>
<artifactId>pdsl-xray</artifactId>
<version>5.2.1-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>xray_pdsl</name>
<url>https://maven.apache.org</url>
Expand Down Expand Up @@ -52,13 +52,19 @@ limitations under the License.
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<apache.httpclient.version>5.6.1</apache.httpclient.version>
<apache.httpcore.version>5.3.6</apache.httpcore.version>
<antlr.version>4.13.2</antlr.version>
<guava.version>33.6.0-jre</guava.version>
<jackson.version>2.21.5</jackson.version>
<junit5.version>5.9.2</junit5.version>
<pdsl.version>1.13.0</pdsl.version>
<maven.deploy.plugin.version>3.1.2</maven.deploy.plugin.version>
<maven.gpg.plugin.version>3.2.4</maven.gpg.plugin.version>
<maven.install.plugin.version>3.1.2</maven.install.plugin.version>
<maven.javadoc.plugin.version>3.7.0</maven.javadoc.plugin.version>
<maven.source.plugin.version>3.3.1</maven.source.plugin.version>
<mockito.version>5.18.0</mockito.version>
<mvn.jar.version>3.2.2</mvn.jar.version>
</properties>
<distributionManagement>
Expand All @@ -75,28 +81,28 @@ limitations under the License.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.14</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${apache.httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>5.3.4</version>
<version>${apache.httpcore.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<version>${junit5.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<version>${junit5.version}</version>
</dependency>
<dependency>
<groupId>com.google.pdsl</groupId>
Expand All @@ -116,7 +122,7 @@ limitations under the License.
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.18.0</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -127,7 +133,7 @@ limitations under the License.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.1-jre</version>
<version>${guava.version}</version>
</dependency>
</dependencies>
<repositories>
Expand Down Expand Up @@ -159,6 +165,13 @@ limitations under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<configuration>
<sourceDirectory>src/test/antlr4</sourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
79 changes: 40 additions & 39 deletions src/main/java/com/google/pdsl/xray/core/XrayTestResultUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import com.pdsl.testcases.TestCase;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.apache.commons.codec.Charsets;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.EntityBuilder;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -420,14 +420,14 @@ private static void addTags(Set<String> tags, Map<String, String> substitutions,
* there will be 3 executions created. The implementation cannot
* consolidate this down to 2 executions based on the shared environments because
* some users of XRAY will specify operations systems (such as iOS or Android) with
* the environments. Currently we have no feature that allows us to distinguish between
* the environments. Currently, we have no feature that allows us to distinguish between
* environments we could safely factor out and combine with other executions and others
* that must be coupled to their original groups of environments.
*
* @return List of HTTPResponse: the responses from each attempt to create a test execution
*/
public List<org.apache.http.HttpResponse> publishReportsToXray() {
List<org.apache.http.HttpResponse> responses = new ArrayList<>();
public List<HttpResponse> publishReportsToXray() {
List<HttpResponse> responses = new ArrayList<>();
boolean debugging = false;
if (debugging) {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
Expand All @@ -443,15 +443,15 @@ public List<org.apache.http.HttpResponse> publishReportsToXray() {

try {
info = Files.writeString(tempDirectory.resolve(String.format("info-%s.json", UUID.randomUUID())),
objectMapper.writeValueAsString(fieldSupplier.get()), Charsets.UTF_8,
objectMapper.writeValueAsString(fieldSupplier.get()), StandardCharsets.UTF_8,
StandardOpenOption.CREATE_NEW);
info.toFile().deleteOnExit();
for (HierarchicalTestSuite suite : testCaseXrayTestExecutionResultMap.values()) {
for (XrayTestExecution executionResult : suite.info2Results()) {
String requestBody = objectMapper.writeValueAsString(executionResult);
// Convert the request to files as per the xray API specification
Path results = Files.writeString(tempDirectory.resolve(Path.of(String.format("results-%s.json", UUID.randomUUID()))),
requestBody, Charsets.UTF_8,
requestBody, StandardCharsets.UTF_8,
StandardOpenOption.CREATE_NEW);
results.toFile().deleteOnExit();

Expand Down Expand Up @@ -484,8 +484,8 @@ public List<org.apache.http.HttpResponse> publishReportsToXray() {
*
* @return List of HTTPResponse: the response from the single attempt to create a test execution
*/
public List<org.apache.http.HttpResponse> publishConsolidatedReportsToXray() {
List<org.apache.http.HttpResponse> responses = new ArrayList<>();
public List<HttpResponse> publishConsolidatedReportsToXray() {
List<HttpResponse> responses = new ArrayList<>();
boolean debugging = false;
if (debugging) {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
Expand All @@ -502,7 +502,7 @@ public List<org.apache.http.HttpResponse> publishConsolidatedReportsToXray() {

try {
info = Files.writeString(tempDirectory.resolve(String.format("info-%s.json", UUID.randomUUID())),
objectMapper.writeValueAsString(fieldSupplier.get()), Charsets.UTF_8,
objectMapper.writeValueAsString(fieldSupplier.get()), StandardCharsets.UTF_8,
StandardOpenOption.CREATE_NEW);
info.toFile().deleteOnExit();

Expand Down Expand Up @@ -532,7 +532,7 @@ public List<org.apache.http.HttpResponse> publishConsolidatedReportsToXray() {
String requestBody = objectMapper.writeValueAsString(finalExecution);

results = Files.writeString(tempDirectory.resolve(Path.of(String.format("results-%s.json", UUID.randomUUID()))),
requestBody, Charsets.UTF_8,
requestBody, StandardCharsets.UTF_8,
StandardOpenOption.CREATE_NEW);
results.toFile().deleteOnExit();

Expand All @@ -553,7 +553,7 @@ public List<org.apache.http.HttpResponse> publishConsolidatedReportsToXray() {
return responses;
}

private void postXrayExecution(Path results, Path info, List<org.apache.http.HttpResponse> responses) throws IOException {
private void postXrayExecution(Path results, Path info, List<HttpResponse> responses) throws IOException {
HttpPost post = new HttpPost(getXrayReportUrl());
post.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + xrayAuth.getAuthToken());
post.addHeader(HttpHeaders.CONTENT_TYPE, String.format("%s; boundary=%s",
Expand All @@ -571,17 +571,16 @@ private void postXrayExecution(Path results, Path info, List<org.apache.http.Htt
.build());

try (CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client
.execute(post)) {
HttpResponse clonedResponse = cloneResponseIntoMemory(response);
CloseableHttpResponse response = client.execute(post)) {
ClassicHttpResponse clonedResponse = cloneResponseIntoMemory(response);
responses.add(clonedResponse);
final int statusCode = response.getStatusLine().getStatusCode();
final int statusCode = response.getCode();
if (statusCode >= 200 && statusCode < 300) {
logger.info(String.format("Xray test execution results imported successfully\n%s%n",
new String(clonedResponse.getEntity().getContent().readAllBytes())));
} else {
logger.severe(String.format("Failed to import Xray test execution results: %s - %s%n",
response.getStatusLine(), new String(clonedResponse.getEntity().getContent().readAllBytes())));
logger.severe(String.format("Failed to import Xray test execution results: %d %s - %s%n",
response.getCode(), response.getReasonPhrase(), new String(clonedResponse.getEntity().getContent().readAllBytes())));
}
}
}
Expand All @@ -590,22 +589,24 @@ private void postXrayExecution(Path results, Path info, List<org.apache.http.Htt
* Reads an active HttpResponse and clones it completely into memory
* so it can be safely used after the original network stream is closed.
*/
private BasicHttpResponse cloneResponseIntoMemory(HttpResponse originalResponse) throws IOException {
BasicHttpResponse clonedResponse = new BasicHttpResponse(originalResponse.getStatusLine());
private BasicClassicHttpResponse cloneResponseIntoMemory(ClassicHttpResponse originalResponse) throws IOException {
BasicClassicHttpResponse clonedResponse =
new BasicClassicHttpResponse(originalResponse.getCode(), originalResponse.getReasonPhrase());

clonedResponse.setHeaders(originalResponse.getAllHeaders());
clonedResponse.setHeaders(originalResponse.getHeaders());

if (originalResponse.getEntity() != null) {
ByteArrayEntity memoryEntity = new ByteArrayEntity(EntityUtils.toByteArray(originalResponse.getEntity()));

byte[] bytes = EntityUtils.toByteArray(originalResponse.getEntity());
ContentType contentType = null;
if (originalResponse.getEntity().getContentType() != null) {
memoryEntity.setContentType(originalResponse.getEntity().getContentType());
}
if (originalResponse.getEntity().getContentEncoding() != null) {
memoryEntity.setContentEncoding(originalResponse.getEntity().getContentEncoding());
contentType = ContentType.parse(originalResponse.getEntity().getContentType());
}

clonedResponse.setEntity(memoryEntity);
clonedResponse.setEntity(EntityBuilder.create()
.setBinary(bytes)
.setContentType(contentType)
.setContentEncoding(originalResponse.getEntity().getContentEncoding())
.build());
}

return clonedResponse;
Expand Down Expand Up @@ -785,7 +786,7 @@ private StepStatus determineStepStatus(Integer failingStepIndex, int startIndex,
}
if (failingStepIndex < startIndex) {
return StepStatus.BLOCKED;
} else if (failingStepIndex >= startIndex && failingStepIndex < endIndex) {
} else if (failingStepIndex < endIndex) {
return StepStatus.FAILED;
} else {
return StepStatus.PASSED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.pdsl.specifications.FilteredPhrase;
import com.pdsl.transformers.PolymorphicDslPhraseFilter;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.apache.http.HttpResponse;
import org.apache.hc.core5.http.HttpResponse;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down