Search in sources :

Example 21 with WebResource

use of org.apache.catalina.WebResource in project tomcat by apache.

the class AbstractTestResourceSetMount method testGetResourceAbove.

@Test
public final void testGetResourceAbove() {
    WebResource webResource = resourceRoot.getResource("/");
    Assert.assertFalse(webResource.exists());
}
Also used : WebResource(org.apache.catalina.WebResource) Test(org.junit.Test)

Example 22 with WebResource

use of org.apache.catalina.WebResource in project tomcat by apache.

the class TestAbstractArchiveResource method testNestedJarGetURL.

@Test
public void testNestedJarGetURL() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File docBase = new File("test/webresources/war-url-connection.war");
    Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
    skipTldsForResourceJars(ctx);
    ((StandardHost) tomcat.getHost()).setUnpackWARs(false);
    tomcat.start();
    WebResource webResource = ctx.getResources().getClassLoaderResource("/META-INF/resources/index.html");
    StringBuilder expectedURL = new StringBuilder("jar:war:");
    expectedURL.append(docBase.getAbsoluteFile().toURI().toURL().toString());
    expectedURL.append("*/WEB-INF/lib/test.jar!/META-INF/resources/index.html");
    Assert.assertEquals(expectedURL.toString(), webResource.getURL().toString());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) StandardHost(org.apache.catalina.core.StandardHost) WebResource(org.apache.catalina.WebResource) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 23 with WebResource

use of org.apache.catalina.WebResource in project tomcat by apache.

the class TestJarInputStreamWrapper method getWrappedClosedInputStream.

private InputStream getWrappedClosedInputStream() throws IOException {
    StandardRoot root = new StandardRoot();
    root.setCachingAllowed(false);
    JarResourceSet jarResourceSet = new JarResourceSet(root, "/", "test/webresources/non-static-resources.jar", "/");
    WebResource webResource = jarResourceSet.getResource("/META-INF/MANIFEST.MF");
    InputStream wrapped = webResource.getInputStream();
    wrapped.close();
    return wrapped;
}
Also used : InputStream(java.io.InputStream) WebResource(org.apache.catalina.WebResource)

Example 24 with WebResource

use of org.apache.catalina.WebResource in project tomcat by apache.

the class AbstractTestResourceSet method testGetResourceCaseSensitive.

@Test
public final void testGetResourceCaseSensitive() {
    WebResource webResource = resourceRoot.getResource(getMount() + "/d1/d1-F1.txt");
    Assert.assertFalse(webResource.exists());
}
Also used : WebResource(org.apache.catalina.WebResource) Test(org.junit.Test)

Example 25 with WebResource

use of org.apache.catalina.WebResource in project tomcat by apache.

the class AbstractTestResourceSet method testWriteDirA.

@Test
public final void testWriteDirA() {
    WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
    InputStream is = new ByteArrayInputStream("test".getBytes());
    if (d1.exists()) {
        Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is, false));
    } else if (d1.isVirtual()) {
        Assert.assertTrue(resourceRoot.write(getMount() + "/d1", is, false));
        File file = new File(getBaseDir(), "d1");
        Assert.assertTrue(file.exists());
        Assert.assertTrue(file.delete());
    } else {
        Assert.fail("Unhandled condition in unit test");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WebResource(org.apache.catalina.WebResource) File(java.io.File) Test(org.junit.Test)

Aggregations

WebResource (org.apache.catalina.WebResource)47 Test (org.junit.Test)14 InputStream (java.io.InputStream)10 File (java.io.File)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)7 URL (java.net.URL)7 BufferedInputStream (java.io.BufferedInputStream)5 FileInputStream (java.io.FileInputStream)5 InputSource (org.xml.sax.InputSource)5 PrintWriter (java.io.PrintWriter)3 RandomAccessFile (java.io.RandomAccessFile)3 Manifest (java.util.jar.Manifest)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 WebResourceSet (org.apache.catalina.WebResourceSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringWriter (java.io.StringWriter)2 Hashtable (java.util.Hashtable)2 LinkedHashSet (java.util.LinkedHashSet)2