diff --git a/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java b/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java index 1f926f96..67c61c1c 100644 --- a/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java +++ b/samples/webflux-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java @@ -66,8 +66,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.UNAUTHORIZED.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.UNAUTHORIZED); }); } @@ -86,8 +85,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.FORBIDDEN.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.FORBIDDEN); }); } @@ -118,8 +116,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.UNAUTHORIZED.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.UNAUTHORIZED); }); } diff --git a/samples/webmvc-http-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java b/samples/webmvc-http-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java index 60e14f91..42141303 100644 --- a/samples/webmvc-http-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java +++ b/samples/webmvc-http-security/src/test/java/io/spring/sample/graphql/SampleApplicationTests.java @@ -51,8 +51,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.UNAUTHORIZED.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.UNAUTHORIZED); }); } @@ -71,8 +70,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.FORBIDDEN.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.FORBIDDEN); }); } @@ -103,8 +101,7 @@ class SampleApplicationTests { .errors() .satisfy(errors -> { assertThat(errors).hasSize(1); - assertThat(errors.get(0).getExtensions().get("classification")) - .isEqualTo(ErrorType.UNAUTHORIZED.name()); + assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.UNAUTHORIZED); }); } diff --git a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/TestGraphQlError.java b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/TestGraphQlError.java index 699905c6..c945cda7 100644 --- a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/TestGraphQlError.java +++ b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/TestGraphQlError.java @@ -42,9 +42,6 @@ class TestGraphQlError implements GraphQLError { @Nullable private List locations; - @Nullable - private ErrorClassification errorType; - @Nullable private List path; @@ -75,15 +72,27 @@ class TestGraphQlError implements GraphQLError { return this.locations; } - @SuppressWarnings("unused") - void setErrorType(ErrorClassification errorType) { - this.errorType = errorType; - } - @Override @Nullable public ErrorClassification getErrorType() { - return this.errorType; + // Attempt the reverse of how errorType is serialized in GraphqlErrorHelper.toSpecification. + // However we can only do that for ErrorClassification enums that we know of. + String value = (getExtensions() != null ? (String) getExtensions().get("classification") : null); + if (value != null) { + try { + return graphql.ErrorType.valueOf(value); + } + catch (IllegalArgumentException ex) { + // ignore + } + try { + return org.springframework.graphql.execution.ErrorType.valueOf(value); + } + catch (IllegalArgumentException ex) { + // ignore + } + } + return null; } @SuppressWarnings("unused")