forked from dropwizard/dropwizard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dropwizard#544 from blacklocus/master
DropwizardAppRule should not require a configPath to operate.
- Loading branch information
Showing
2 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
...testing/src/test/java/io/dropwizard/testing/junit/DropwizardAppRuleWithoutConfigTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.dropwizard.testing.junit; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.sun.jersey.api.client.Client; | ||
import io.dropwizard.Application; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.Map; | ||
|
||
public class DropwizardAppRuleWithoutConfigTest { | ||
|
||
@ClassRule | ||
public static final DropwizardAppRule<Configuration> RULE = new DropwizardAppRule<>(TestApplication.class, null); | ||
|
||
Client client = new Client(); | ||
|
||
@Test | ||
public void runWithoutConfigFile() { | ||
Map response = client.resource("http://localhost:" + RULE.getLocalPort() + "/test").get(Map.class); | ||
Assert.assertEquals(ImmutableMap.of("color", "orange"), response); | ||
} | ||
|
||
static class TestApplication extends Application<Configuration> { | ||
@Override | ||
public void initialize(Bootstrap<Configuration> bootstrap) { | ||
} | ||
|
||
@Override | ||
public void run(Configuration configuration, Environment environment) throws Exception { | ||
environment.jersey().register(new TestResource()); | ||
} | ||
} | ||
|
||
@Path("test") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public static class TestResource { | ||
@GET | ||
public Response get() { | ||
return Response.ok(ImmutableMap.of("color", "orange")).build(); | ||
} | ||
} | ||
} |