Skip to content

Commit 8ab7318

Browse files
committed
[0.17] Fix the return type of Run.add to be array of ints
Signed-off-by: Andrea Lamparelli <a.lamparelli95@gmail.com>
1 parent ec57e1c commit 8ab7318

5 files changed

Lines changed: 15 additions & 24 deletions

File tree

horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/services/RunService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.microprofile.openapi.annotations.responses.APIResponseSchema;
3030
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
3131
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
32+
import org.jboss.resteasy.reactive.ResponseStatus;
3233
import org.jboss.resteasy.reactive.RestForm;
3334
import org.jboss.resteasy.reactive.Separator;
3435
import org.jboss.resteasy.reactive.multipart.FileUpload;
@@ -166,13 +167,14 @@ void updateAccess(@PathParam("id") int id,
166167
@Parameter(name = "access", description = "New Access level", example = "0"),
167168
})
168169
@RequestBody(name = "runBody", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Run.class)), required = true)
170+
@ResponseStatus(202) // ACCEPTED
169171
@APIResponses(value = {
170172
@APIResponse(responseCode = "202", description = "The request has been accepted for processing. Returns a list of created run IDs if available, "
171173
+ "or an empty list if processing is still ongoing. Label values and change detection processing " +
172174
"is performed asynchronously.", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(type = SchemaType.ARRAY, implementation = Integer.class, example = "[101, 102, 103]"), example = "[101, 102, 103]")),
173175
@APIResponse(responseCode = "400", description = "Some fields are missing or invalid", content = @Content(mediaType = MediaType.APPLICATION_JSON))
174176
})
175-
Response add(@QueryParam("test") String testNameOrId,
177+
List<Integer> add(@QueryParam("test") String testNameOrId,
176178
@QueryParam("owner") String owner,
177179
@QueryParam("access") Access access,
178180
Run run);

horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/RunServiceImpl.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import jakarta.transaction.TransactionManager;
3636
import jakarta.transaction.Transactional;
3737
import jakarta.ws.rs.WebApplicationException;
38-
import jakarta.ws.rs.core.HttpHeaders;
3938
import jakarta.ws.rs.core.MediaType;
4039
import jakarta.ws.rs.core.Response;
4140

@@ -382,7 +381,7 @@ public void updateAccess(int id, String owner, Access access) {
382381
@RolesAllowed(Roles.UPLOADER)
383382
@WithRoles
384383
@Override
385-
public Response add(String testNameOrId, String owner, Access access, Run run) {
384+
public List<Integer> add(String testNameOrId, String owner, Access access, Run run) {
386385
if (owner != null) {
387386
run.owner = owner;
388387
}
@@ -392,7 +391,7 @@ public Response add(String testNameOrId, String owner, Access access, Run run) {
392391
log.debugf("About to add new run to test %s using owner", testNameOrId, owner);
393392
if (testNameOrId == null || testNameOrId.isEmpty()) {
394393
if (run.testid == null || run.testid == 0) {
395-
return Response.status(Response.Status.BAD_REQUEST).entity("No test name or id provided").build();
394+
throw ServiceException.badRequest("No test name or id provided");
396395
} else
397396
testNameOrId = run.testid.toString();
398397
}
@@ -408,9 +407,7 @@ public Response add(String testNameOrId, String owner, Access access, Run run) {
408407
Log.warnf("Dataset with id %d not found, cannot process it", dsId);
409408
}
410409
});
411-
return Response.status(Response.Status.ACCEPTED).entity(String.valueOf(runPersistence.runId))
412-
.header(HttpHeaders.LOCATION, "/run/" + runPersistence.runId)
413-
.build();
410+
return Collections.singletonList(runPersistence.runId);
414411
}
415412

416413
@Override

horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/BaseServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ protected <T> T withExampleDataset(Test test, JsonNode data, Function<Dataset, T
632632
.oauth2(getUploaderToken())
633633
.body(run)
634634
.post("/api/run/test");
635-
run.id = response.body().as(Integer.class);
635+
run.id = (int) response.body().as(List.class).get(0);
636636
log.debugf("Run ID: %d, for test ID: %d", run.id, run.testid);
637637
} finally {
638638
if (tm.getTransaction().getStatus() == Status.STATUS_ACTIVE) {
@@ -961,7 +961,7 @@ protected void populateDataFromFiles() throws IOException {
961961
.body(r)
962962
.post("/api/run/test");
963963
assertEquals(202, response.statusCode());
964-
964+
assertEquals(1, response.getBody().as(List.class).size());
965965
}
966966

967967
String readFile(File file) {

horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/RunServiceNoRestTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import static org.junit.jupiter.api.Assertions.assertNotNull;
1010
import static org.junit.jupiter.api.Assertions.assertTrue;
1111

12+
import java.util.List;
13+
1214
import jakarta.inject.Inject;
13-
import jakarta.ws.rs.core.Response;
1415

1516
import com.fasterxml.jackson.databind.JsonNode;
1617
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -108,9 +109,8 @@ private Test addTest(String name, String owner, String folder, Integer datastore
108109
private int uploadRun(int testId, String owner, JsonNode runData) {
109110
Run run = createSampleRun(testId, runData, owner);
110111

111-
try (Response resp = runService.add(String.valueOf(testId), owner, Access.PUBLIC, run)) {
112-
assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
113-
return Integer.parseInt(resp.getEntity().toString());
114-
}
112+
List<Integer> runIds = runService.add(String.valueOf(testId), owner, Access.PUBLIC, run);
113+
assertEquals(1, runIds.size());
114+
return runIds.get(0);
115115
}
116116
}

horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/TestServiceNoRestTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,7 @@ void testDeleteTestWithRun() {
515515
assertEquals(1, TestDAO.count());
516516

517517
Run run1 = createSampleRun(created1.id, JsonNodeFactory.instance.objectNode(), FOO_TEAM);
518-
int runId;
519-
try (Response resp = runService.add(created1.name, FOO_TEAM, Access.PUBLIC, run1)) {
520-
assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
521-
runId = Integer.parseInt(resp.getEntity().toString());
522-
}
518+
int runId = runService.add(created1.name, FOO_TEAM, Access.PUBLIC, run1).get(0);
523519
assertEquals(1, RunDAO.count());
524520

525521
// flush data
@@ -544,11 +540,7 @@ void testDeleteTestWithAlreadyTrashedRun() {
544540
assertEquals(1, TestDAO.count());
545541

546542
Run run1 = createSampleRun(created1.id, JsonNodeFactory.instance.objectNode(), FOO_TEAM);
547-
int runId;
548-
try (Response resp = runService.add(created1.name, FOO_TEAM, Access.PUBLIC, run1)) {
549-
assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
550-
runId = Integer.parseInt(resp.getEntity().toString());
551-
}
543+
int runId = runService.add(created1.name, FOO_TEAM, Access.PUBLIC, run1).get(0);
552544
assertEquals(1, RunDAO.count());
553545

554546
// flush data

0 commit comments

Comments
 (0)