Search in sources :

Example 1 with ContextImpl

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();
}
Also used : ServletContext(javax.servlet.ServletContext) ContextImpl(org.apache.tapestry5.http.internal.services.ContextImpl) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 2 with ContextImpl

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();
}
Also used : ServletContext(javax.servlet.ServletContext) Context(org.apache.tapestry5.http.services.Context) ServletContext(javax.servlet.ServletContext) ContextImpl(org.apache.tapestry5.http.internal.services.ContextImpl) Test(org.testng.annotations.Test)

Example 3 with ContextImpl

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();
}
Also used : ServletContext(javax.servlet.ServletContext) Context(org.apache.tapestry5.http.services.Context) ServletContext(javax.servlet.ServletContext) ContextImpl(org.apache.tapestry5.http.internal.services.ContextImpl) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with ContextImpl

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();
}
Also used : ServletContext(javax.servlet.ServletContext) ContextImpl(org.apache.tapestry5.http.internal.services.ContextImpl) Test(org.testng.annotations.Test)

Example 5 with ContextImpl

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();
}
Also used : MalformedURLException(java.net.MalformedURLException) ServletContext(javax.servlet.ServletContext) ContextImpl(org.apache.tapestry5.http.internal.services.ContextImpl) Test(org.testng.annotations.Test)

Aggregations

ServletContext (javax.servlet.ServletContext)7 ContextImpl (org.apache.tapestry5.http.internal.services.ContextImpl)7 Test (org.testng.annotations.Test)7 Context (org.apache.tapestry5.http.services.Context)3 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1