Search in sources :

Example 26 with WebResource

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

the class AbstractTestResourceSet method testGetResourceDirA.

@Test
public final void testGetResourceDirA() {
    WebResource webResource = resourceRoot.getResource(getMount() + "/d1");
    Assert.assertTrue(webResource.isDirectory());
    Assert.assertEquals("d1", webResource.getName());
    Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath());
    Assert.assertEquals(-1, webResource.getContentLength());
    Assert.assertNull(webResource.getContent());
    Assert.assertNull(webResource.getInputStream());
}
Also used : WebResource(org.apache.catalina.WebResource) Test(org.junit.Test)

Example 27 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 28 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 29 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 30 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)

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