Skip to content

Instantly share code, notes, and snippets.

@joschi
Created January 17, 2015 14:58

Revisions

  1. joschi created this gist Jan 17, 2015.
    60 changes: 60 additions & 0 deletions Issue832.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    package io.dropwizard.client;

    import io.dropwizard.Application;
    import io.dropwizard.Configuration;
    import io.dropwizard.setup.Environment;
    import io.dropwizard.testing.junit.DropwizardAppRule;
    import org.junit.Rule;
    import org.junit.Test;

    import javax.ws.rs.client.Client;

    import static org.junit.Assert.fail;

    public class Issue832 {
    @Rule
    public final DropwizardAppRule<TestConfiguration> RULE = new DropwizardAppRule<TestConfiguration>(TestApplication.class, null);

    @Test
    public void testSingleClient() {
    Client c = buildClient(RULE, "test-client");
    c.close();
    }

    @Test
    public void testMultipleClientsWithDistinctNames() {
    Client c1 = buildClient(RULE, "test-client");
    Client c2 = buildClient(RULE, "test-client2");
    c1.close();
    c2.close();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testMultipleClientsWithSameName() {
    // This should fail because names need to be distinct
    buildClient(RULE, "test-client");
    buildClient(RULE, "test-client");
    fail();
    }

    public static Client buildClient(DropwizardAppRule<TestConfiguration> appRule, String name) {
    return new JerseyClientBuilder(appRule.getEnvironment())
    .using(appRule.getConfiguration().getJerseyClientConfiguration())
    .build(name);
    }

    public static class TestConfiguration extends Configuration {
    private JerseyClientConfiguration jerseyClientConfiguration = new JerseyClientConfiguration();

    public JerseyClientConfiguration getJerseyClientConfiguration() {
    return jerseyClientConfiguration;
    }
    }

    public static class TestApplication extends Application<TestConfiguration> {
    @Override
    public void run(TestConfiguration configuration, Environment environment) throws Exception {

    }
    }
    }