Search in sources :

Example 6 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method embeddedJarWithoutAppResources2.

@Test
public void embeddedJarWithoutAppResources2() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar");
    JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
    jarWarResourceSet.init();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(dirResourceSet, jarWarResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(2);
}
Also used : JarWarResourceSet(org.apache.catalina.webresources.JarWarResourceSet) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) Test(org.junit.Test)

Example 7 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method embeddedWarWithoutAppResources.

@Test
public void embeddedWarWithoutAppResources() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war");
    JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES);
    jarWarResourceSet.init();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(jarWarResourceSet, dirResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(0);
}
Also used : JarWarResourceSet(org.apache.catalina.webresources.JarWarResourceSet) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) Test(org.junit.Test)

Example 8 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method testingResources.

@Test
public void testingResources() throws LifecycleException {
    ContextMock contextMock = new ContextMock();
    DirResourceSet dirResourceSet = new DirResourceSet(contextMock.getWebResourceRoot(), TEST, TEST, TEST);
    contextMock.init(dirResourceSet);
    callApplicationEvent(contextMock);
    assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()).isEqualTo(0);
}
Also used : DirResourceSet(org.apache.catalina.webresources.DirResourceSet) Test(org.junit.Test)

Example 9 with DirResourceSet

use of org.apache.catalina.webresources.DirResourceSet in project hazelcast by hazelcast.

the class ServiceLoaderTest method testClassIteratorInTomcat_whenClassesInBothLibs.

@Test
public void testClassIteratorInTomcat_whenClassesInBothLibs() throws Exception {
    ClassLoader launchClassLoader = this.getClass().getClassLoader();
    ClassLoader webappClassLoader;
    // setup embedded tomcat
    Tomcat tomcat = new Tomcat();
    // 8080 may be used by some other tests
    tomcat.setPort(13256);
    Context ctx = tomcat.addContext("", null);
    // Map target/classes as WEB-INF/classes, so webapp classloader
    // will locate compiled production classes in the webapp classpath.
    // The purpose of this setup is to make project classes available
    // to both launch classloader and webapplication classloader,
    // modeling a Tomcat deployment in which Hazelcast JARs are deployed
    // in both tomcat/lib and webapp/lib
    File webInfClasses = new File("target/classes");
    WebResourceRoot resources = new StandardRoot(ctx);
    resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", webInfClasses.getAbsolutePath(), "/"));
    ctx.setResources(resources);
    TestServiceLoaderServlet testServlet = new TestServiceLoaderServlet();
    Wrapper wrapper = tomcat.addServlet("", "testServlet", testServlet);
    wrapper.setLoadOnStartup(1);
    ctx.addServletMappingDecoded("/", "testServlet");
    tomcat.start();
    try {
        assertTrueEventually(() -> assertTrue(testServlet.isInitDone()));
        assertNull("No failure is expected from servlet init() method", testServlet.failure());
        webappClassLoader = testServlet.getWebappClassLoader();
        assertNotEquals(launchClassLoader, webappClassLoader);
        Iterator<? extends Class<?>> iterator = ServiceLoader.classIterator(DataSerializerHook.class, "com.hazelcast.DataSerializerHook", webappClassLoader);
        assertTrue(iterator.hasNext());
        while (iterator.hasNext()) {
            Class<?> klass = iterator.next();
            assertEquals(launchClassLoader, klass.getClassLoader());
        }
    } finally {
        tomcat.stop();
    }
}
Also used : Context(org.apache.catalina.Context) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) StandardRoot(org.apache.catalina.webresources.StandardRoot) URLClassLoader(java.net.URLClassLoader) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DirResourceSet (org.apache.catalina.webresources.DirResourceSet)9 File (java.io.File)8 Test (org.junit.Test)5 WebResourceRoot (org.apache.catalina.WebResourceRoot)4 JarWarResourceSet (org.apache.catalina.webresources.JarWarResourceSet)3 StandardRoot (org.apache.catalina.webresources.StandardRoot)3 Tomcat (org.apache.catalina.startup.Tomcat)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 JarFile (java.util.jar.JarFile)1 Context (org.apache.catalina.Context)1 Wrapper (org.apache.catalina.Wrapper)1 StandardContext (org.apache.catalina.core.StandardContext)1 ClassLoaderConfigurer (org.apache.openejb.classloader.ClassLoaderConfigurer)1 CompositeClassLoaderConfigurer (org.apache.openejb.classloader.CompositeClassLoaderConfigurer)1 WebAppEnricher (org.apache.openejb.classloader.WebAppEnricher)1