Skip to content

Instantly share code, notes, and snippets.

@psamsotha
Created May 3, 2018 00:06
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/13fe79f0e572bbbec6ca486e4501fe5a to your computer and use it in GitHub Desktop.
Save psamsotha/13fe79f0e572bbbec6ca486e4501fe5a to your computer and use it in GitHub Desktop.
Example of complete JerseyTest
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import static org.assertj.core.api.Assertions.assertThat;
public class CompleteTestExample extends JerseyTest {
public static class Model {
private String name;
public Model() {}
public Model(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
@Path("test")
public static class TestResource {
@GET
@Produces("application/json")
public Model getModel() {
return new Model("Hello World");
}
}
@Override
public ResourceConfig configure() {
return new ResourceConfig()
.register(TestResource.class);
}
@Test
public void doIt() {
Response res = target("test")
.request().get();
Model model = res.readEntity(Model.class);
assertThat(model.getName()).isEqualTo("Hello World");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment