Search in sources :

Example 1 with EmbeddedJetty

use of com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty in project shiro by apache.

the class AbstractContainerIT method startContainer.

@BeforeClass
public static void startContainer() throws Exception {
    EmbeddedJettyConfiguration config = EmbeddedJettyConfiguration.builder().withWebapp(getWarDir()).build();
    jetty = new EmbeddedJetty(config) {

        /**
         * Overriding with contents of this pull request, to make fragment scanning work.
         * https://github.com/mjeanroy/junit-servers/pull/3
         */
        protected WebAppContext createdWebAppContext() throws Exception {
            final String path = configuration.getPath();
            final String webapp = configuration.getWebapp();
            final String classpath = configuration.getClasspath();
            WebAppContext ctx = new WebAppContext();
            ctx.setClassLoader(Thread.currentThread().getContextClassLoader());
            ctx.setContextPath(path);
            // Useful for WebXmlConfiguration
            ctx.setBaseResource(newResource(webapp));
            ctx.setConfigurations(new Configuration[] { new WebInfConfiguration(), new WebXmlConfiguration(), new AnnotationConfiguration(), new JettyWebXmlConfiguration(), new MetaInfConfiguration(), new FragmentConfiguration() });
            if (isNotBlank(classpath)) {
                // Fix to scan Spring WebApplicationInitializer
                // This will add compiled classes to jetty classpath
                // See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
                // And more precisely: http://stackoverflow.com/a/18449506/1215828
                File classes = new File(classpath);
                FileResource containerResources = new FileResource(classes.toURI());
                ctx.getMetaData().addContainerResource(containerResources);
            }
            Server server = getDelegate();
            ctx.setParentLoaderPriority(true);
            ctx.setWar(webapp);
            ctx.setServer(server);
            // Add server context
            server.setHandler(ctx);
            return ctx;
        }
    };
    jetty.start();
    assertTrue(jetty.isStarted());
}
Also used : JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) FragmentConfiguration(org.eclipse.jetty.webapp.FragmentConfiguration) JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) WebXmlConfiguration(org.eclipse.jetty.webapp.WebXmlConfiguration) Configuration(org.eclipse.jetty.webapp.Configuration) AnnotationConfiguration(org.eclipse.jetty.annotations.AnnotationConfiguration) WebInfConfiguration(org.eclipse.jetty.webapp.WebInfConfiguration) MetaInfConfiguration(org.eclipse.jetty.webapp.MetaInfConfiguration) EmbeddedJettyConfiguration(com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration) WebInfConfiguration(org.eclipse.jetty.webapp.WebInfConfiguration) Server(org.eclipse.jetty.server.Server) FileResource(org.eclipse.jetty.util.resource.FileResource) EmbeddedJettyConfiguration(com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JettyWebXmlConfiguration(org.eclipse.jetty.webapp.JettyWebXmlConfiguration) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) EmbeddedJetty(com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty) MetaInfConfiguration(org.eclipse.jetty.webapp.MetaInfConfiguration) FragmentConfiguration(org.eclipse.jetty.webapp.FragmentConfiguration) AnnotationConfiguration(org.eclipse.jetty.annotations.AnnotationConfiguration) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Aggregations

EmbeddedJetty (com.github.mjeanroy.junit.servers.jetty.EmbeddedJetty)1 EmbeddedJettyConfiguration (com.github.mjeanroy.junit.servers.jetty.EmbeddedJettyConfiguration)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AnnotationConfiguration (org.eclipse.jetty.annotations.AnnotationConfiguration)1 Server (org.eclipse.jetty.server.Server)1 FileResource (org.eclipse.jetty.util.resource.FileResource)1 Configuration (org.eclipse.jetty.webapp.Configuration)1 FragmentConfiguration (org.eclipse.jetty.webapp.FragmentConfiguration)1 JettyWebXmlConfiguration (org.eclipse.jetty.webapp.JettyWebXmlConfiguration)1 MetaInfConfiguration (org.eclipse.jetty.webapp.MetaInfConfiguration)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 WebInfConfiguration (org.eclipse.jetty.webapp.WebInfConfiguration)1 WebXmlConfiguration (org.eclipse.jetty.webapp.WebXmlConfiguration)1 BeforeClass (org.junit.BeforeClass)1