Search in sources :

Example 11 with ComponentClassResolver

use of org.apache.tapestry5.services.ComponentClassResolver in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method no_extra_context.

private void no_extra_context(boolean finalSlash) throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest(false);
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    String path = "/foo/Bar" + (finalSlash ? "/" : "");
    train_getPath(request, path);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/Bar", true);
    train_canonicalizePageName(resolver, "foo/Bar", "foo/bar");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, null, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertEquals(parameters.getLogicalPageName(), "foo/bar");
    assertEquals(parameters.getActivationContext().getCount(), 0);
    assertFalse(parameters.isLoopback());
    verify();
}
Also used : PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) 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)

Example 12 with ComponentClassResolver

use of org.apache.tapestry5.services.ComponentClassResolver in project tapestry-5 by apache.

the class DefaultRequestExceptionHandlerTest method handleRequestExceptionWithConfiguredPage.

@Test
public void handleRequestExceptionWithConfiguredPage() throws IOException {
    train_resolvePageClassNameToPageName(componentClassResolver, MyPage.class.getName(), "mypage");
    Link link = mockLink();
    expect(linkSource.createPageRenderLink("mypage", false, new Object[] { "accesscontrol" })).andReturn(link);
    expect(request.isXHR()).andReturn(false);
    response.sendRedirect(link);
    EasyMock.expectLastCall();
    replay();
    // also test unwrapping TapestryExceptions
    exceptionHandler.handleRequestException(new OperationException(new RenderQueueException("renderqueue", new Object[0], new TapestryException("tapestryexception", new AccessControlException("No permission"))), new String[0]));
}
Also used : AccessControlException(java.security.AccessControlException) Link(org.apache.tapestry5.http.Link) OperationException(org.apache.tapestry5.ioc.internal.OperationException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Test(org.testng.annotations.Test)

Example 13 with ComponentClassResolver

use of org.apache.tapestry5.services.ComponentClassResolver in project tapestry-5 by apache.

the class DefaultRequestExceptionHandlerTest method setup_tests.

@BeforeMethod
public void setup_tests() throws Exception {
    mockConfiguration.clear();
    pageCache = mockRequestPageCache();
    renderer = mockPageResponseRenderer();
    logger = mockLogger();
    request = mockRequest();
    response = mockResponse();
    componentClassResolver = mockComponentClassResolver();
    linkSource = mockLinkSource();
    serviceResources = mockServiceResources();
    mockConfiguration.put(AccessControlException.class, MyPage.class);
    mockConfiguration.put(MyContextAwareException.class, new ExceptionHandlerAssistant() {

        public Object handleRequestException(Throwable exception, List<Object> exceptionContext) throws IOException {
            return null;
        }
    });
    ExceptionReporter noopExceptionReporter = new ExceptionReporter() {

        @Override
        public void reportException(Throwable exception) {
        }
    };
    exceptionHandler = new DefaultRequestExceptionHandler(pageCache, renderer, logger, "exceptionpage", request, response, componentClassResolver, linkSource, serviceResources, noopExceptionReporter, false, mockConfiguration);
}
Also used : ExceptionHandlerAssistant(org.apache.tapestry5.ExceptionHandlerAssistant) ExceptionReporter(org.apache.tapestry5.services.ExceptionReporter) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 14 with ComponentClassResolver

use of org.apache.tapestry5.services.ComponentClassResolver in project tapestry-5 by apache.

the class ComponentSourceImplTest method get_active_page.

@Test
public void get_active_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    RequestGlobals globals = mockRequestGlobals();
    String pageName = "Active";
    expect(globals.getActivePageName()).andReturn(pageName);
    train_get(cache, pageName, page);
    train_getRootComponent(page, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, globals);
    assertSame(source.getActivePage(), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) RequestGlobals(org.apache.tapestry5.http.services.RequestGlobals) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 15 with ComponentClassResolver

use of org.apache.tapestry5.services.ComponentClassResolver in project tapestry-5 by apache.

the class ComponentSourceImplTest method nested_element_within_page.

@Test
public void nested_element_within_page() {
    RequestPageCache cache = mockRequestPageCache();
    Page page = mockPage();
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    ComponentClassResolver resolver = mockComponentClassResolver();
    train_get(cache, PAGE_NAME, page);
    train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
    train_getComponent(element, component);
    replay();
    ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
    assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
    verify();
}
Also used : ComponentSource(org.apache.tapestry5.services.ComponentSource) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Aggregations

ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)27 Test (org.testng.annotations.Test)23 Request (org.apache.tapestry5.http.services.Request)17 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)17 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)13 Response (org.apache.tapestry5.http.services.Response)11 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)11 Link (org.apache.tapestry5.http.Link)6 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)6 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 Page (org.apache.tapestry5.internal.structure.Page)5 Component (org.apache.tapestry5.runtime.Component)5 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)5 ComponentSource (org.apache.tapestry5.services.ComponentSource)5 RequestGlobals (org.apache.tapestry5.http.services.RequestGlobals)4 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)4 EventContext (org.apache.tapestry5.EventContext)3 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)3 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2