Large test case broken down into components
@@ -5,6 +5,7 @@ import org.junit.Test;
import ratpack.exec.Promise;
import ratpack.func.Action;
import ratpack.handling.Chain;
+import ratpack.handling.Handler;
import ratpack.registry.Registry;
import ratpack.test.embed.EmbeddedApp;
import ratpack.test.exec.ExecHarness;
@@ -15,22 +16,28 @@ public class AppHttpUnitTest {
@Test
public void givenAnyUri_GetEmployeeFromSameRegistry() throws Exception {
- final Action<Chain> chainAction = chain -> chain.prefix("employee/:id", empChain -> empChain.all(ctx -> {
+ Handler allHandler = ctx -> {
Long id = Long.valueOf(ctx.getPathTokens()
.get("id"));
Employee employee = new Employee(id, "Mr", "NY");
ctx.next(Registry.single(Employee.class, employee));
- })
- .get("name", ctx -> {
+ };
+ Handler empNameHandler = ctx -> {
Employee employee = ctx.get(Employee.class);
ctx.getResponse()
.send("Name of employee with ID " + employee.getId() + " is " + employee.getName());
- })
- .get("title", ctx -> {
+ };
+ Handler empTitleHandler = ctx -> {
Employee employee = ctx.get(Employee.class);
ctx.getResponse()
.send("Title of employee with ID " + employee.getId() + " is " + employee.getTitle());
- }));
+ };
+
+ Action<Chain> chainAction = chain -> chain.prefix("employee/:id", empChain -> {
+ empChain.all(allHandler)
+ .get("name", empNameHandler)
+ .get("title", empTitleHandler);
+ });
EmbeddedApp.fromHandlers(chainAction)
.test(testHttpClient -> {
assertEquals("Name of employee with ID 1 is NY", testHttpClient.get("employee/1/name")
