I am using DropWizardAppRule to spin up my application and would like to 
stub the external dependencies using DropWizardClientRule.
My problem is that the port/baseUri of the stubbed endpoint is not known 
until I actually have started the web server. This makes it hard to 
conveniently combine these JUnit rules in an integration test.

I would like to do something similar to this:

(I think it would be neat to explicitly set the port, but it would be 
equally viable to retrieve a randomly generated port from the Rule. 
But that assumes the port is set at Rule instance creation, rather than 
when the Rule starts (i.e when before() is invoked).

public class AppTest {

    @Path("dummy")
    public static class StubbedResource {
        @POST
        @Consumes(TEXT_PLAIN)
        @Produces(TEXT_PLAIN)
        public String stub(String request) {
            return "some stubbed response";
        }
    }

    private static final DropWizardClientRule STUB = new 
DropWizardClientRule(9876, new StubbedResource());
    private static final DropwizardAppRule<AppConfig> APP = new 
DropwizardAppRule<>(
            App.class,
            resourceFilePath("config.yml"),
            ConfigOverride.config("externalDependencyUrl", 
"http://localhost:9876/dummy";)); // Override with actual stub port

    @ClassRule
    public static final TestRule RULE = 
RuleChain.outerRule(EXTERNAL).around(APP);

    private final Client client = ClientBuilder.newClient();

    @Test
    public void shouldInvokeService() throws IOException {
        final Response response = 
client.target(invoke(APP.getLocalPort())).request().post(text("Simon"));
        assertThat(response, hasStatus(OK));

    }

}


I am missing something? Or shouldn't this use case be possible using the 
DropWizardAppRule and DropWizardClientRule?


Cheers,

/Patrik


-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to