Skip to content

Commit

Permalink
Merge pull request #436 from cqse/ts/38164_500_json_response
Browse files Browse the repository at this point in the history
TS-38164 Fixed /commit and /revision endpoints
  • Loading branch information
karottenreibe committed Mar 28, 2024
2 parents 43fa715 + 9f8a8b9 commit 22c9121
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ We use [semantic versioning](http://semver.org/):
# Next Release
- [feature] Docker: agent copies itself to `/transfer` if this is mounted into the container
- [fix] Disable warning about proxy port not being correct when no proxy port was set at all
- [fix] _agent_: `GET /commit` and `GET /revision` endpoints did return 500 error

# 33.1.2
- [fix] _teamscale-maven-plugin_: Revision and end commit could not be set via command line (user property)
Expand Down
Expand Up @@ -12,6 +12,8 @@
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Optional;

Expand Down Expand Up @@ -48,13 +50,15 @@ public String getMessage() {
/** Returns revision information for the Teamscale upload. */
@GET
@Path("/revision")
@Produces(MediaType.APPLICATION_JSON)
public RevisionInfo getRevision() {
return this.getRevisionInfo();
}

/** Returns revision information for the Teamscale upload. */
@GET
@Path("/commit")
@Produces(MediaType.APPLICATION_JSON)
public RevisionInfo getCommit() {
return this.getRevisionInfo();
}
Expand Down
Expand Up @@ -86,6 +86,23 @@ public void testGettingPartition() throws Exception {
assertThat(receivedPartition).isEqualTo(defaultPartition);
}

/** Test reading the commit to which the agent will upload. */
@Test
public void testGettingCommit() throws Exception {
String receivedCommit = getText("/commit");
assertThat(receivedCommit).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
receivedCommit = getJson("/commit");
assertThat(receivedCommit).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
}

/** Test reading the revision to which the agent will upload. */
@Test
public void testGettingRevision() throws Exception {
String receivedRevision = getText("/revision");
assertThat(receivedRevision).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
receivedRevision = getJson("/revision");
assertThat(receivedRevision).isEqualTo("{\"type\":\"REVISION\",\"value\":null}");
}

private void putText(String endpointPath, String newValue) throws Exception {
OkHttpClient client = new OkHttpClient();
Expand All @@ -107,4 +124,14 @@ private String getText(String endpointPath) throws Exception {
Response response = client.newCall(request).execute();
return response.body() != null ? response.body().string() : "";
}
}

private String getJson(String endpointPath) throws Exception {
OkHttpClient client = new OkHttpClient();
HttpUrl endpointUrl = HttpUrl.get(baseUri.resolve(endpointPath));
Request request = new Request.Builder()
.url(endpointUrl).header("Accept", javax.ws.rs.core.MediaType.APPLICATION_JSON)
.build();
Response response = client.newCall(request).execute();
return response.body() != null ? response.body().string() : "";
}
}

0 comments on commit 22c9121

Please sign in to comment.