Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce other things on the dsl that are missing from WireMockServer #29

Closed
edeandrea opened this issue Dec 6, 2023 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@edeandrea
Copy link
Contributor

edeandrea commented Dec 6, 2023

Proposal

Many things that I can do with WireMockServer are missing here, such as the ability to add a delay.

Now, I could do a PR to just add that feature to the dsl by adding it to the GrpcStubMappingBuilder or GrpcResponseDefinitionBuilder class, but that would seem to duplicate much of what is in the core ResponseDefinitionBuilder class.

There should be a way to expose this. Currently, if you look at https://github.com/wiremock/wiremock-grpc-extension/blob/main/src/main/java/org/wiremock/grpc/dsl/GrpcStubMappingBuilder.java#L64 you can see that responseBuilder.build is buried a few layers deep.

This needs to be exposed somewhere so that you can pass it's result into WireMockGrpcService.stubFor.

Ideally we should be able to do something like this:

mockGreetingService.stubFor(
        method("greeting")
            .willReturn(
                message(HelloResponse.newBuilder().setGreeting("Hi"))
                    .build()
                    .withFixedDelay(3_000)
                    .with...
        )
);

References

No response

@edeandrea edeandrea added the enhancement New feature or request label Dec 6, 2023
@edeandrea
Copy link
Contributor Author

edeandrea commented Dec 6, 2023

One solution I played around with was introducing functional callbacks. It would make this nice and easy, but the dsl would have a slight difference in usage from the core WireMock dsl.

Something like this in WireMockGrpcService (I have some other local changes in GrpcStubMappingBuilder to make this work):

  public StubMapping stubFor(GrpcStubMappingBuilder builder) {
    return stubFor(builder, r -> {});
  }

  public StubMapping stubFor(GrpcStubMappingBuilder builder, Consumer<ResponseDefinitionBuilder> builderConsumer) {
    final ResponseDefinitionBuilder responseDefinitionBuilder = builder.buildGrpcMappings();
    builderConsumer.accept(responseDefinitionBuilder);

    final StubMapping stubMapping = builder.build(serviceName, responseDefinitionBuilder);
    wireMock.register(stubMapping);
    return stubMapping;
  }

and then it would be used like this:

mockGreetingService.stubFor(
      method("greeting").willReturn(message(HelloResponse.newBuilder().setGreeting("Hi"))),
      builder -> builder.withFixedDelay(10_000)
    );

If you like/are ok with this approach I can certainly put together a PR

@edeandrea
Copy link
Contributor Author

Delays seem to have been implemented with #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant