Skip to content

Instantly share code, notes, and snippets.

@psamsotha
Created January 26, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psamsotha/0fe34f91edad715d09f1e09dd579d625 to your computer and use it in GitHub Desktop.
Save psamsotha/0fe34f91edad715d09f1e09dd579d625 to your computer and use it in GitHub Desktop.
Example of using JerseyTest without extending it.
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