use of org.apache.tapestry5.http.internal.services.ContextImpl in project tapestry-5 by apache.
the class ContextImplTest method get_resource_exists.
@Test
public void get_resource_exists() throws Exception {
String path = "/foo";
URL url = getClass().getResource("ContextImplTest.class");
ServletContext servletContext = newServletContext();
expect(servletContext.getResource(path)).andReturn(url);
replay();
URL result = new ContextImpl(servletContext).getResource(path);
assertSame(result, url);
verify();
}
use of org.apache.tapestry5.http.internal.services.ContextImpl in project tapestry-5 by apache.
the class ContextImplTest method get_attribute.
@Test
public void get_attribute() {
String name = "foo";
Object value = new Object();
ServletContext servletContext = newServletContext();
expect(servletContext.getAttribute(name)).andReturn(value);
replay();
Context context = new ContextImpl(servletContext);
assertSame(context.getAttribute(name), value);
verify();
}
use of org.apache.tapestry5.http.internal.services.ContextImpl in project tapestry-5 by apache.
the class ContextImplTest method get_real_file_exists.
@Test
public void get_real_file_exists() throws IOException {
String path = "/foo.gif";
File file = File.createTempFile("foo", "gif");
String realPath = file.getPath();
ServletContext servletContext = newServletContext();
train_getRealPath(servletContext, path, realPath);
replay();
Context c = new ContextImpl(servletContext);
File f = c.getRealFile(path);
assertEquals(f, file);
verify();
}
use of org.apache.tapestry5.http.internal.services.ContextImpl in project tapestry-5 by apache.
the class ContextImplTest method ignore_null_from_get_resource_paths.
/**
* Tomcat 5.5.20 appears to sometimes return null if it can't find a match.
*/
@Test
public void ignore_null_from_get_resource_paths() throws Exception {
ServletContext servletContext = newServletContext();
expect(servletContext.getResourcePaths("/foo")).andReturn(null);
replay();
List<String> actual = new ContextImpl(servletContext).getResourcePaths("/foo");
assertTrue(actual.isEmpty());
verify();
}
use of org.apache.tapestry5.http.internal.services.ContextImpl in project tapestry-5 by apache.
the class ContextImplTest method get_resource_exception.
@Test
public void get_resource_exception() throws Exception {
String path = "/foo";
Throwable t = new MalformedURLException("/foo is not a URL.");
ServletContext servletContext = newServletContext();
expect(servletContext.getResource(path)).andThrow(t);
replay();
try {
new ContextImpl(servletContext).getResource(path);
unreachable();
} catch (RuntimeException ex) {
assertEquals(ex.getMessage(), "java.net.MalformedURLException: /foo is not a URL.");
assertSame(ex.getCause(), t);
}
verify();
}
Aggregations