use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method page_requires_whitelist_and_client_not_on_whitelist.
@Test
public void page_requires_whitelist_and_client_not_on_whitelist() {
ComponentClassResolver resolver = mockComponentClassResolver();
Request request = mockRequest();
LocalizationSetter ls = mockLocalizationSetter();
MetaDataLocator metaDataLocator = mockMetaDataLocator();
ClientWhitelist whitelist = newMock(ClientWhitelist.class);
String path = "/foo/Bar";
train_getPath(request, path);
train_setLocaleFromLocaleName(ls, "foo", false);
train_isPageName(resolver, "foo/Bar", true);
train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
expect(metaDataLocator.findMeta(MetaDataConstants.WHITELIST_ONLY_PAGE, "foo/bar", boolean.class)).andReturn(true);
expect(whitelist.isClientRequestOnWhitelist()).andReturn(false);
train_isPageName(resolver, "foo", false);
train_isPageName(resolver, "", false);
replay();
ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, whitelist);
assertNull(linkEncoder.decodePageRenderRequest(request));
verify();
}
use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.
the class ComponentTemplateSourceImplTest method localization_to_same.
/**
* Checks that localization to the same resource works (w/ caching).
*/
@Test
public void localization_to_same() {
Resource resource = mockResource();
TemplateParser parser = mockTemplateParser();
ComponentTemplate template = mockComponentTemplate();
ComponentModel model = mockComponentModel();
ComponentResourceLocator locator = newMock(ComponentResourceLocator.class);
train_getComponentClassName(model, PACKAGE + ".Fred");
expect(locator.locateTemplate(model, english)).andReturn(resource).once();
expect(resource.exists()).andReturn(true).anyTimes();
expect(resource.toURL()).andReturn(null).anyTimes();
expect(locator.locateTemplate(model, french)).andReturn(resource).once();
train_parseTemplate(parser, resource, template);
replay();
ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(true, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
assertSame(source.getTemplate(model, Locale.ENGLISH), template);
// A second pass finds the same resource, but using a different
// path/locale combination.
assertSame(source.getTemplate(model, Locale.FRENCH), template);
// A third pass should further demonstrate the caching.
assertSame(source.getTemplate(model, Locale.FRENCH), template);
verify();
}
use of org.apache.tapestry5.annotations.Path 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();
}
use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.
the class ContextImplTest method get_real_file_missing.
@Test
public void get_real_file_missing() {
String path = "/foo.gif";
ServletContext servletContext = newServletContext();
train_getRealPath(servletContext, path, null);
replay();
Context c = new ContextImpl(servletContext);
assertNull(c.getRealFile(path));
verify();
}
use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.
the class AbstractReloadableObjectCreator method doClassLoad.
public Class<?> doClassLoad(String className) throws IOException {
ClassVisitor analyzer = new ClassVisitor(Opcodes.ASM9) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
String path = superName + ".class";
URL url = baseClassLoader.getResource(path);
if (isFileURL(url)) {
add(PlasticInternalUtils.toClassName(superName));
}
}
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
// the internal name of the containing class.
if (outerName == null || classesToLoad.contains(PlasticInternalUtils.toClassName(outerName))) {
add(PlasticInternalUtils.toClassName(name));
}
}
};
String path = PlasticInternalUtils.toClassPath(className);
InputStream stream = baseClassLoader.getResourceAsStream(path);
assert stream != null;
ByteArrayOutputStream classBuffer = new ByteArrayOutputStream(5000);
byte[] buffer = new byte[5000];
while (true) {
int length = stream.read(buffer);
if (length < 0) {
break;
}
classBuffer.write(buffer, 0, length);
}
stream.close();
byte[] bytecode = classBuffer.toByteArray();
new ClassReader(new ByteArrayInputStream(bytecode)).accept(analyzer, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return loader.defineClassWithBytecode(className, bytecode);
}
Aggregations