/***************************************************************************** * Copyright 2011 Zdenko Vrabel * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *****************************************************************************/ package org.zdevra.guice.mvc.case2; import java.io.IOException; import javax.servlet.Servlet; import javax.servlet.ServletException; import org.testng.Assert; import org.testng.annotations.Test; import org.zdevra.guice.mvc.AbstractTest; import org.zdevra.guice.mvc.TestServlet; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; import com.meterware.servletunit.InvocationContext; import com.meterware.servletunit.ServletUnitClient; /** * This case tests the abstraction of controllers. In guice we may have split up * a contoller's interface which defines a mapping and controller's * implementation. */ @Test public class Case2Test extends AbstractTest { public static class Case2Servlet extends TestServlet { public Case2Servlet() { super(Case2Controller.class, new Case2Module()); } } public Case2Test() { super(Case2Servlet.class); } @Test public void testSimple() throws IOException, ServletException { //prepare request ServletUnitClient sc = sr.newClient(); WebRequest request = new GetMethodWebRequest("http://www.car.com/test/getcar/1999"); InvocationContext ic = sc.newInvocation(request); //invoke request Servlet ss = ic.getServlet(); ss.service(ic.getRequest(), ic.getResponse()); WebResponse response = ic.getServletResponse(); //process response String out = response.getText(); Assert.assertTrue(out.contains("ford-1999")); } }