Search in sources :

Example 41 with WebResource

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

the class AbstractTestResourceSet method testGetManifest.

// ----------------------------------------------------------- getManifest()
@Test
public final void testGetManifest() {
    WebResource exists = resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
    boolean manifestExists = resourceRoot.getResource("/META-INF/MANIFEST.MF").exists();
    Manifest m = exists.getManifest();
    if (getMount().equals("") && manifestExists) {
        Assert.assertNotNull(m);
    } else {
        Assert.assertNull(m);
    }
}
Also used : WebResource(org.apache.catalina.WebResource) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Example 42 with WebResource

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

the class AbstractTestResourceSet method doTestGetResourceRoot.

private void doTestGetResourceRoot(boolean slash) {
    String mount = getMount();
    if (!slash && mount.length() == 0) {
        return;
    }
    mount = mount + (slash ? "/" : "");
    WebResource webResource = resourceRoot.getResource(mount);
    Assert.assertTrue(webResource.isDirectory());
    String expected;
    if (getMount().length() > 0) {
        expected = getMount().substring(1);
    } else {
        expected = "";
    }
    Assert.assertEquals(expected, webResource.getName());
    Assert.assertEquals(mount + (!slash ? "/" : ""), webResource.getWebappPath());
}
Also used : WebResource(org.apache.catalina.WebResource)

Example 43 with WebResource

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

the class AbstractTestResourceSet method testGetCanonicalPathExists.

// ------------------------------------------------------ getCanonicalPath()
@Test
public final void testGetCanonicalPathExists() {
    WebResource exists = resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
    String existsCanonicalPath = exists.getCanonicalPath();
    URL existsUrl = exists.getURL();
    if ("file".equals(existsUrl.getProtocol())) {
        // Should have a canonical path
        Assert.assertNotNull(existsCanonicalPath);
    } else {
        Assert.assertNull(existsCanonicalPath);
    }
}
Also used : WebResource(org.apache.catalina.WebResource) URL(java.net.URL) Test(org.junit.Test)

Example 44 with WebResource

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

the class AbstractTestResourceSet method testGetResourceTraversal.

@Test
public final void testGetResourceTraversal() {
    WebResource webResource = null;
    try {
        webResource = resourceRoot.getResource(getMount() + "/../");
    } catch (IllegalArgumentException iae) {
        // Expected if mount point is zero length
        Assert.assertTrue(getMount().length() == 0);
        return;
    }
    Assert.assertFalse(webResource.exists());
}
Also used : WebResource(org.apache.catalina.WebResource) Test(org.junit.Test)

Example 45 with WebResource

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

the class TestAbstractArchiveResource method testJarGetURL.

@Test
public void testJarGetURL() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File docBase = new File("test/webapp");
    Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
    skipTldsForResourceJars(ctx);
    ((StandardHost) tomcat.getHost()).setUnpackWARs(false);
    tomcat.start();
    WebResource webResource = ctx.getResources().getClassLoaderResource("/META-INF/tags/echo.tag");
    StringBuilder expectedURL = new StringBuilder("jar:");
    expectedURL.append(docBase.getAbsoluteFile().toURI().toURL().toString());
    expectedURL.append("WEB-INF/lib/test-lib.jar!/META-INF/tags/echo.tag");
    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)

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