Keeping it really easy
There is pretty good documentation for RestEasy and Undertow, but piecing together the Gradle dependencies for that combination eluded my for a while.
So very simply, this is it ... the Gradle dependencies, and a test (the test is translated to Spock from the example in the RestEasy docs)
build.gradle dependencies:
compile 'org.jboss.resteasy:resteasy-jaxrs:3.1.0.Final'
compile 'org.jboss.resteasy:resteasy-undertow:3.1.0.Final'
compile group: 'io.undertow', name: 'undertow-core', version: '1.4.8.Final'
compile group: 'io.undertow', name: 'undertow-servlet', version: '1.4.8.Final'
the test
class MyAppTest extends Specification {
@Path("/test")
public static class Resource
{
@GET
@Produces("text/plain")
public String get()
{
return "hello world";
}
}
@ApplicationPath("/base")
public static class MyApp extends Application
{
@Override
public Set<Class<?>> getClasses()
{
HashSet<Class<?>> classes = new HashSet<Class<?>>();
classes.add(Resource.class);
return classes;
}
}
static UndertowJaxrsServer server
Client client
def setupSpec() {
server = new UndertowJaxrsServer().start();
}
def setup() {
client = ClientBuilder.newClient();
}
def cleanup() {
client.close();
}
def cleanupSpec() {
server.stop();
}
def "testApplicationPath"() {
given:
server.deploy(MyApp.class);
when:
String val = client.target(TestPortProvider.generateURL("/base/test")).request().get(String.class);
then:
val == "hello world"
}
def "testApplicationContext"() {
given:
server.deploy(MyApp.class, "/root");
when:
String val = client.target(TestPortProvider.generateURL("/root/test"))
.request().get(String.class);
then:
val == "hello world"
}
def "testDeploymentInfo"() {
given:
DeploymentInfo di = server.undertowDeployment(MyApp.class);
di.setContextPath("/di");
di.setDeploymentName("DI");
server.deploy(di);
when:
String val = client.target(TestPortProvider.generateURL("/di/base/test"))
.request().get(String.class);
then:
val == "hello world"
}
}
No comments:
Post a Comment