Search in sources :

Example 61 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 62 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 63 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.getCanonicalFile().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)

Example 64 with WebResource

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

the class TestAbstractArchiveResourceSet method testBloomFilterWithDirectory.

/*
     * https://bz.apache.org/bugzilla/show_bug.cgi?id=65586
     */
@Test
public void testBloomFilterWithDirectory() {
    WebResourceRoot root = new TesterWebResourceRoot();
    root.getContext().setUseBloomFilterForArchives(true);
    File file = new File("webapps/examples/WEB-INF/lib/taglibs-standard-impl-1.2.5-migrated-0.0.1.jar");
    JarResourceSet jarResourceSet = new JarResourceSet(root, "/WEB-INF/classes", file.getAbsolutePath(), "/");
    jarResourceSet.getArchiveEntries(false);
    WebResource r1 = jarResourceSet.getResource("/WEB-INF/classes/org/");
    Assert.assertTrue(r1.isDirectory());
    WebResource r2 = jarResourceSet.getResource("/WEB-INF/classes/org");
    Assert.assertTrue(r2.isDirectory());
}
Also used : WebResource(org.apache.catalina.WebResource) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot) Test(org.junit.Test)

Example 65 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)

Aggregations

WebResource (org.apache.catalina.WebResource)65 ByteArrayInputStream (java.io.ByteArrayInputStream)17 Test (org.junit.Test)17 File (java.io.File)15 InputStream (java.io.InputStream)15 BufferedInputStream (java.io.BufferedInputStream)11 IOException (java.io.IOException)10 FileInputStream (java.io.FileInputStream)9 OutputStreamWriter (java.io.OutputStreamWriter)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 PrintWriter (java.io.PrintWriter)7 RandomAccessFile (java.io.RandomAccessFile)7 URL (java.net.URL)7 InputSource (org.xml.sax.InputSource)7 StreamSource (javax.xml.transform.stream.StreamSource)5 Manifest (java.util.jar.Manifest)4 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)3 Source (javax.xml.transform.Source)3 Transformer (javax.xml.transform.Transformer)3