Search in sources :

Example 41 with Path

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();
}
Also used : ClientWhitelist(org.apache.tapestry5.services.security.ClientWhitelist) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 42 with Path

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) Test(org.testng.annotations.Test)

Example 43 with Path

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

Example 44 with Path

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();
}
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 45 with Path

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClassReader(org.apache.tapestry5.internal.plastic.asm.ClassReader) ClassVisitor(org.apache.tapestry5.internal.plastic.asm.ClassVisitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4