Search in sources :

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

Example 52 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 53 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 54 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 55 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)

Aggregations

WebResource (org.apache.catalina.WebResource)57 Test (org.junit.Test)17 File (java.io.File)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 InputStream (java.io.InputStream)11 IOException (java.io.IOException)8 URL (java.net.URL)7 BufferedInputStream (java.io.BufferedInputStream)6 InputSource (org.xml.sax.InputSource)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileInputStream (java.io.FileInputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 PrintWriter (java.io.PrintWriter)4 RandomAccessFile (java.io.RandomAccessFile)4 Manifest (java.util.jar.Manifest)4 StreamSource (javax.xml.transform.stream.StreamSource)3 WebResourceRoot (org.apache.catalina.WebResourceRoot)3 WebResourceSet (org.apache.catalina.WebResourceSet)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2