Skip to content

Commit

Permalink
feat: added test results endpoints (#78)
Browse files Browse the repository at this point in the history
* feat: added test results endpoints

* feat: added test results endpoints (added to changelog)
  • Loading branch information
galimru authored Dec 9, 2024
1 parent 4136805 commit 1415d7b
Show file tree
Hide file tree
Showing 20 changed files with 2,226 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 6.0.1

- Added support for TestCaseResult in **TestApi**.

# 6.0.0

**Major release**
Expand Down
1 change: 1 addition & 0 deletions azd/src/main/java/org/azd/common/ApiVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class ApiVersion {
public static final String SERVICE_ENDPOINTS = "7.1-preview.4";
public static final String SERVICE_HOOKS = "7.1-preview.1";
public static final String TEST_RUNS = "7.1-preview.3";
public static final String TEST_RESULTS = "7.2-preview.6";
public static final String VARIABLE_GROUPS = "7.1-preview.2";
public static final String WIKI = "7.1-preview.2";
public static final String WIKI_ATTACHMENTS = "7.1-preview.1";
Expand Down
7 changes: 3 additions & 4 deletions azd/src/main/java/org/azd/interfaces/TestDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import org.azd.enums.TestRunPublishContext;
import org.azd.enums.TestRunState;
import org.azd.exceptions.AzDException;
import org.azd.test.types.RunCreateModel;
import org.azd.test.types.TestRun;
import org.azd.test.types.TestRunStatistic;
import org.azd.test.types.TestRuns;
import org.azd.test.types.*;

public interface TestDetails {
TestRun createTestRun(RunCreateModel runCreateModel) throws AzDException;
Expand Down Expand Up @@ -41,4 +38,6 @@ TestRuns queryTestRuns(String maxLastUpdatedDate, String minLastUpdatedDate, Str
String runTitle) throws AzDException;

TestRun updateTestRun(int runId, TestRun testRun) throws AzDException;

TestCaseResults updateTestResults(int runId, TestCaseResults testCaseResults) throws AzDException;
}
22 changes: 18 additions & 4 deletions azd/src/main/java/org/azd/test/TestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import org.azd.exceptions.AzDException;
import org.azd.helpers.JsonMapper;
import org.azd.interfaces.TestDetails;
import org.azd.test.types.RunCreateModel;
import org.azd.test.types.TestRun;
import org.azd.test.types.TestRunStatistic;
import org.azd.test.types.TestRuns;
import org.azd.test.types.*;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -335,4 +332,21 @@ public TestRun updateTestRun(int runId, TestRun testRun) throws AzDException {

return MAPPER.mapJsonResponse(r, TestRun.class);
}

/**
* Update test case results by run ID.
*
* @param runId ID of the run to update.
* @param testCaseResults {@link TestCaseResults} object.
* @return TestCaseResults Object {@link TestCaseResults}
* @throws AzDException Default Api exception handler.
*/
@Override
public TestCaseResults updateTestResults(int runId, TestCaseResults testCaseResults) throws AzDException {
String r = send(RequestMethod.PATCH, CONNECTION, TEST, CONNECTION.getProject(),
AREA + "/runs", String.valueOf(runId), "results", ApiVersion.TEST_RUNS, null, testCaseResults.getResults(),
CustomHeader.JSON_CONTENT_TYPE);

return MAPPER.mapJsonResponse(r, TestCaseResults.class);
}
}
10 changes: 10 additions & 0 deletions azd/src/main/java/org/azd/test/TestRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.azd.abstractions.BaseRequestBuilder;
import org.azd.authentication.AccessTokenCredential;
import org.azd.test.results.ResultsRequestBuilder;
import org.azd.test.runs.RunsRequestBuilder;

/**
Expand All @@ -26,4 +27,13 @@ public TestRequestBuilder(String organizationUrl, AccessTokenCredential accessTo
public RunsRequestBuilder runs() {
return new RunsRequestBuilder(organizationUrl, accessTokenCredential);
}

/**
* Provides functionality to work with Test results Api.
*
* @return ResultsRequestBuilder {@link ResultsRequestBuilder}
*/
public ResultsRequestBuilder results() {
return new ResultsRequestBuilder(organizationUrl, accessTokenCredential);
}
}
92 changes: 92 additions & 0 deletions azd/src/main/java/org/azd/test/results/ResultsRequestBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package org.azd.test.results;

import org.azd.abstractions.BaseRequestBuilder;
import org.azd.abstractions.QueryParameter;
import org.azd.authentication.AccessTokenCredential;
import org.azd.common.ApiVersion;
import org.azd.enums.TestRunPublishContext;
import org.azd.enums.TestRunState;
import org.azd.exceptions.AzDException;
import org.azd.test.types.*;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

/**
* Provides functionality to work with Test results Api.
*/
public class ResultsRequestBuilder extends BaseRequestBuilder {
/**
* Instantiates a new RequestBuilder instance and sets the default values.
*
* @param organizationUrl Represents organization location request url.
* @param accessTokenCredential Access token credential object.
*/
public ResultsRequestBuilder(String organizationUrl, AccessTokenCredential accessTokenCredential) {
super(organizationUrl, accessTokenCredential, "test", "4637d869-3a76-4468-8057-0bb02aa385cf", ApiVersion.TEST_RESULTS);
}


/**
* Get a test case results for a test run.
*
* @param runId ID of the run to get.
* @param testCaseResultId ID of the test case result to get.
* @return TestCaseResult Object {@link TestCaseResult}
* @throws AzDException Default Api Exception handler.
**/
public TestCaseResult get(int runId, int testCaseResultId) throws AzDException {
return builder()
.serviceEndpoint("runId", runId)
.serviceEndpoint("testCaseResultId", testCaseResultId)
.build()
.execute(TestCaseResult.class);
}

/**
* Get a list of test results by run ID.
*
* @param runId ID of the run.
* @return Collection of TestCaseResults Object {@link TestRuns}
* @throws AzDException Default Api Exception handler.
**/
public TestCaseResults list(int runId) throws AzDException {
return builder()
.serviceEndpoint("runId", runId)
.build()
.execute(TestCaseResults.class);
}

/**
* Create test results by run ID.
*
* @param runId ID of the run to update.
* @param testCaseResults Test case results object to update.
* @return Test case results object {@link TestCaseResults}
* @throws AzDException Default Api Exception handler.
*/
public TestCaseResults create(int runId, TestCaseResults testCaseResults) throws AzDException {
return builder()
.POST(testCaseResults.getResults())
.serviceEndpoint("runId", runId)
.build()
.execute(TestCaseResults.class);
}

/**
* Update test results by run ID.
*
* @param runId ID of the run to update.
* @param testCaseResults Test case results object to update.
* @return Test case results object {@link TestCaseResults}
* @throws AzDException Default Api Exception handler.
*/
public TestCaseResults update(int runId, TestCaseResults testCaseResults) throws AzDException {
return builder()
.PATCH(testCaseResults.getResults())
.serviceEndpoint("runId", runId)
.build()
.execute(TestCaseResults.class);
}

}
117 changes: 117 additions & 0 deletions azd/src/main/java/org/azd/test/types/BuildReference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.azd.test.types;

/*
----------------------------------------------------------
GENERATED FILE, should be edited to suit the purpose.
----------------------------------------------------------
*/

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.azd.abstractions.serializer.SerializableEntity;

/**
* Represents a reference to a build with details such as branch name,
* build system, and repository information.
**/
@JsonIgnoreProperties(ignoreUnknown = true)
public class BuildReference extends SerializableEntity {

/**
* Name of the branch associated with the build.
**/
@JsonProperty("branchName")
private String branchName;

/**
* The build system used for the build.
**/
@JsonProperty("buildSystem")
private String buildSystem;

/**
* ID of the build definition.
**/
@JsonProperty("definitionId")
private Integer definitionId;

/**
* Unique ID of the build.
**/
@JsonProperty("id")
private Integer id;

/**
* Number identifying the build.
**/
@JsonProperty("number")
private String number;

/**
* Repository ID associated with the build.
**/
@JsonProperty("repositoryId")
private String repositoryId;

/**
* URI of the build.
**/
@JsonProperty("uri")
private String uri;

public String getBranchName() {
return branchName;
}

public void setBranchName(String branchName) {
this.branchName = branchName;
}

public String getBuildSystem() {
return buildSystem;
}

public void setBuildSystem(String buildSystem) {
this.buildSystem = buildSystem;
}

public Integer getDefinitionId() {
return definitionId;
}

public void setDefinitionId(Integer definitionId) {
this.definitionId = definitionId;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getRepositoryId() {
return repositoryId;
}

public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}

public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}
}
61 changes: 61 additions & 0 deletions azd/src/main/java/org/azd/test/types/FailingSince.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.azd.test.types;

/*
----------------------------------------------------------
GENERATED FILE, should be edited to suit the purpose.
----------------------------------------------------------
*/

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.azd.abstractions.serializer.SerializableEntity;

/**
* Represents the failing since information of a test result.
**/
@JsonIgnoreProperties(ignoreUnknown = true)
public class FailingSince extends SerializableEntity {

/**
* Build reference since failing.
**/
@JsonProperty("build")
private BuildReference build;

/**
* Time since failing (UTC).
**/
@JsonProperty("date")
private String date;

/**
* Release reference since failing.
**/
@JsonProperty("release")
private ReleaseReference release;

// Getters and setters
public BuildReference getBuild() {
return build;
}

public void setBuild(BuildReference build) {
this.build = build;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public ReleaseReference getRelease() {
return release;
}

public void setRelease(ReleaseReference release) {
this.release = release;
}
}
Loading

0 comments on commit 1415d7b

Please sign in to comment.