如何解决Micronaut 使用声明式 HTTP 客户端 Junit 5 进行测试
尝试使用 Micronaut 声明式 HTTP 客户端进行 Junit 5 E2E 功能测试。
public interface IProductOperation {
@Get(value = "/search/{text}")
@Secured(SecurityRule.IS_ANONYMOUS)
Maybe<?> freeTextSearch(@NotBlank String text);
}
声明式 micronaut HTTP 客户端
@Client(
id = "feteBirdProduct",path = "/product"
)
public interface IProductClient extends IProductOperation {
}
JUnit - 5 测试
@MicronautTest
public record ProductControllerTest(IProductClient iProductClient) {
@Test
@DisplayName("Should search the item based on the name")
void shouldSearchTheItemBasedOnTheName() {
var value = iProductClient.freeTextSearch("test").blockingGet();
System.out.println(value);
}
}
控制器
@Controller("/product")
public class ProductController implements IProductOperation {
private final IProductManager iProductManager;
public ProductController(IProductManager iProductManager) {
this.iProductManager = iProductManager;
}
@Override
public Maybe<List> freeTextSearch(String text) {
LOG.info("Controller --> Finding all the products");
return iProductManager.findFreeText(text);
}
}
当我运行测试时,我收到 500 Internet 服务器错误。我想当我运行测试时,应用程序也在运行。不知道 500 内部服务器错误的原因是什么。
任何帮助将不胜感激
是 @Get(value = "/search/{text}")
导致了问题吗?。如果是,我该如何解决声明式客户端
服务发现
application.yml
consul:
client:
defaultZone: ${CONSUL_HOST:localhost}:${CONSUL_PORT:8500}
registration:
enabled: true
application-test.yml
micronaut:
server:
port: -1
http:
services:
feteBirdProduct:
urls:
- http://product
consul:
client:
registration:
enabled: false
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。