Search in sources :

Example 6 with F

use of org.apache.tapestry5.func.F 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 7 with F

use of org.apache.tapestry5.func.F in project tapestry-5 by apache.

the class ContextResourceTest method get_url_file_exists.

@Test
public void get_url_file_exists() throws Exception {
    File f = File.createTempFile("Bar", ".txt");
    String path = "/foo/" + f.getName();
    Context context = mockContext();
    expect(context.getRealFile(path)).andReturn(f);
    replay();
    Resource r = new ContextResource(context, "foo/" + f.getName());
    assertEquals(r.toURL(), f.toURL());
    verify();
}
Also used : Context(org.apache.tapestry5.http.services.Context) Resource(org.apache.tapestry5.commons.Resource) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with F

use of org.apache.tapestry5.func.F in project tapestry-5 by apache.

the class ComponentTemplateSourceImplTest method invalidation.

/**
 * Tests resource invalidation.
 */
@Test
public void invalidation() throws Exception {
    File rootDir = createClasspathRoot();
    URLClassLoader loader = newLoaderWithClasspathRoot(rootDir);
    ComponentModel model = mockComponentModel();
    File packageDir = new File(rootDir, "baz");
    packageDir.mkdirs();
    File f = new File(packageDir, "Biff.tml");
    f.createNewFile();
    Resource baseResource = new ClasspathResource(loader, "baz/Biff.class");
    Resource localized = baseResource.withExtension(TapestryConstants.TEMPLATE_EXTENSION);
    TemplateParser parser = mockTemplateParser();
    ComponentTemplate template = mockComponentTemplate();
    InvalidationListener listener = mockInvalidationListener();
    train_getComponentClassName(model, "baz.Biff");
    ComponentResourceLocator locator = mockLocator(model, english, localized);
    train_parseTemplate(parser, localized, template);
    replay();
    ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(false, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
    source.addInvalidationListener(listener);
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    // Check for updates (which won't be found).
    source.checkForUpdates();
    // A second pass will test the caching (the
    // parser is not invoked).
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    verify();
    // Now, change the file and processInbound an UpdateEvent.
    touch(f);
    listener.objectWasInvalidated();
    replay();
    // Check for updates (which will be found).
    source.checkForUpdates();
    verify();
    // Check that the cache really is cleared.
    train_getComponentClassName(model, "baz.Biff");
    expect(locator.locateTemplate(model, english)).andReturn(localized);
    train_parseTemplate(parser, localized, template);
    replay();
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    verify();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) URLClassLoader(java.net.URLClassLoader) ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) InvalidationListener(org.apache.tapestry5.commons.services.InvalidationListener) File(java.io.File) Test(org.testng.annotations.Test)

Example 9 with F

use of org.apache.tapestry5.func.F in project tapestry-5 by apache.

the class SessionImplTest method get_attribute_names_by_prefix.

@Test
public void get_attribute_names_by_prefix() {
    Enumeration e = Collections.enumeration(Arrays.asList("fred", "barney", "fanny"));
    HttpSession hs = mockHttpSession();
    SessionLock lock = mockLock();
    lock.acquireReadLock();
    expect(hs.getAttributeNames()).andReturn(e);
    replay();
    Session session = new SessionImpl(null, hs, lock);
    assertEquals(session.getAttributeNames("f"), Arrays.asList("fanny", "fred"));
    verify();
}
Also used : Enumeration(java.util.Enumeration) HttpSession(javax.servlet.http.HttpSession) SessionImpl(org.apache.tapestry5.http.internal.services.SessionImpl) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 10 with F

use of org.apache.tapestry5.func.F in project tapestry-5 by apache.

the class TestInjectTransformer method transform.

@Override
public void transform(PlasticClass plasticClass) {
    for (PlasticField f : plasticClass.getFieldsWithAnnotation(TestInject.class)) {
        if (f.getTypeName().equals(className)) {
            f.inject(fieldValue);
            f.claim(this);
        }
    }
}
Also used : PlasticField(org.apache.tapestry5.plastic.PlasticField)

Aggregations

Test (org.testng.annotations.Test)7 File (java.io.File)4 Context (org.apache.tapestry5.http.services.Context)3 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Resource (org.apache.tapestry5.commons.Resource)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 URLClassLoader (java.net.URLClassLoader)1 Enumeration (java.util.Enumeration)1 Formatter (java.util.Formatter)1 ServletContext (javax.servlet.ServletContext)1 HttpSession (javax.servlet.http.HttpSession)1 InvalidationListener (org.apache.tapestry5.commons.services.InvalidationListener)1 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)1 ContextImpl (org.apache.tapestry5.http.internal.services.ContextImpl)1 SessionImpl (org.apache.tapestry5.http.internal.services.SessionImpl)1 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)1 Session (org.apache.tapestry5.http.services.Session)1 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)1 ConstantDynamic (org.apache.tapestry5.internal.plastic.asm.ConstantDynamic)1