use of org.apache.catalina.WebResource in project tomcat by apache.
the class TestResourceJars method testNonStaticResources.
@Test
public void testNonStaticResources() {
File empty = new File("test/webresources/dir3");
File jar = new File("test/webresources/non-static-resources.jar");
TesterWebResourceRoot root = new TesterWebResourceRoot();
// Use empty dir for root of web app.
WebResourceSet webResourceSet = new DirResourceSet(root, "/", empty.getAbsolutePath(), "/");
root.setMainResources(webResourceSet);
// If this JAR was in a web application, this is equivalent to how it
// would be added
JarResourceSet test = new JarResourceSet(root, "/", jar.getAbsolutePath(), "/META-INF/resources");
test.setStaticOnly(true);
root.addJarResources(test);
WebResource resource = root.getClassLoaderResource("/org/apache/tomcat/unittest/foo.txt");
Assert.assertFalse(resource.exists());
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testWriteDirB.
@Test
public final void testWriteDirB() {
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");
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetCanonicalPathDoesNotExist.
@Test
public final void testGetCanonicalPathDoesNotExist() {
WebResource exists = resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
WebResource doesNotExist = resourceRoot.getResource(getMount() + "/d1/dummy.txt");
String doesNotExistCanonicalPath = doesNotExist.getCanonicalPath();
URL existsUrl = exists.getURL();
if ("file".equals(existsUrl.getProtocol())) {
// Should be possible to construct a canonical path for a resource
// that doesn't exist given that a resource that does exist in the
// same directory has a URL with the file protocol
Assert.assertNotNull(doesNotExistCanonicalPath);
} else {
Assert.assertNull(doesNotExistCanonicalPath);
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetResourceDirB.
@Test
public final void testGetResourceDirB() {
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());
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetResourceFile.
@Test
public final void testGetResourceFile() {
WebResource webResource = resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
Assert.assertTrue(webResource.isFile());
Assert.assertEquals("d1-f1.txt", webResource.getName());
Assert.assertEquals(getMount() + "/d1/d1-f1.txt", webResource.getWebappPath());
Assert.assertEquals(0, webResource.getContentLength());
Assert.assertEquals(0, webResource.getContent().length);
Assert.assertNotNull(webResource.getInputStream());
}
Aggregations