When we started developing GitHub - arquillian/arquillian-container-se we aimed for simple basic Java SE testing with clearly defined and also separated classpath. Recently we realized that it should be possible to start some embedded web container instance within the separated Java process and take advantage of Arquillian mixed mode (see Test run modes - Arquillian - Project Documentation Editor) and thus basically enable testing at embedded web container of your preference.

 

You need to provide your own implementation of abstract class LaunchService arquillian-container-se/LaunchServices.java at master · arquillian/arquillian-container-se · GitHub to start e.g embedded web container. In this class you can simply override initialize() and shutdown() methods where you can handle start:

 

  @Override
    public void initialize() {
        String webappDirLocation = ".";
        tomcat = new Tomcat();
        tomcat.setPort(8080);


        StandardContext ctx = null;
        ctx = (StandardContext) tomcat.addContext("", new File(webappDirLocation).getAbsolutePath());
        Tomcat.addServlet(ctx, TestServlet.class.getSimpleName(), new TestServlet());
        ctx.addServletMapping("/test", TestServlet.class.getSimpleName());


        try {
            tomcat.start();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
        Executors.newSingleThreadExecutor().submit(new Runnable() {
            @Override
            public void run() {
                tomcat.getServer().await();
            }
        });
    }

 

and shutdown of the web container:

 

    @Override
    public void shutdown(){
        try {
            tomcat.stop();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
    }

 

Complete test example is available at arquillian-container-se/container-se-tests/src/test/java/org/jboss/arquillian/container/se/test/client at master · arqui… .