Skip to content

Commit cb29393

Browse files
committed
Update E2ETests
1 parent 596e109 commit cb29393

8 files changed

Lines changed: 121 additions & 66 deletions

File tree

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ConstraintsTests.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import gov.nasa.jpl.aerie.e2e.types.ExternalDataset.ProfileInput;
77
import gov.nasa.jpl.aerie.e2e.types.ExternalDataset.ProfileInput.ProfileSegmentInput;
88
import gov.nasa.jpl.aerie.e2e.types.ValueSchema;
9+
import gov.nasa.jpl.aerie.e2e.types.workspaces.HasuraRequestFailure;
910
import gov.nasa.jpl.aerie.e2e.utils.GatewayRequests;
1011
import gov.nasa.jpl.aerie.e2e.utils.HasuraRequests;
1112
import org.junit.jupiter.api.*;
@@ -94,14 +95,17 @@ void afterEach() throws IOException {
9495

9596
@Test
9697
void constraintsFailNoSimData() {
97-
final var exception = assertThrows(RuntimeException.class, () -> hasura.checkConstraints(planId));
98-
final var message = exception.getMessage().split("\"message\":\"")[1].split("\"}]")[0];
99-
// Hasura strips the cause message ("Assumption falsified -- mission model for existing plan does not exist")
100-
// from the error it returns
98+
final var exception = assertThrows(HasuraRequestFailure.class, () -> hasura.checkConstraints(planId));
99+
100+
// Check the response message
101101
final var expectedMessage = "plan with id " + planId + " has not yet been simulated at its current revision";
102-
if (!message.equals(expectedMessage)) {
103-
throw exception;
104-
}
102+
assertEquals(expectedMessage, exception.getMessage());
103+
104+
// Check the attached extensions object
105+
final var extensions = exception.getExtensions();
106+
assertEquals("INPUT_MISMATCH_EXCEPTION", extensions.getString("type"));
107+
assertEquals(expectedMessage, extensions.getString("message"));
108+
assertEquals("aerie_merlin", extensions.getString("service"));
105109
}
106110

107111
@Test

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/bindings/MerlinBindingsTests.java

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void invalidPlanId() {
110110
.toString();
111111
final var response = request.post("/getSimulationResults", RequestOptions.create().setData(data));
112112
assertEquals(404, response.status());
113-
assertEquals("no such plan", getBody(response).getString("message"));
113+
assertEquals("No plan exists with id `-1`", getBody(response).getString("message"));
114114
}
115115

116116
@Test
@@ -184,7 +184,6 @@ class ResourceSamples {
184184
@Test
185185
void invalidPlanId() {
186186
// Returns a 404 if the PlanId is invalid
187-
// message is "no such plan"
188187
final String data = Json.createObjectBuilder()
189188
.add("action", Json.createObjectBuilder().add("name", "resource_samples"))
190189
.add("input", Json.createObjectBuilder().add("planId", -1))
@@ -194,7 +193,7 @@ void invalidPlanId() {
194193
.toString();
195194
final var response = request.post("/resourceSamples", RequestOptions.create().setData(data));
196195
assertEquals(404, response.status());
197-
assertEquals("no such plan", getBody(response).getString("message"));
196+
assertEquals("No plan exists with id `-1`", getBody(response).getString("message"));
198197
}
199198

200199
@Test
@@ -259,13 +258,12 @@ void invalidPlanId() {
259258
.toString();
260259
final var response = request.post("/constraintViolations", RequestOptions.create().setData(data));
261260
assertEquals(404, response.status());
262-
assertEquals("no such plan", getBody(response).getString("message"));
261+
assertEquals("No plan exists with id `-1`", getBody(response).getString("message"));
263262
}
264263

265264
@Test
266265
void invalidSimDatasetId() throws IOException {
267266
// Returns a 404 if the SimDatasetId is invalid
268-
// Message is an "input mismatch exception"
269267
hasura.awaitSimulation(planId);
270268
final String data = Json.createObjectBuilder()
271269
.add("action", Json.createObjectBuilder().add("name", "check_constraints"))
@@ -279,15 +277,17 @@ void invalidSimDatasetId() throws IOException {
279277
.toString();
280278
final var response = request.post("/constraintViolations", RequestOptions.create().setData(data));
281279
assertEquals(404, response.status());
282-
final var expectedResponse = Json.createObjectBuilder()
283-
.add("message", "input mismatch exception")
284-
.add(
285-
"extensions", Json.createObjectBuilder()
286-
.add(
287-
"cause",
288-
"simulation dataset with id `-1` does not exist"))
289-
.build();
290-
assertEquals(expectedResponse, getBody(response));
280+
281+
final var body = getBody(response);
282+
final var extensions = body.getJsonObject("extensions");
283+
// Check the message field
284+
final var expectedMessage = "simulation dataset with id `-1` does not exist";
285+
assertEquals(expectedMessage, body.getString("message"));
286+
287+
// Check the extensions
288+
assertEquals("INPUT_MISMATCH_EXCEPTION", extensions.getString("type"));
289+
assertEquals(expectedMessage, extensions.getString("message"));
290+
assertEquals("aerie_merlin", extensions.getString("service"));
291291
}
292292

293293
@Test
@@ -303,7 +303,6 @@ void incorrectSimDatasetId() throws IOException {
303303
final int simDatasetId = hasura.awaitSimulation(secondPlanId).simDatasetId();
304304

305305
// Returns a 404 because the simDataset belonged to a different plan
306-
// Message is 'simulation dataset mismatch exception'
307306
final String data = Json.createObjectBuilder()
308307
.add("action", Json.createObjectBuilder().add("name", "check_constraints"))
309308
.add(
@@ -316,13 +315,19 @@ void incorrectSimDatasetId() throws IOException {
316315
.toString();
317316
final var response = request.post("/constraintViolations", RequestOptions.create().setData(data));
318317
assertEquals(404, response.status());
319-
final var expectedCause =
320-
"Simulation Dataset with id `" + simDatasetId + "` does not belong to Plan with id `" + planId + "`";
321-
final var expectedResponse = Json.createObjectBuilder()
322-
.add("message", "simulation dataset mismatch exception")
323-
.add("extensions", Json.createObjectBuilder().add("cause", expectedCause))
324-
.build();
325-
assertEquals(expectedResponse, getBody(response));
318+
319+
// Check the response
320+
final var body = getBody(response);
321+
final var extensions = body.getJsonObject("extensions");
322+
323+
// Check the message field
324+
final var expectedMessage = "Simulation Dataset with id `" + simDatasetId + "` does not belong to Plan with id `" + planId + "`";
325+
assertEquals(expectedMessage, body.getString("message"));
326+
327+
// Check the extensions object
328+
assertEquals("SIM_DATASET_MISMATCH_EXCEPTION", extensions.getString("type"));
329+
assertEquals(expectedMessage, extensions.getString("message"));
330+
assertEquals("aerie_merlin", extensions.getString("service"));
326331
} finally {
327332
hasura.deletePlan(secondPlanId);
328333
}
@@ -358,12 +363,19 @@ void noSimDatasets() {
358363
.toString();
359364
final var response = request.post("/constraintViolations", RequestOptions.create().setData(data));
360365
assertEquals(404, response.status());
361-
final var expectedCause = "plan with id " + planId + " has not yet been simulated at its current revision";
362-
final var expectedBody = Json.createObjectBuilder()
363-
.add("message", "input mismatch exception")
364-
.add("extensions", Json.createObjectBuilder().add("cause", expectedCause))
365-
.build();
366-
assertEquals(expectedBody, getBody(response));
366+
367+
// Check the response
368+
final var body = getBody(response);
369+
final var extensions = body.getJsonObject("extensions");
370+
371+
// Check the message field
372+
final var expectedMessage = "plan with id " + planId + " has not yet been simulated at its current revision";
373+
assertEquals(expectedMessage, body.getString("message"));
374+
375+
// Check the extensions object
376+
assertEquals("INPUT_MISMATCH_EXCEPTION", extensions.getString("type"));
377+
assertEquals(expectedMessage, extensions.getString("message"));
378+
assertEquals("aerie_merlin", extensions.getString("service"));
367379
}
368380

369381
@Test
@@ -434,7 +446,7 @@ void invalidMissionModelId() {
434446
.toString();
435447
final var response = request.post("/refreshModelParameters", RequestOptions.create().setData(data));
436448
assertEquals(404, response.status());
437-
assertEquals("no such mission model", getBody(response).getString("message"));
449+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
438450
}
439451

440452
@Test
@@ -474,7 +486,7 @@ void invalidMissionModelId() {
474486
.toString();
475487
final var response = request.post("/refreshActivityTypes", RequestOptions.create().setData(data));
476488
assertEquals(404, response.status());
477-
assertEquals("no such mission model", getBody(response).getString("message"));
489+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
478490
}
479491

480492
@Test
@@ -502,7 +514,6 @@ class RefreshResourceTypes {
502514
@Test
503515
void invalidMissionModelId() {
504516
// Returns a 404 if the MissionModelId is invalid
505-
// message is "no such mission model"
506517
final String data = Json.createObjectBuilder()
507518
.add(
508519
"event", Json.createObjectBuilder()
@@ -514,7 +525,7 @@ void invalidMissionModelId() {
514525
.toString();
515526
final var response = request.post("/refreshResourceTypes", RequestOptions.create().setData(data));
516527
assertEquals(404, response.status());
517-
assertEquals("no such mission model", getBody(response).getString("message"));
528+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
518529
}
519530

520531
@Test
@@ -542,7 +553,6 @@ class ValidateActivityArguments {
542553
@Test
543554
void invalidMissionModelId() {
544555
// Returns a 404 if the MissionModelId is invalid
545-
// message is "no such mission model"
546556
final String data = Json.createObjectBuilder()
547557
.add("action", Json.createObjectBuilder().add("name", "validateActivityArguments"))
548558
.add(
@@ -556,7 +566,10 @@ void invalidMissionModelId() {
556566
.toString();
557567
final var response = request.post("/validateActivityArguments", RequestOptions.create().setData(data));
558568
assertEquals(404, response.status());
559-
assertEquals("no such mission model", getBody(response).getString("message"));
569+
final var body = getBody(response);
570+
assertEquals("No mission model exists with id `-1`", body.getString("message"));
571+
assertTrue(body.containsKey("extensions"));
572+
assertEquals("NO_SUCH_MISSION_MODEL", body.getJsonObject("extensions").getString("type"));
560573
}
561574

562575
@Test
@@ -585,7 +598,6 @@ class ValidateModelArguments {
585598
@Test
586599
void invalidMissionModelId() {
587600
// Returns a 404 if the MissionModelId is invalid
588-
// message is "no such mission model"
589601
final String data = Json.createObjectBuilder()
590602
.add("action", Json.createObjectBuilder().add("name", "validateModelArguments"))
591603
.add(
@@ -598,7 +610,7 @@ void invalidMissionModelId() {
598610
.toString();
599611
final var response = request.post("/validateModelArguments", RequestOptions.create().setData(data));
600612
assertEquals(404, response.status());
601-
assertEquals("no such mission model", getBody(response).getString("message"));
613+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
602614
}
603615

604616
@Test
@@ -636,7 +648,7 @@ void invalidPlanId() {
636648
.toString();
637649
final var response = request.post("/validatePlan", RequestOptions.create().setData(data));
638650
assertEquals(404, response.status());
639-
assertEquals("no such plan", getBody(response).getString("message"));
651+
assertEquals("No plan exists with id `-1`", getBody(response).getString("message"));
640652
}
641653

642654
@Test
@@ -674,7 +686,7 @@ void invalidMissionModelId() {
674686
.toString();
675687
final var response = request.post("/getModelEffectiveArguments", RequestOptions.create().setData(data));
676688
assertEquals(404, response.status());
677-
assertEquals("no such mission model", getBody(response).getString("message"));
689+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
678690
}
679691

680692
@Test
@@ -733,7 +745,7 @@ void invalidMissionModelId() {
733745
.toString();
734746
final var response = request.post("/getActivityEffectiveArgumentsBulk", RequestOptions.create().setData(data));
735747
assertEquals(404, response.status());
736-
assertEquals("no such mission model", getBody(response).getString("message"));
748+
assertEquals("No mission model exists with id `-1`", getBody(response).getString("message"));
737749
}
738750

739751
@Test
@@ -818,7 +830,7 @@ void invalidPlanId() {
818830
.toString();
819831
final var response = request.post("/addExternalDataset", RequestOptions.create().setData(data));
820832
assertEquals(404, response.status());
821-
assertEquals("no such plan", getBody(response).getString("message"));
833+
assertEquals("No plan exists with id `-1`", getBody(response).getString("message"));
822834
}
823835

824836
@Test
@@ -885,7 +897,7 @@ void invalidDatasetId() {
885897
.toString();
886898
final var response = request.post("/extendExternalDataset", RequestOptions.create().setData(data));
887899
assertEquals(404, response.status());
888-
assertEquals("no such plan dataset", getBody(response).getString("message"));
900+
assertEquals("No plan dataset exists with id `-1`", getBody(response).getString("message"));
889901
}
890902

891903
@Test

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/bindings/SchedulerBindingsTests.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class Schedule{
8989
@Test
9090
void invalidSpecId(){
9191
// Returns a 404 if the SpecId is invalid
92-
// message is "no such scheduling specification"
9392
final String data = Json.createObjectBuilder()
9493
.add("action", Json.createObjectBuilder().add("name", "scheduler"))
9594
.add("input", Json.createObjectBuilder().add("specificationId", -1))
@@ -99,7 +98,19 @@ void invalidSpecId(){
9998
.toString();
10099
final var response = request.post("/schedule", RequestOptions.create().setData(data));
101100
assertEquals(404, response.status());
102-
assertEquals("no such scheduling specification", getBody(response).getString("message"));
101+
102+
// Check the response
103+
final var body = getBody(response);
104+
final var extensions = body.getJsonObject("extensions");
105+
106+
// Check the message field
107+
final var expectedMessage = "Could not check permissions on scheduling specification -1: specification does not exist.";
108+
assertEquals(expectedMessage, body.getString("message"));
109+
110+
// Check the extensions object
111+
assertEquals("NO_SUCH_SCHEDULING_SPECIFICATION", extensions.getString("type"));
112+
assertEquals(expectedMessage, extensions.getString("message"));
113+
assertEquals("aerie_permissions", extensions.getString("service"));
103114
}
104115
@Test
105116
void forbidden(){
@@ -172,7 +183,7 @@ void invalidPlanId() {
172183
assertEquals(200, response.status());
173184
final var expectedBody = Json.createObjectBuilder()
174185
.add("status", "failure")
175-
.add("reason", "No plan exists with id `PlanId[id=-1]`")
186+
.add("reason", "No plan exists with id `-1`")
176187
.build();
177188
assertEquals(expectedBody, getBody(response));
178189
}

e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/bindings/workspace/MetadataWorkspaceRoutesTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void forbiddenInsufficientPrivileges() {
231231
assertEquals("FORBIDDEN", body.getString("type"));
232232
assertEquals("Role 'viewer' is not allowed to perform action 'write_file_directory'",
233233
body.getString("message"));
234-
assertEquals("aerie_workspace", body.getString("service"));
234+
assertEquals("aerie_permissions", body.getString("service"));
235235
}
236236

237237
/**
@@ -247,7 +247,7 @@ void forbiddenNotOwner() {
247247
assertEquals(("User '%s' with role 'user' cannot perform 'write_file_directory' "
248248
+ "because they are not a 'OWNER_COLLABORATOR' for workspace with id '%d'").formatted(nonOwner.name(), workspaceId),
249249
body.getString("message"));
250-
assertEquals("aerie_workspace", body.getString("service"));
250+
assertEquals("aerie_permissions", body.getString("service"));
251251
}
252252

253253
/**
@@ -259,7 +259,7 @@ void noSuchWorkspace() {
259259
assertEquals(404, resp.status());
260260
final var body = getBody(resp);
261261
assertEquals("NO_SUCH_WORKSPACE", body.getString("type"));
262-
assertEquals("Could not check permissions on Workspace -1.", body.getString("message"));
262+
assertEquals("Could not check permissions on workspace -1: workspace does not exist.", body.getString("message"));
263263
}
264264

265265
/**
@@ -719,7 +719,7 @@ void forbiddenInsufficientPrivileges() {
719719
assertEquals("FORBIDDEN", body.getString("type"));
720720
assertEquals("Role 'viewer' is not allowed to perform action 'write_file_directory'",
721721
body.getString("message"));
722-
assertEquals("aerie_workspace", body.getString("service"));
722+
assertEquals("aerie_permissions", body.getString("service"));
723723
}
724724

725725
/**
@@ -735,7 +735,7 @@ void forbiddenNotOwner() {
735735
assertEquals(("User '%s' with role 'user' cannot perform 'write_file_directory' "
736736
+ "because they are not a 'OWNER_COLLABORATOR' for workspace with id '%d'").formatted(nonOwner.name(), workspaceId),
737737
body.getString("message"));
738-
assertEquals("aerie_workspace", body.getString("service"));
738+
assertEquals("aerie_permissions", body.getString("service"));
739739
}
740740

741741
/**
@@ -747,7 +747,7 @@ void noSuchWorkspace() {
747747
assertEquals(404, resp.status());
748748
final var body = getBody(resp);
749749
assertEquals("NO_SUCH_WORKSPACE", body.getString("type"));
750-
assertEquals("Could not check permissions on Workspace -1.", body.getString("message"));
750+
assertEquals("Could not check permissions on workspace -1: workspace does not exist.", body.getString("message"));
751751
}
752752

753753
/**
@@ -1099,7 +1099,7 @@ void forbiddenInsufficientPrivileges() {
10991099
assertEquals("FORBIDDEN", body.getString("type"));
11001100
assertEquals(("Role 'viewer' is not allowed to perform action 'delete_file_directory'"),
11011101
body.getString("message"));
1102-
assertEquals("aerie_workspace", body.getString("service"));
1102+
assertEquals("aerie_permissions", body.getString("service"));
11031103
}
11041104

11051105
/**
@@ -1115,7 +1115,7 @@ void forbiddenNotOwner() {
11151115
assertEquals(("User '%s' with role 'user' cannot perform 'delete_file_directory' "
11161116
+ "because they are not a 'OWNER_COLLABORATOR' for workspace with id '%d'").formatted(nonOwner.name(), workspaceId),
11171117
body.getString("message"));
1118-
assertEquals("aerie_workspace", body.getString("service"));
1118+
assertEquals("aerie_permissions", body.getString("service"));
11191119
}
11201120

11211121
/**
@@ -1127,7 +1127,7 @@ void noSuchWorkspace() {
11271127
assertEquals(404, resp.status());
11281128
final var body = getBody(resp);
11291129
assertEquals("NO_SUCH_WORKSPACE", body.getString("type"));
1130-
assertEquals("Could not check permissions on Workspace -1.", body.getString("message"));
1130+
assertEquals("Could not check permissions on workspace -1: workspace does not exist.", body.getString("message"));
11311131
}
11321132

11331133
/**

0 commit comments

Comments
 (0)