diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ConstraintsTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ConstraintsTests.java index a0fafe6375..1277d7b119 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ConstraintsTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ConstraintsTests.java @@ -13,6 +13,7 @@ import javax.json.Json; import javax.json.JsonValue; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -137,7 +138,10 @@ void constraintsSucceedNoViolations() throws IOException { hasura.deleteActivity(planId, activityId); hasura.awaitSimulation(planId); final var constraintsResults = hasura.checkConstraints(planId); - assertEquals(0, constraintsResults.size()); + + assertEquals(1, constraintsResults.size()); + assertEquals(true, constraintsResults.get(0).success()); + assertEquals(0, constraintsResults.get(0).result().violations().size()); } @Test @@ -183,7 +187,7 @@ void constraintCachedNoViolations() throws IOException { assertEquals(constraintDefinition, cachedRun.constraintDefinition()); // Check results - assertTrue(cachedRun.results().isEmpty()); + assertTrue(!cachedRun.results().isEmpty()); } @Test @@ -258,7 +262,7 @@ void runConstraintsOnOldSimulation() throws IOException { // Expect no violations on the new simulation final var newConstraintResults = hasura.checkConstraints(planId, newSimDatasetId); - assertEquals(0, newConstraintResults.size()); + assertEquals(1, newConstraintResults.size()); // Expect one violation on the old simulation final var oldConstraintsResponses = hasura.checkConstraints(planId, oldSimDatasetId); @@ -460,7 +464,8 @@ void compilationFailsOutdatedSimulationSimDatasetId() throws IOException { assertEquals(false,constraintRepsonse.success()); assertEquals(1,constraintRepsonse.errors().size()); final ConstraintError error = constraintRepsonse.errors().get(0); - assertEquals("Constraint 'fruit_equal_peel': TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message()); + assertEquals("Constraint 'fruit_equal_peel' compilation failed:\n" + + " TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message()); } @Test @@ -478,7 +483,39 @@ void compilationFailsOutdatedSimulationNoSimDataset() throws IOException { assertEquals(false,constraintRepsonse.success()); assertEquals(1,constraintRepsonse.errors().size()); final ConstraintError error = constraintRepsonse.errors().get(0); - assertEquals("Constraint 'fruit_equal_peel': TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message()); + assertEquals("Constraint 'fruit_equal_peel' compilation failed:\n" + + " TypeError: TS2345 Argument of type '\"/my_boolean\"' is not assignable to parameter of type 'ResourceName'.",error.message()); + + } + + @Test + @DisplayName("A modified and recompiled constraint that originally compiled successfully.") + void constraintInvalidModification() throws IOException { + + hasura.awaitSimulation(planId); + var constraintsResponses = hasura.checkConstraints(planId); + + assertEquals(1, constraintsResponses.size()); + assertEquals(true, constraintsResponses.get(0).success()); + + hasura.updateConstraint( + constraintId, + constraintDefinition+"compilation error"); + + var constraintsErrorResponses = hasura.checkConstraints(planId); + + assertEquals(1, constraintsErrorResponses.size()); + assertEquals(false, constraintsErrorResponses.get(0).success()); + assertEquals(3 , constraintsErrorResponses.get(0).errors().size()); + + hasura.updateConstraint( + constraintId, + constraintDefinition); + constraintsResponses = hasura.checkConstraints(planId); + + assertEquals(1, constraintsResponses.size()); + assertEquals(true, constraintsResponses.get(0).success()); + } } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ConstraintRecord.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ConstraintRecord.java index 4da7467845..52d5c82462 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ConstraintRecord.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/types/ConstraintRecord.java @@ -3,6 +3,7 @@ import javax.json.JsonNumber; import javax.json.JsonObject; import javax.json.JsonString; +import java.util.ArrayList; import java.util.List; public record ConstraintRecord( @@ -14,7 +15,7 @@ public record ConstraintRecord( public static ConstraintRecord fromJSON(JsonObject json){ return new ConstraintRecord( json.getBoolean("success"), - json.getJsonObject("results").isEmpty() ? null : ConstraintResult.fromJSON(json.getJsonObject("results")), + json.getJsonObject("results").isEmpty() ? new ConstraintResult(-1,"","",new ArrayList<>(), new ArrayList<>(),new ArrayList<>()) : ConstraintResult.fromJSON(json.getJsonObject("results")), json.getJsonArray("errors").getValuesAs(ConstraintError::fromJSON)); } }