问题描述
尝试使用 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 (将#修改为@)