Created
January 17, 2015 14:58
-
-
Save joschi/eb12da2baae6c032a1a4 to your computer and use it in GitHub Desktop.
Dropwizard #832
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment