Skip to content

Commit

Permalink
Adjust ConstraintAction error messages
Browse files Browse the repository at this point in the history
The errors will now correctly distinguish between a plan never being simulated and a specified sim dataset not existing.
Additionally, the serialializer for SimDatasetMismatch now refers to the correct extension.
  • Loading branch information
Mythicaeda committed Oct 3, 2023
1 parent aeb8710 commit 07462aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
16 changes: 15 additions & 1 deletion e2e-tests/src/tests/bindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ test.describe('Merlin Bindings', () => {
expect(response.status()).toEqual(404);
expect((await response.json()).message).toEqual('no such plan');

// Returns a 404 if the SimulationDataset id is invalid
// message is "input mismatch exception"
response = await request.post(`${urls.MERLIN_URL}/constraintViolations`, {
data: {
action: {name: "check_constraints"},
input: {planId: plan_id, simulationDatasetId: -1},
request_query: "",
session_variables: admin.session}});
expect(response.status()).toEqual(404);
expect((await response.json())).toEqual({

Check failure on line 194 in e2e-tests/src/tests/bindings.test.ts

View workflow job for this annotation

GitHub Actions / e2e-test

src/tests/bindings.test.ts:173:3 › Merlin Bindings › ConstraintViolations

1) src/tests/bindings.test.ts:173:3 › Merlin Bindings › ConstraintViolations ===================== Error: expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 1 Object { "cause": "simulation dataset with id `-1` does not exist", - "message": "simulation dataset mismatch exception", + "message": "input mismatch exception", } 192 | session_variables: admin.session}}); 193 | expect(response.status()).toEqual(404); > 194 | expect((await response.json())).toEqual({ | ^ 195 | message: "simulation dataset mismatch exception", 196 | cause: "simulation dataset with id `-1` does not exist" 197 | }); at file:///home/runner/work/***/***/e2e-tests/src/tests/bindings.test.ts:194:37
message: "simulation dataset mismatch exception",
cause: "simulation dataset with id `-1` does not exist"
});

// Returns a 403 if unauthorized
response = await request.post(`${urls.MERLIN_URL}/constraintViolations`, {
data: {
Expand Down Expand Up @@ -218,7 +232,7 @@ test.describe('Merlin Bindings', () => {
session_variables: admin.session}});
expect(response.status()).toEqual(404);
expect((await response.json())).toEqual({
message: "input mismatch exception",
message: "simulation dataset mismatch exception",
cause: "Simulation Dataset with id `" + invalidSimDatasetId + "` does not belong to Plan with id `"+plan_id+"`"
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public static JsonValue serializeInputMismatchException(final InputMismatchExcep

public static JsonValue serializeSimulationDatasetMismatchException(final SimulationDatasetMismatchException ex){
return Json.createObjectBuilder()
.add("message", "input mismatch exception")
.add("message", "simulation dataset mismatch exception")
.add("cause", ex.getMessage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ public List<ConstraintResult> getViolations(final PlanId planId, final Optional<
throws NoSuchPlanException, MissionModelService.NoSuchMissionModelException, SimulationDatasetMismatchException {
final var plan = this.planService.getPlanForValidation(planId);
final Optional<SimulationResultsHandle> resultsHandle$;
final SimulationDatasetId simDatasetId;
if (simulationDatasetId.isPresent()) {
resultsHandle$ = this.simulationService.get(planId, simulationDatasetId.get());
simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("simulation dataset with id `" + simulationDatasetId.get().id() + "` does not exist"));
} else {
final var revisionData = this.planService.getPlanRevisionData(planId);
resultsHandle$ = this.simulationService.get(planId, revisionData);
simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("no simulation datasets found for plan id " + planId.id()));
}


Expand All @@ -68,9 +75,6 @@ public List<ConstraintResult> getViolations(final PlanId planId, final Optional<
throw new RuntimeException("Assumption falsified -- mission model for existing plan does not exist");
}

final var simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("no simulation datasets found for plan id " + planId.id()));
final var violations = new HashMap<Long, ConstraintResult>();

final var validConstraintRuns = this.constraintService.getValidConstraintRuns(constraintCode.values().stream().toList(), simDatasetId);
Expand Down

0 comments on commit 07462aa

Please sign in to comment.