Adding ratpack module (#1374)

* adding ratpack module

* adding pom.xml
This commit is contained in:
Abhinab Kanrar
2017-03-12 15:19:13 +05:30
committed by maibin
parent dda35bc510
commit 2f3f490453
4 changed files with 121 additions and 0 deletions
@@ -0,0 +1,22 @@
package com.baeldung;
import ratpack.http.MutableHeaders;
import ratpack.server.RatpackServer;
public class Application {
public static void main(String... args) throws Exception {
RatpackServer.start(server -> server.handlers(chain -> chain.all(ctx -> {
MutableHeaders headers = ctx.getResponse().getHeaders();
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Accept-Language", "en-us");
headers.set("Accept-Charset", "UTF-8");
ctx.next();
})
.get(ctx -> ctx.render("Welcome to baeldung ratpack!!!"))
.get(":name", ctx -> ctx.render("Hello " + ctx.getPathTokens().get("name") + "!!!"))
.post(":amount", ctx -> ctx.render(" Amount $" + ctx.getPathTokens().get("amount") + " added successfully !!!"))
));
}
}
@@ -0,0 +1,31 @@
package com.baeldung;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import ratpack.test.MainClassApplicationUnderTest;
import static org.junit.Assert.assertEquals;
@RunWith(JUnit4.class)
public class ApplicationTest {
MainClassApplicationUnderTest appUnderTest = new MainClassApplicationUnderTest(Application.class);
@Test
public void givenDefaultUrl_getStaticText() {
assertEquals("Welcome to baeldung ratpack!!!", appUnderTest.getHttpClient().getText("/"));
}
@Test
public void givenDynamicUrl_getDynamicText() {
assertEquals("Hello dummybot!!!", appUnderTest.getHttpClient().getText("/dummybot"));
}
@After
public void shutdown() {
appUnderTest.close();
}
}