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();
}
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();
}
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();
}
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();
}
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);
}
}
}
Aggregations