Created
May 3, 2018 00:06
-
-
Save psamsotha/13fe79f0e572bbbec6ca486e4501fe5a to your computer and use it in GitHub Desktop.
Example of complete JerseyTest
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
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