質問

I'm aware that 'embedded' is an overloaded term, especially with regard to web components in the Java world. I'm using it to mean "done entirely in a Java class with no xml configuration". An example of this is below.

My question is - is there a proven way to do embedded web testing of JSF-2.0 components? I mean starting up a server with opening a port (that a selenium test could theoretically connect to). I'm not interested in the Selenium startup.

All I want is to be able to point to an existing JSF-2.0 page, an existing backing bean, and have it served up on a given port.

The closest to this appears to be this page in Jetty: http://musingsofaprogrammingaddict.blogspot.com.au/2009/12/running-jsf-2-on-embedded-jetty.html

I'm hoping there is another example in Tomcat or Glassfish or another library that explains this better.

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;

public class HelloHandler extends AbstractHandler
{
    public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
    throws IOException, ServletException
    {
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        baseRequest.setHandled(true);
        response.getWriter().println("<h1>Hello World</h1>");
    }

    public static void main(String[] args) throws Exception
    {
        Server server = new Server(8080);
        server.setHandler(new HelloHandler());

        server.start();
        server.join();
    }
}
役に立ちましたか?

解決

Looks like the best way to embedded (where embedded means like embedded Tomcat) is to use Arquillian. https://community.jboss.org/wiki/ArquillianIntegrationIdeas?_sscc=t

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top