Reputation: 70
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?
Upvotes: 1
Views: 46
Reputation: 4143
thanks 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.com/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.com/salaboy/pizza/pull/13/files
Upvotes: 1