admin管理员组文章数量:1289900
I am trying to test a spring boot application using dapr. For my test set up I want to start a Dapr testcontainer and have a Conmponent that references a Wiremock testcontainer to stub http calls.
class TestcontainersConfiguration {
private static final Network network = Network.newNetwork();
@Bean
@ServiceConnection
public DaprContainer daprContainer(WireMockContainer wireMockContainer) {
// Get the network alias instead of the base URL
String wireServiceUrl = "http://" + wireMockContainer.getNetworkAliases().getFirst() + ":" + wireMockContainer.getPort();
DaprContainer dapr = new DaprContainer("daprio/daprd:latest")
.withAppName("local-dapr-app")
.withNetwork(network)
.withComponent(new Component("warehouse", "http", "v1", Collections.singletonList(new MetadataEntry("url", wireServiceUrl))))
.withAppPort(8080)
.withAppChannelAddress("host.testcontainers.internal");
return dapr;
}
@Bean
WireMockContainer wireMockContainer() {
WireMockContainer wireMockContainer = new WireMockContainer("wiremock/wiremock:3.12.0-1")
.withMappingFromResource("warehouse-service-stubs.json")
.withNetwork(network);
wireMockContainer.start();
return wireMockContainer;
}
@Bean
public DynamicPropertyRegistrar wireMockProperties(WireMockContainer wireMockContainer, DaprContainer dapr) {
return registry -> {
registry.add("DAPR_HTTP_ENDPOINT", wireMockContainer::getBaseUrl);
registry.add("dapr.grpc.port", () -> dapr.getMappedPort(50001));
registry.add("dapr.http.port", () -> dapr.getMappedPort(3500));
};
}
}
If I start the set up with the .withComponent line, the health check of the dapr container fails. If i remove it, the application fails because there is no component with the id "warehouse". Is there a working set up to stub http calls in tests with dapr?
I am trying to test a spring boot application using dapr. For my test set up I want to start a Dapr testcontainer and have a Conmponent that references a Wiremock testcontainer to stub http calls.
class TestcontainersConfiguration {
private static final Network network = Network.newNetwork();
@Bean
@ServiceConnection
public DaprContainer daprContainer(WireMockContainer wireMockContainer) {
// Get the network alias instead of the base URL
String wireServiceUrl = "http://" + wireMockContainer.getNetworkAliases().getFirst() + ":" + wireMockContainer.getPort();
DaprContainer dapr = new DaprContainer("daprio/daprd:latest")
.withAppName("local-dapr-app")
.withNetwork(network)
.withComponent(new Component("warehouse", "http", "v1", Collections.singletonList(new MetadataEntry("url", wireServiceUrl))))
.withAppPort(8080)
.withAppChannelAddress("host.testcontainers.internal");
return dapr;
}
@Bean
WireMockContainer wireMockContainer() {
WireMockContainer wireMockContainer = new WireMockContainer("wiremock/wiremock:3.12.0-1")
.withMappingFromResource("warehouse-service-stubs.json")
.withNetwork(network);
wireMockContainer.start();
return wireMockContainer;
}
@Bean
public DynamicPropertyRegistrar wireMockProperties(WireMockContainer wireMockContainer, DaprContainer dapr) {
return registry -> {
registry.add("DAPR_HTTP_ENDPOINT", wireMockContainer::getBaseUrl);
registry.add("dapr.grpc.port", () -> dapr.getMappedPort(50001));
registry.add("dapr.http.port", () -> dapr.getMappedPort(3500));
};
}
}
If I start the set up with the .withComponent line, the health check of the dapr container fails. If i remove it, the application fails because there is no component with the id "warehouse". Is there a working set up to stub http calls in tests with dapr?
Share Improve this question edited Feb 20 at 12:59 JP13 asked Feb 20 at 12:42 JP13JP13 701 silver badge9 bronze badges 1- If I start the set up with the .withComponent line, the health check of the dapr container fails. ... It fails how? What is the error? What is the URL for the wiremock container. – M. Deinum Commented Feb 20 at 14:23
1 Answer
Reset to default 1thanks for asking this question, this helps us to refine the Dapr and Spring Boot integration. Is there any way you can share your code in GitHub for me to take a look at it? I think we can definitely add a test upstream to demonstrate how to configure this scenario, but we need to look at the code a little bit closer (errors, and how you are calling the service).
Please create an issue in the https://github/dapr/java-sdk/ repository so we can keep track of this.
If you have time, you can also check this PR, which we are working with the folks from https://microcks.io to cover more complex testing scenarios: https://github/salaboy/pizza/pull/13/files
本文标签:
版权声明:本文标题:java - Is there a way to add a Component referencing a WireMockContainer to a Dapr testcontainer? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741434666a2378564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论