@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user