package com.jetdrone.vertx.yoke.test.middleware;

import com.jetdrone.vertx.yoke.annotations.GET;
import com.jetdrone.vertx.yoke.annotations.Path;
import com.jetdrone.vertx.yoke.annotations.Produces;
import com.jetdrone.vertx.yoke.middleware.YokeRequest;
import com.jetdrone.vertx.yoke.test.Response;
import com.jetdrone.vertx.yoke.test.YokeTester;
import org.junit.Test;
import org.vertx.java.core.Handler;
import org.vertx.testtools.TestVerticle;

import static org.vertx.testtools.VertxAssert.assertEquals;
import static org.vertx.testtools.VertxAssert.testComplete;

public class Router extends TestVerticle {

    @Path("/ws")
    public static class TestRouter {
        @GET
        public void get(YokeRequest request) {
            request.response().end("Hello ws!");
        }
    }

    @Test
    public void testAnnotatedRouter() {
        YokeTester yoke = new YokeTester(this);
        yoke.use(com.jetdrone.vertx.yoke.middleware.Router.from(new TestRouter()));

        yoke.request("GET", "/ws", new Handler<Response>() {
            @Override
            public void handle(Response resp) {
                assertEquals(200, resp.getStatusCode());
                assertEquals("Hello ws!", resp.body.toString());
                testComplete();
            }
        });
    }

    @Path("/ws")
    public static class TestRouter2 {
        @GET
        @Produces({"text/plain"})
        public void get(YokeRequest request) {
            request.response().end("Hello ws!");
        }
    }

    @Test
    public void testAnnotatedRouter2() {
        YokeTester yoke = new YokeTester(this);
        yoke.use(com.jetdrone.vertx.yoke.middleware.Router.from(new TestRouter2()));

        yoke.request("GET", "/ws", new Handler<Response>() {
            @Override
            public void handle(Response resp) {
                assertEquals(200, resp.getStatusCode());
                assertEquals("Hello ws!", resp.body.toString());
                testComplete();
            }
        });
    }
}

@@ -39,24 +39,67 @@
 iddleware;%0A%0A
+import com.jetdrone.vertx.yoke.Middleware;%0A
 import com.j
@@ -2048,11 +2048,1040 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testRouterWithParams() %7B%0A        YokeTester yoke = new YokeTester(this);%0A        yoke.use(new com.jetdrone.vertx.yoke.middleware.Router() %7B%7B%0A            get(%22/api/:id%22, new Middleware() %7B%0A                @Override%0A                public void handle(YokeRequest request, Handler%3CObject%3E next) %7B%0A                    request.response().end(%22OK%22);%0A                %7D%0A            %7D);%0A            param(%22id%22, new Middleware() %7B%0A                @Override%0A                public void handle(YokeRequest request, Handler%3CObject%3E next) %7B%0A                    System.err.println(request.params().get(%22id%22));%0A                    next.handle(null);%0A                %7D%0A            %7D);%0A        %7D%7D);%0A%0A        yoke.request(%22GET%22, %22/api/1%22, new Handler%3CResponse%3E() %7B%0A            @Override%0A            public void handle(Response resp) %7B%0A                assertEquals(200, resp.getStatusCode());%0A                assertEquals(%22Hello ws!%22, resp.body.toString());%0A                testComplete();%0A            %7D%0A        %7D);%0A    %7D
 %0A%7D%0A

create test that breaks everything!