是否可以在 grails 4 功能 API 测试中使用 Micronaut 声明式 HTTP 客户端?
Is it possible to use Micronaut Declarative HTTP client in grails 4 functional API tests?
我正在尝试创建一个声明式客户端来测试 API 我正在用 grails 4 编写,就像您可以在 micronaut 中那样。
据我所知,如果您在编译时知道基数 URL,则可以创建声明式客户端。因为 grails 功能(集成)测试在随机端口上创建服务器,所以您无法事先知道该端口并使用 @Client('http://localhost:8080') 注释。
使用 @Client('http://localhost:${local.server.port}') 之类的东西失败,grails 抱怨无法查找配置 属性。
有什么我遗漏的吗?
Is it possible to use Micronnaut Declarative HTTP client in grails 4
functional API tests?
是。
这样做的一个问题是,当使用 @Client('/')
连接到本地 运行 服务器时,需要在上下文中配置一个 EmbeddedServer
bean 来回答问题应用 运行 在哪个端口上。一些相关代码位于 https://github.com/micronaut-projects/micronaut-core/blob/458bbf07221407abe7e283815fb62b7b4d1fc224/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java#L93.
我们将添加测试支持以简化此操作,但您可以通过自己注册 bean 来使其工作。请参阅以下内容:
src/integration-test/groovy/com/objectcomputing/example/TestEmbeddedServer.groovy
src/integration-test/groovy/com/objectcomputing/example/BookClient.groovy
src/integration-test/groovy/com/objectcomputing/example/EmbeddedServerTest.groovy
src/integration-test/groovy/com/objectcomputing/example/BookFunctionalSpec.groovy
目前这是一个问题,但我相信在测试框架中发布适当的支持之前它会起作用。
我正在尝试创建一个声明式客户端来测试 API 我正在用 grails 4 编写,就像您可以在 micronaut 中那样。
据我所知,如果您在编译时知道基数 URL,则可以创建声明式客户端。因为 grails 功能(集成)测试在随机端口上创建服务器,所以您无法事先知道该端口并使用 @Client('http://localhost:8080') 注释。
使用 @Client('http://localhost:${local.server.port}') 之类的东西失败,grails 抱怨无法查找配置 属性。
有什么我遗漏的吗?
Is it possible to use Micronnaut Declarative HTTP client in grails 4 functional API tests?
是。
这样做的一个问题是,当使用 @Client('/')
连接到本地 运行 服务器时,需要在上下文中配置一个 EmbeddedServer
bean 来回答问题应用 运行 在哪个端口上。一些相关代码位于 https://github.com/micronaut-projects/micronaut-core/blob/458bbf07221407abe7e283815fb62b7b4d1fc224/http-client-core/src/main/java/io/micronaut/http/client/DefaultLoadBalancerResolver.java#L93.
我们将添加测试支持以简化此操作,但您可以通过自己注册 bean 来使其工作。请参阅以下内容:
src/integration-test/groovy/com/objectcomputing/example/TestEmbeddedServer.groovy
src/integration-test/groovy/com/objectcomputing/example/BookClient.groovy
src/integration-test/groovy/com/objectcomputing/example/EmbeddedServerTest.groovy
src/integration-test/groovy/com/objectcomputing/example/BookFunctionalSpec.groovy
目前这是一个问题,但我相信在测试框架中发布适当的支持之前它会起作用。