Created
January 26, 2018 20:17
-
-
Save psamsotha/0fe34f91edad715d09f1e09dd579d625 to your computer and use it in GitHub Desktop.
Example of using JerseyTest without extending it.
This file contains hidden or 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
| import org.glassfish.jersey.server.ResourceConfig; | |
| import org.glassfish.jersey.test.JerseyTest; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Test; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.core.Application; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| public class CompositionTest { | |
| @Path("test") | |
| public static class TestResource { | |
| @GET | |
| public String get() { | |
| return "Hello World!"; | |
| } | |
| } | |
| private JerseyTest jerseyTest; | |
| @Before | |
| public void setUp() throws Exception { | |
| this.jerseyTest = new JerseyTest() { | |
| @Override | |
| protected Application configure() { | |
| return CompositionTest.this.configure(); | |
| } | |
| }; | |
| this.jerseyTest.setUp(); | |
| } | |
| @After | |
| public void tearDown() throws Exception { | |
| this.jerseyTest.tearDown(); | |
| } | |
| public ResourceConfig configure() { | |
| return new ResourceConfig(TestResource.class); | |
| } | |
| @Test | |
| public void doTest() { | |
| String response = this.jerseyTest.target("test") | |
| .request() | |
| .get(String.class); | |
| assertThat(response).isEqualTo("Hello World!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment