package com.wizzardo.servlet.war;

import com.wizzardo.servlet.WarBuilder;
import com.wizzardo.servlet.WarTest;
import org.junit.Test;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by wizzardo on 25.01.15.
 */
public class TestServletMapping extends WarTest {
    @Override
    protected void customizeWar(WarBuilder builder) {
        builder.addClass(SimpleServlet.class);
        builder.addClass(EndsWithServlet.class);
        builder.getWebXmlBuilder()
                .append(new WarBuilder.ServletMapping(SimpleServlet.class).url("/simple/*"))
                .append(new WarBuilder.ServletMapping(EndsWithServlet.class).url("*.foo"))
        ;
    }


    @Test
    public void test() throws IOException {
        servletPath = "";
        test(request -> request.get().asString(), "/simple");
        test(request -> request.get().asString(), "/simple.foo");
        test(request -> request.get().asString(), "/bar.foo");
    }

    public static class SimpleServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.getWriter().write(getClass().getSimpleName());
        }
    }

    public static class EndsWithServlet extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.getWriter().write(getClass().getSimpleName());
        }
    }
}

@@ -101,24 +101,49 @@
 et.WarTest;%0A
+import org.junit.Assert;%0A
 import org.j
@@ -736,24 +736,209 @@
 simple/*%22))%0A
+                .append(new WarBuilder.ServletMapping(StaticServlet.class).url(%22/simple%22))%0A                .append(new WarBuilder.ServletMapping(BarServlet.class).url(%22/simple/bar/*%22))%0A
             
@@ -1118,66 +1118,748 @@
 %22%22;%0A
-        test(request -%3E request.get().asString(), %22/simple
+%0A        Assert.assertEquals(%22StaticServlet%22, myRequest(contextPath + %22/simple%22).get().asString());%0A        Assert.assertEquals(%22SimpleServlet%22, myRequest(contextPath + %22/simple/foo%22).get().asString());%0A        Assert.assertEquals(%22BarServlet%22, myRequest(contextPath + %22/simple/bar%22).get().asString());%0A        Assert.assertEquals(%22EndsWithServlet%22, myRequest(contextPath + %22/simple.foo%22).get().asString());%0A        Assert.assertEquals(%22SimpleServlet%22, myRequest(contextPath + %22/simple/1.foo%22).get().asString());%0A        Assert.assertEquals(%22EndsWithServlet%22, myRequest(contextPath + %22/bar.foo%22).get().asString());%0A%0A        test(request -%3E request.get().asString(), %22/simple%22);%0A        test(request -%3E request.get().asString(), %22/simple/bar
 %22);%0A
@@ -2311,36 +2311,38 @@
 Servlet extends 
-Http
+Simple
 Servlet %7B%0A      
@@ -2343,213 +2343,138 @@
     
+%7D%0A%0A
     
-@Override%0A        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+public static class BarServlet extends SimpleServlet
  %7B%0A    
-   
+%7D%0A%0A
     
- resp.getWriter().write(getClass().getSimpleName());%0A        %7D
+public static class StaticServlet extends SimpleServlet %7B
 %0A   

improve test