Skip to content

Commit

Permalink
Updated the e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrrGit committed Nov 27, 2023
1 parent 61d6a31 commit a66518c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void constraintsSucceedOneViolation() throws IOException {
// Check the Result
final var constraintResponse = constraintsResponses.get(0);
assertTrue(constraintResponse.success());
assertEquals(constraintResponse.constraintId(),constraintId);
assertTrue(constraintResponse.result().isPresent());
final var constraintResult = constraintResponse.result().get();
assertEquals(constraintId, constraintResult.constraintId());
Expand Down Expand Up @@ -140,6 +141,7 @@ void constraintsSucceedNoViolations() throws IOException {

assertEquals(1, constraintResponses.size());
assertTrue( constraintResponses.get(0).success());
assertEquals(constraintResponses.get(0).constraintId(),constraintId);
assertTrue( constraintResponses.get(0).result().isPresent());
assertEquals(0, constraintResponses.get(0).result().get().violations().size());
}
Expand All @@ -153,6 +155,7 @@ void constraintCachedViolation() throws IOException {
// There's the correct number of results
assertEquals(1, cachedRuns.size());
assertEquals(1, constraintResponses.size());
assertEquals(cachedRuns.get(0).constraintId(),constraintId);

// Check properties
final var cachedRun = cachedRuns.get(0);
Expand Down Expand Up @@ -243,8 +246,10 @@ void constraintsWorkMonthLongActivity() throws IOException {
// Check the Result
final var constraintResponse = constraintsResponses.get(0);
assertTrue(constraintResponse.success());
assertEquals(constraintResponse.constraintId(),constraintId);
assertTrue(constraintResponse.result().isPresent());
final var constraintResult = constraintResponse.result().get();

assertEquals(constraintId, constraintResult.constraintId());
assertEquals(constraintName, constraintResult.constraintName());

Expand Down Expand Up @@ -276,6 +281,7 @@ void runConstraintsOnOldSimulation() throws IOException {
assertEquals(1, newConstraintResponses.size());
assertTrue(newConstraintResponses.get(0).result().isPresent());
final var newConstraintResult = newConstraintResponses.get(0).result().get();
assertEquals(newConstraintResult.constraintId(),constraintId);
assertTrue(newConstraintResult.violations().isEmpty());


Expand All @@ -286,6 +292,7 @@ void runConstraintsOnOldSimulation() throws IOException {
// Check the Result
final var oldConstraintResponse = oldConstraintsResponses.get(0);
assertTrue(oldConstraintResponse.success());
assertEquals(oldConstraintResponse.constraintId(),constraintId);
assertTrue(oldConstraintResponse.result().isPresent());
final var constraintResult = oldConstraintResponse.result().get();

Expand Down Expand Up @@ -372,13 +379,15 @@ void oneViolationCurrentSimulation() throws IOException {
final var noDatasetResponses = hasura.checkConstraints(planId);
assertEquals(1, noDatasetResponses.size());
assertTrue(noDatasetResponses.get(0).success());
assertEquals(noDatasetResponses.get(0).constraintId(),constraintId);
assertTrue(noDatasetResponses.get(0).result().isPresent());
final var nRecordResults = noDatasetResponses.get(0).result().get();

// Constraint Results w/ SimDatasetId
final var withDatasetResponses = hasura.checkConstraints(planId, simDatasetId);
assertEquals(1, withDatasetResponses.size());
assertTrue( withDatasetResponses.get(0).success());
assertTrue(withDatasetResponses.get(0).success());
assertEquals(withDatasetResponses.get(0).constraintId(),constraintId);
assertTrue(withDatasetResponses.get(0).result().isPresent());
final var wRecordResults = withDatasetResponses.get(0).result().get();

Expand Down Expand Up @@ -432,6 +441,7 @@ void oneViolationOutdatedSimIdPassed() throws IOException {

final var constraintResponse = constraintResponses.get(0);
assertTrue(constraintResponse.success());
assertEquals(constraintResponse.constraintId(),constraintId);
assertTrue(constraintResponse.result().isPresent());
final var record = constraintResponse.result().get();

Expand Down Expand Up @@ -481,6 +491,7 @@ void compilationFailsOutdatedSimulationSimDatasetId() throws IOException {
final var constraintResponses = hasura.checkConstraints(planId, newSimDatasetId);
assertEquals(1,constraintResponses.size());
final var constraintResponse = constraintResponses.get(0);
assertEquals(constraintResponse.constraintId(),constraintId);
assertFalse(constraintResponse.success());
assertTrue(constraintResponse.result().isEmpty());
assertEquals(1,constraintResponse.errors().size());
Expand All @@ -502,6 +513,7 @@ void compilationFailsOutdatedSimulationNoSimDataset() throws IOException {
assertEquals(1,constraintResponses.size());
final var constraintResponse = constraintResponses.get(0);
assertFalse(constraintResponse.success());
assertEquals(constraintResponse.constraintId(),constraintId);
assertTrue(constraintResponse.result().isEmpty());
assertEquals(1,constraintResponse.errors().size());
final ConstraintError error = constraintResponse.errors().get(0);
Expand All @@ -526,7 +538,7 @@ void constraintInvalidModification() throws IOException {
final var constraintsResponses = hasura.checkConstraints(planId);
assertEquals(1, constraintsResponses.size());
assertTrue(constraintsResponses.get(0).success());

assertEquals(constraintsResponses.get(0).constraintId(),constraintId);
// Attempt to update a constraint with an invalid syntax and capture the error response
hasura.updateConstraint(
constraintId,
Expand All @@ -536,6 +548,7 @@ void constraintInvalidModification() throws IOException {
final var constraintsErrorResponses = hasura.checkConstraints(planId);
assertEquals(1, constraintsErrorResponses.size());
assertFalse(constraintsErrorResponses.get(0).success());
assertEquals(constraintsErrorResponses.get(0).constraintId(),constraintId);
assertTrue(constraintsErrorResponses.get(0).result().isEmpty());
assertEquals(1, constraintsErrorResponses.get(0).errors().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

public record ConstraintRecord(
boolean success,
int constraintId,
Optional<ConstraintResult> result,
List<ConstraintError> errors

) {
public static ConstraintRecord fromJSON(JsonObject json){
return new ConstraintRecord(
json.getBoolean("success"),
json.getInt("constraintId"),
json.getJsonObject("results").isEmpty() ? Optional.empty() : Optional.of(ConstraintResult.fromJSON(json.getJsonObject("results"))),
json.getJsonArray("errors").getValuesAs(ConstraintError::fromJSON));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mutation cancelSimulation($id: Int!) {
query checkConstraints($planId: Int!, $simulationDatasetId: Int) {
constraintViolations(planId: $planId, simulationDatasetId: $simulationDatasetId) {
success
constraintId
results {
constraintId
constraintName
Expand Down

0 comments on commit a66518c

Please sign in to comment.