diff --git a/http-client-jdk/src/test/groovy/io/micronaut/http/client/jdk/SslSelfSignedSpec.groovy b/http-client-jdk/src/test/groovy/io/micronaut/http/client/jdk/SslSelfSignedSpec.groovy index 645fe510a3e..aadb282709c 100644 --- a/http-client-jdk/src/test/groovy/io/micronaut/http/client/jdk/SslSelfSignedSpec.groovy +++ b/http-client-jdk/src/test/groovy/io/micronaut/http/client/jdk/SslSelfSignedSpec.groovy @@ -19,25 +19,23 @@ class SslSelfSignedSpec extends Specification { @Shared String host = Optional.ofNullable(System.getenv(Environment.HOSTNAME)).orElse(SocketUtils.LOCALHOST) - ApplicationContext context EmbeddedServer embeddedServer HttpClient client void setup() { - context = ApplicationContext.run([ + embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'SslSelfSignedSpec', 'micronaut.ssl.enabled': true, 'micronaut.server.ssl.buildSelfSigned': true, 'micronaut.server.ssl.port': -1, 'micronaut.http.client.ssl.insecure-trust-all-certificates': true, ]) - embeddedServer = context.getBean(EmbeddedServer).start() - client = context.createBean(HttpClient, embeddedServer.getURL()) + client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) } void cleanup() { client.close() - context.close() + embeddedServer.close() } void "expect the url to be https"() { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/ProxyInterceptFullResponseSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/ProxyInterceptFullResponseSpec.groovy index 61c051240fc..75e8d50ba0c 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/ProxyInterceptFullResponseSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/ProxyInterceptFullResponseSpec.groovy @@ -26,16 +26,13 @@ class ProxyInterceptFullResponseSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run( - 'spec.name': 'ProxyInterceptFullResponseSpec' + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, + ['spec.name': 'ProxyInterceptFullResponseSpec'] ) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - @Shared @AutoCleanup - HttpClient client = context.createBean(HttpClient, embeddedServer.getURL()) + HttpClient client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) void "test a request expecting a full response intercepted by a proxy providing a streaming response"() { expect: diff --git a/http-client/src/test/groovy/io/micronaut/http/client/ReadTimeoutSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/ReadTimeoutSpec.groovy index 9e3fb0f7a72..fa6288c5f5f 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/ReadTimeoutSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/ReadTimeoutSpec.groovy @@ -52,17 +52,14 @@ class ReadTimeoutSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run( + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ "micronaut.http.client.readTimeout": '3s', 'spec.name': 'ReadTimeoutSpec' - ) - - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() + ]) @Shared @AutoCleanup - HttpClient client = context.createBean(HttpClient, embeddedServer.getURL()) + HttpClient client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) void "test read timeout setting"() { @@ -321,12 +318,10 @@ class ReadTimeoutSpec extends Specification { void "test disable read timeout"() { given: - - ApplicationContext clientContext = ApplicationContext.run([ + EmbeddedServer server = ApplicationContext.run(EmbeddedServer, [ 'spec.name' : 'ReadTimeoutSpec', 'micronaut.http.client.read-timeout': '-1s']) - def server = clientContext.getBean(EmbeddedServer).start() - HttpClient client = clientContext.createBean(HttpClient, server.getURL()) + HttpClient client = server.applicationContext.createBean(HttpClient, server.getURL()) when: def result = client.toBlocking().retrieve(HttpRequest.GET('/timeout/client'), String) @@ -335,7 +330,7 @@ class ReadTimeoutSpec extends Specification { cleanup: client.close() - clientContext.close() + server.close() } @Requires(property = 'spec.name', value = 'ReadTimeoutSpec') diff --git a/http-client/src/test/groovy/io/micronaut/http/client/SslSelfSignedSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/SslSelfSignedSpec.groovy index a142ee33de3..7c87c1dc8eb 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/SslSelfSignedSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/SslSelfSignedSpec.groovy @@ -33,25 +33,23 @@ class SslSelfSignedSpec extends Specification { @Shared String host = Optional.ofNullable(System.getenv(Environment.HOSTNAME)).orElse(SocketUtils.LOCALHOST) - ApplicationContext context EmbeddedServer embeddedServer HttpClient client void setup() { - context = ApplicationContext.run([ + embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'SslSelfSignedSpec', 'micronaut.ssl.enabled': true, 'micronaut.server.ssl.buildSelfSigned': true, 'micronaut.server.ssl.port': -1, 'micronaut.http.client.ssl.insecure-trust-all-certificates': true, ]) - embeddedServer = context.getBean(EmbeddedServer).start() - client = context.createBean(HttpClient, embeddedServer.getURL()) + client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) } void cleanup() { client.close() - context.close() + embeddedServer.close() } void "expect the url to be https"() { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/SslStaticCertSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/SslStaticCertSpec.groovy index 2bb12fcd5bd..6f43ac39e0f 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/SslStaticCertSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/SslStaticCertSpec.groovy @@ -38,12 +38,11 @@ class SslStaticCertSpec extends Specification { @Shared String host = Optional.ofNullable(System.getenv(Environment.HOSTNAME)).orElse(SocketUtils.LOCALHOST) - ApplicationContext context EmbeddedServer embeddedServer HttpClient client void setup() { - context = ApplicationContext.run([ + embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'SslStaticCertSpec', 'micronaut.ssl.enabled': true, 'micronaut.ssl.keyStore.path': 'classpath:keystore.p12', @@ -61,13 +60,12 @@ class SslStaticCertSpec extends Specification { 'TLS_DHE_DSS_WITH_AES_256_GCM_SHA384'], 'micronaut.http.client.ssl.insecure-trust-all-certificates': true ]) - embeddedServer = context.getBean(EmbeddedServer).start() - client = context.createBean(HttpClient, embeddedServer.getURL()) + client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) } void cleanup() { client.close() - context.close() + embeddedServer.close() } void "expect the url to be https"() { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingCrudSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingCrudSpec.groovy index 8f6bce2b10b..c51c4dee0ef 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingCrudSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingCrudSpec.groovy @@ -44,13 +44,10 @@ class BlockingCrudSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run([ + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'BlockingCrudSpec', ]) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - void "test configured client"() { given: ApplicationContext anotherContext = ApplicationContext.run([ @@ -65,7 +62,7 @@ class BlockingCrudSpec extends Specification { void "test CRUD operations on generated client that returns blocking responses"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.get(99) @@ -130,7 +127,7 @@ class BlockingCrudSpec extends Specification { void "test DELETE operation with null values"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: client.delete(null) @@ -141,7 +138,7 @@ class BlockingCrudSpec extends Specification { void "test POST operation with null values"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.save(null) @@ -152,7 +149,7 @@ class BlockingCrudSpec extends Specification { void "test PUT operation with null values"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.update(5, null) @@ -163,7 +160,7 @@ class BlockingCrudSpec extends Specification { void "test GET operation with null values"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.get(null) @@ -174,7 +171,7 @@ class BlockingCrudSpec extends Specification { void "test a declarative client void method and 404 response"() { given: - VoidNotFoundClient client = context.getBean(VoidNotFoundClient) + VoidNotFoundClient client = embeddedServer.applicationContext.getBean(VoidNotFoundClient) when: client.call() @@ -186,7 +183,7 @@ class BlockingCrudSpec extends Specification { @Issue('https://github.com/micronaut-projects/micronaut-core/issues/2959') void "test annotation stereotype"() { given: - def client = context.getBean(StereotypeClient) + def client = embeddedServer.applicationContext.getBean(StereotypeClient) expect: client.list().size() == 0 diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingFallbackSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingFallbackSpec.groovy index 057f8e19a90..1829e4c9c3d 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingFallbackSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingFallbackSpec.groovy @@ -36,16 +36,13 @@ class BlockingFallbackSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run([ + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name':'BlockingFallbackSpec', ]) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - void "test that fallback is called when an exception happens invoking the server"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.get(99) diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingPojoCrudSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingPojoCrudSpec.groovy index 215c491e13e..fbbe90b843e 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingPojoCrudSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/BlockingPojoCrudSpec.groovy @@ -35,16 +35,13 @@ class BlockingPojoCrudSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run([ + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name':'BlockingPojoCrudSpec', ]) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - void "test CRUD operations on generated client that returns blocking responses"() { given: - BookClient client = context.getBean(BookClient) + BookClient client = embeddedServer.applicationContext.getBean(BookClient) when: Book book = client.get(99) diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/ClientFilterSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/ClientFilterSpec.groovy index 36965ed0588..e10b1d79570 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/ClientFilterSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/ClientFilterSpec.groovy @@ -38,6 +38,7 @@ import org.reactivestreams.Publisher import reactor.core.publisher.Flux import reactor.core.publisher.Mono import spock.lang.AutoCleanup +import spock.lang.Shared import spock.lang.Specification /** @@ -46,16 +47,15 @@ import spock.lang.Specification */ class ClientFilterSpec extends Specification{ + @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run([ + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'ClientFilterSpec', ]) - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - void "test client filter includes header"() { given: - MyApi myApi = context.getBean(MyApi) + MyApi myApi = embeddedServer.applicationContext.getBean(MyApi) expect: myApi.name() == 'Fred' @@ -63,7 +63,7 @@ class ClientFilterSpec extends Specification{ void "test method-based client filter includes header"() { given: - MyMethodApi myApi = context.getBean(MyMethodApi) + MyMethodApi myApi = embeddedServer.applicationContext.getBean(MyMethodApi) expect: myApi.name() == 'Fred' @@ -71,7 +71,7 @@ class ClientFilterSpec extends Specification{ void "test a client with no service ids doesn't match a filter with a service id"() { given: - HttpClient client = context.createBean(HttpClient, embeddedServer.getURL()) + HttpClient client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) when: HttpResponse response = client.toBlocking().exchange("/filters/name", String.class) @@ -103,7 +103,7 @@ class ClientFilterSpec extends Specification{ void "test a client filter that throws an exception"() { given: - HttpClient client = context.createBean(HttpClient, embeddedServer.getURL()) + HttpClient client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) when: HttpResponse response = client.toBlocking().exchange("/filter-exception/name", String.class) @@ -118,7 +118,7 @@ class ClientFilterSpec extends Specification{ void "test a client filter matching to the root"() { given: - RootApi rootApi = context.getBean(RootApi) + RootApi rootApi = embeddedServer.applicationContext.getBean(RootApi) expect: rootApi.name() == 'processed' @@ -304,8 +304,8 @@ class ClientFilterSpec extends Specification{ void "filter always observes a response"() { given: - ObservesResponseClient client = context.getBean(ObservesResponseClient) - ObservesResponseFilter filter = context.getBean(ObservesResponseFilter) + ObservesResponseClient client = embeddedServer.applicationContext.getBean(ObservesResponseClient) + ObservesResponseFilter filter = embeddedServer.applicationContext.getBean(ObservesResponseFilter) when: Mono.from(client.monoVoid()).block() == null diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/NullableCrudSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/NullableCrudSpec.groovy index ab32387bb92..ed240c23fba 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/NullableCrudSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/NullableCrudSpec.groovy @@ -16,6 +16,7 @@ package io.micronaut.http.client.aop import io.micronaut.context.ApplicationContext +import io.micronaut.context.annotation.Requires import io.micronaut.core.annotation.Nullable import io.micronaut.http.annotation.* import io.micronaut.http.client.annotation.Client @@ -30,14 +31,11 @@ class NullableCrudSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run() - - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, Collections.singletonMap("spec.name", "NullableCrudSpec")) void "test CRUD operations on generated client that returns blocking responses"() { given: - NullableBookClient client = context.getBean(NullableBookClient) + NullableBookClient client = embeddedServer.applicationContext.getBean(NullableBookClient) when: NullableBook book = client.get(99) @@ -80,7 +78,7 @@ class NullableCrudSpec extends Specification { void "test DELETE operation with null values"() { given: - NullableBookClient client = context.getBean(NullableBookClient) + NullableBookClient client = embeddedServer.applicationContext.getBean(NullableBookClient) when: client.delete(null) @@ -91,7 +89,7 @@ class NullableCrudSpec extends Specification { void "test POST operation with null values"() { given: - NullableBookClient client = context.getBean(NullableBookClient) + NullableBookClient client = embeddedServer.applicationContext.getBean(NullableBookClient) when: NullableBook book = client.save(null) @@ -103,7 +101,7 @@ class NullableCrudSpec extends Specification { void "test PUT operation with null values"() { given: - NullableBookClient client = context.getBean(NullableBookClient) + NullableBookClient client = embeddedServer.applicationContext.getBean(NullableBookClient) when: NullableBook saved = client.save("Temporary") @@ -116,7 +114,7 @@ class NullableCrudSpec extends Specification { void "test GET operation with null values"() { given: - NullableBookClient client = context.getBean(NullableBookClient) + NullableBookClient client = embeddedServer.applicationContext.getBean(NullableBookClient) when: NullableBook book = client.get(null) @@ -126,10 +124,12 @@ class NullableCrudSpec extends Specification { noExceptionThrown() } + @Requires(property = "spec.name", value = "NullableCrudSpec") @Client('/blocking/nullableBooks') static interface NullableBookClient extends NullableBookApi { } + @Requires(property = "spec.name", value = "NullableCrudSpec") @Controller("/blocking/nullableBooks") static class NullableBookController implements NullableBookApi { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/ParameterSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/ParameterSpec.groovy index 0a4fc9dbb31..94881fd39d5 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/ParameterSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/ParameterSpec.groovy @@ -16,6 +16,7 @@ package io.micronaut.http.client.aop import io.micronaut.context.ApplicationContext +import io.micronaut.context.annotation.Requires import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Get import io.micronaut.http.annotation.QueryValue @@ -32,14 +33,11 @@ import spock.lang.Specification class ParameterSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run() - - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, Collections.singletonMap("spec.name", "ParameterSpec")) void "test send and receive parameter"() { given: - UserClient userClient = context.getBean(UserClient) + UserClient userClient = embeddedServer.applicationContext.getBean(UserClient) User user = userClient.get("Fred") expect: @@ -55,11 +53,13 @@ class ParameterSpec extends Specification { } + @Requires(property = "spec.name", value = "ParameterSpec") @Client('/parameters') static interface UserClient extends MyApi { } + @Requires(property = "spec.name", value = "ParameterSpec") @Controller('/parameters') static class UserController implements MyApi { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/aop/PathVariableSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/aop/PathVariableSpec.groovy index 57988394ef8..17d42f7d74f 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/aop/PathVariableSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/aop/PathVariableSpec.groovy @@ -16,6 +16,7 @@ package io.micronaut.http.client.aop import io.micronaut.context.ApplicationContext +import io.micronaut.context.annotation.Requires import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Get import io.micronaut.http.annotation.PathVariable @@ -29,14 +30,11 @@ class PathVariableSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run() - - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, Collections.singletonMap("spec.name", "PathVariableSpec")) void "test send and receive with path variable"() { given: - UserClient userClient = context.getBean(UserClient) + UserClient userClient = embeddedServer.applicationContext.getBean(UserClient) User user = userClient.get("Fred") expect: @@ -52,11 +50,13 @@ class PathVariableSpec extends Specification { } + @Requires(property = "spec.name", value = "PathVariableSpec") @Client('/path-variables') static interface UserClient extends MyApi { } + @Requires(property = "spec.name", value = "PathVariableSpec") @Controller('/path-variables') static class UserController implements MyApi { diff --git a/http-client/src/test/groovy/io/micronaut/http/client/sse/ServerSentEventProxyingSpec.groovy b/http-client/src/test/groovy/io/micronaut/http/client/sse/ServerSentEventProxyingSpec.groovy index b7737fdae2e..e87d1764487 100644 --- a/http-client/src/test/groovy/io/micronaut/http/client/sse/ServerSentEventProxyingSpec.groovy +++ b/http-client/src/test/groovy/io/micronaut/http/client/sse/ServerSentEventProxyingSpec.groovy @@ -31,16 +31,13 @@ class ServerSentEventProxyingSpec extends Specification { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run( - 'spec.name': 'ServerSentEventProxyingSpec' + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, + ['spec.name': 'ServerSentEventProxyingSpec'] ) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - @Shared @AutoCleanup - SseClient sseClient = context.createBean(SseClient, embeddedServer.getURL()) + SseClient sseClient = embeddedServer.applicationContext.createBean(SseClient, embeddedServer.getURL()) void "test a request expecting a full response intercepted by a proxy providing a streaming response"() { given: diff --git a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/CompressionSpec.groovy b/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/CompressionSpec.groovy index 3377129edf0..3988309baa8 100644 --- a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/CompressionSpec.groovy +++ b/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/CompressionSpec.groovy @@ -38,14 +38,13 @@ class CompressionSpec extends Specification { def compression(ChannelHandler decompressor, CharSequence contentEncoding) { given: - def ctx = ApplicationContext.run(['spec.name': 'CompressionSpec'] + serverOptions()) - def server = ctx.getBean(EmbeddedServer).start() + EmbeddedServer server = ApplicationContext.run(EmbeddedServer, ['spec.name': 'CompressionSpec'] + serverOptions()) byte[] uncompressed = new byte[1024] ThreadLocalRandom.current().nextBytes(uncompressed) - ctx.getBean(Ctrl).data = uncompressed + server.applicationContext.getBean(Ctrl).data = uncompressed - def client = ctx.createBean(HttpClient, server.URI).toBlocking() + def client = server.applicationContext.createBean(HttpClient, server.URI).toBlocking() when: byte[] compressed = client.retrieve(HttpRequest.GET("/compress").header("Accept-Encoding", contentEncoding.toString()), byte[]) @@ -67,7 +66,6 @@ class CompressionSpec extends Specification { cleanup: client.close() server.stop() - ctx.close() where: contentEncoding | decompressor @@ -78,14 +76,13 @@ class CompressionSpec extends Specification { def compressionLevel(int threshold, int actual, boolean compressed) { given: - def ctx = ApplicationContext.run(['spec.name': 'CompressionSpec', 'micronaut.server.netty.compression-threshold': threshold] + serverOptions()) - def server = ctx.getBean(EmbeddedServer).start() + def server = ApplicationContext.run(EmbeddedServer, ['spec.name': 'CompressionSpec', 'micronaut.server.netty.compression-threshold': threshold] + serverOptions()) byte[] uncompressed = new byte[actual] ThreadLocalRandom.current().nextBytes(uncompressed) - ctx.getBean(Ctrl).data = uncompressed + server.applicationContext.getBean(Ctrl).data = uncompressed - def client = ctx.createBean(HttpClient, server.URI).toBlocking() + def client = server.applicationContext.createBean(HttpClient, server.URI).toBlocking() when: def response = client.exchange(HttpRequest.GET("/compress").header("Accept-Encoding", "gzip"), byte[]) @@ -97,7 +94,6 @@ class CompressionSpec extends Specification { cleanup: client.close() server.stop() - ctx.close() where: threshold | actual | compressed @@ -110,9 +106,8 @@ class CompressionSpec extends Specification { def decompression(ChannelHandler compressor, CharSequence contentEncoding) { given: - def ctx = ApplicationContext.run(['spec.name': 'CompressionSpec'] + serverOptions()) - def server = ctx.getBean(EmbeddedServer).start() - def client = ctx.createBean(HttpClient, server.URI).toBlocking() + EmbeddedServer server = ApplicationContext.run(EmbeddedServer, ['spec.name': 'CompressionSpec'] + serverOptions()) + def client = server.applicationContext.createBean(HttpClient, server.URI).toBlocking() def compChannel = new EmbeddedChannel(compressor) byte[] uncompressed = new byte[1024] @@ -132,12 +127,11 @@ class CompressionSpec extends Specification { when: client.exchange(HttpRequest.POST("/decompress", ByteBufUtil.getBytes(compressed)).header(HttpHeaderNames.CONTENT_ENCODING, contentEncoding)) then: - ctx.getBean(Ctrl).data == uncompressed + server.applicationContext.getBean(Ctrl).data == uncompressed cleanup: client.close() server.stop() - ctx.close() where: contentEncoding | compressor diff --git a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/Http2CompressionSpec.groovy b/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/Http2CompressionSpec.groovy index 529c1f26efb..782ea33d775 100644 --- a/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/Http2CompressionSpec.groovy +++ b/http-server-netty/src/test/groovy/io/micronaut/http/server/netty/Http2CompressionSpec.groovy @@ -3,13 +3,13 @@ package io.micronaut.http.server.netty class Http2CompressionSpec extends CompressionSpec { @Override protected Map serverOptions() { - return [ + [ 'micronaut.http.client.alpn-modes': 'h2', 'micronaut.http.client.ssl.insecure-trust-all-certificates': true, 'micronaut.server.http-version': '2.0', 'micronaut.server.ssl.enabled': true, 'micronaut.server.ssl.build-self-signed': true, - ] + ] as Map } } diff --git a/test-suite-geb/src/test/groovy/io/micronaut/upload/browser/UploadBrowserSpec.groovy b/test-suite-geb/src/test/groovy/io/micronaut/upload/browser/UploadBrowserSpec.groovy index f4615005ab8..70977856352 100644 --- a/test-suite-geb/src/test/groovy/io/micronaut/upload/browser/UploadBrowserSpec.groovy +++ b/test-suite-geb/src/test/groovy/io/micronaut/upload/browser/UploadBrowserSpec.groovy @@ -10,14 +10,11 @@ import spock.lang.Shared class UploadBrowserSpec extends GebSpec { @Shared @AutoCleanup - ApplicationContext context = ApplicationContext.run( + EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': UploadBrowserSpec.simpleName, ], Environment.TEST) - @Shared - EmbeddedServer embeddedServer = context.getBean(EmbeddedServer).start() - def "submitting a form without a file triggers an error"() { given: browser.baseUrl = "http://localhost:${embeddedServer.port}" diff --git a/test-suite-http-client-jdk-ssl/src/test/groovy/io/micronaut/http/client/jdk/SslStaticCertSpec.groovy b/test-suite-http-client-jdk-ssl/src/test/groovy/io/micronaut/http/client/jdk/SslStaticCertSpec.groovy index fffc7190c23..bfd9f6fbc65 100644 --- a/test-suite-http-client-jdk-ssl/src/test/groovy/io/micronaut/http/client/jdk/SslStaticCertSpec.groovy +++ b/test-suite-http-client-jdk-ssl/src/test/groovy/io/micronaut/http/client/jdk/SslStaticCertSpec.groovy @@ -19,12 +19,11 @@ class SslStaticCertSpec extends Specification { @Shared String host = Optional.ofNullable(System.getenv(Environment.HOSTNAME)).orElse(SocketUtils.LOCALHOST) - ApplicationContext context EmbeddedServer embeddedServer HttpClient client void setup() { - context = ApplicationContext.run([ + embeddedServer = ApplicationContext.run(EmbeddedServer, [ 'spec.name': 'SslStaticCertSpec', 'micronaut.ssl.enabled': true, 'micronaut.ssl.keyStore.path': 'classpath:keystore.p12', @@ -42,13 +41,12 @@ class SslStaticCertSpec extends Specification { 'TLS_DHE_DSS_WITH_AES_256_GCM_SHA384'], 'micronaut.http.client.ssl.insecure-trust-all-certificates': true ]) - embeddedServer = context.getBean(EmbeddedServer).start() - client = context.createBean(HttpClient, embeddedServer.getURL()) + client = embeddedServer.applicationContext.createBean(HttpClient, embeddedServer.getURL()) } void cleanup() { client.close() - context.close() + embeddedServer.close() } void "expect the url to be https"() {