diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java index cf47ded8..0252b7da 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -60,7 +60,7 @@ public class BatchMappingPrincipalMethodArgumentResolverTests extends BatchMappi ReactiveSecurityContextHolder.withAuthentication(this.authentication); private final Function threadLocalContextWriter = context -> - ContextSnapshot.captureAll().updateContext(context); + ContextSnapshotFactory.builder().build().captureAll().updateContext(context); private static Stream controllers() { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java index 49e4e949..780cbe07 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import java.util.function.Function; import graphql.GraphqlErrorBuilder; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -70,8 +71,10 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests { private final Function reactiveContextWriterWithoutAuthentication = context -> ReactiveSecurityContextHolder.withSecurityContext(Mono.just(SecurityContextHolder.createEmptyContext())); - private final Function threadLocalContextWriter = context -> - ContextSnapshot.captureAll().updateContext(context); + private final Function threadLocalContextWriter = context -> { + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + return snapshot.updateContext(context); + }; private final GreetingController greetingController = new GreetingController(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java index 2181a47f..e079acea 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import graphql.GraphQLError; import graphql.GraphqlErrorBuilder; import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -109,7 +110,8 @@ public class CompositeSubscriptionExceptionResolverTests { .toGraphQl(); ExecutionInput input = ExecutionInput.newExecutionInput(query).build(); - ContextSnapshot.captureAll().updateContext(input.getGraphQLContext()); + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + snapshot.updateContext(input.getGraphQLContext()); Flux flux = Mono.defer(() -> Mono.fromFuture(graphQL.executeAsync(input))) .map(ResponseHelper::forSubscription) diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java index ab9968e6..698108ae 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/ContextDataFetcherDecoratorTests.java @@ -37,6 +37,7 @@ import graphql.schema.idl.SchemaDirectiveWiring; import graphql.schema.idl.SchemaDirectiveWiringEnvironment; import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -181,7 +182,8 @@ public class ContextDataFetcherDecoratorTests { .toGraphQl(); ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build(); - ContextSnapshot.captureAll().updateContext(input.getGraphQLContext()); + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + snapshot.updateContext(input.getGraphQLContext()); Mono resultMono = Mono.delay(Duration.ofMillis(10)) .flatMap((aLong) -> Mono.fromFuture(graphQl.executeAsync(input))); @@ -202,7 +204,7 @@ public class ContextDataFetcherDecoratorTests { @SuppressWarnings("unchecked") @Override public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment env) { - if (env.getDirective("UpperCase") != null) { + if (env.getAppliedDirective("UpperCase") != null) { return env.setFieldDataFetcher(DataFetcherFactories.wrapDataFetcher( env.getFieldDataFetcher(), ((dataFetchingEnv, value) -> { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java index 0c086e54..35140500 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import graphql.ExecutionResult; import graphql.GraphqlErrorBuilder; import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -100,7 +101,8 @@ public class ExceptionResolversExceptionHandlerTests { .build()); resolver.setThreadLocalContextAware(true); - ContextSnapshot.captureAll().updateContext(this.input.getGraphQLContext()); + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + snapshot.updateContext(this.input.getGraphQLContext()); Mono result = Mono.delay(Duration.ofMillis(10)).flatMap((aLong) -> Mono.fromFuture(this.graphQlSetup.exceptionResolver(resolver).toGraphQl().executeAsync(this.input))); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandlerTests.java index a70cc013..7383ac47 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandlerTests.java @@ -31,6 +31,7 @@ import java.util.function.Consumer; import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; +import io.micrometer.context.ContextSnapshotFactory; import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -403,7 +404,8 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { GraphQlWebSocketHandler handler = initWebSocketHandler(threadLocalInterceptor); // Ensure ContextSnapshot is present in WebSocketSession attributes - this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll()); + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + this.session.getAttributes().put(ContextSnapshot.class.getName(), snapshot); // Context should propagate, if message is handled on different thread Thread thread = new Thread(() -> { @@ -452,7 +454,8 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { if (!this.session.getAttributes().containsKey(ContextSnapshot.class.getName())) { // Ensure ContextSnapshot is present in WebSocketSession attributes - this.session.getAttributes().put(ContextSnapshot.class.getName(), ContextSnapshot.captureAll()); + ContextSnapshot snapshot = ContextSnapshotFactory.builder().build().captureAll(); + this.session.getAttributes().put(ContextSnapshot.class.getName(), snapshot); } for (TextMessage message : textMessages) {