Search in sources :

Example 26 with Response

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

the class ComponentEventLinkEncoderImplTest method index_stripped_off.

@Test
public void index_stripped_off() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/admin/abc", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 27 with Response

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

the class ComponentEventLinkEncoderImplTest method illegal_activation_context_leads_to_http_404.

@Test
public // TAP5-2436
void illegal_activation_context_leads_to_http_404() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    train_getPath(request, "/foo/pageid=123");
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_isPageName(resolver, "foo/pageid=123", false);
    train_isPageName(resolver, "foo", false);
    train_isPageName(resolver, "", true);
    train_canonicalizePageName(resolver, "", "Index");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) Test(org.testng.annotations.Test)

Example 28 with Response

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

the class ComponentEventLinkEncoderImplTest method not_a_page_request.

@Test
public void not_a_page_request() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    stub_isPageName(resolver, false);
    train_setLocaleFromLocaleName(ls, "foo", false);
    train_getPath(request, "/foo/Bar.baz");
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) Test(org.testng.annotations.Test)

Example 29 with Response

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

the class ComponentEventLinkEncoderImplTest method empty_path.

@Test
public void empty_path() throws Exception {
    ComponentClassResolver resolver = mockComponentClassResolver();
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    train_getPath(request, "");
    train_setLocaleFromLocaleName(ls, "", false);
    train_isPageName(resolver, "", false);
    replay();
    ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null);
    PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request);
    assertNull(parameters);
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) 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) Test(org.testng.annotations.Test)

Example 30 with Response

use of org.apache.tapestry5.http.services.Response 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)

Aggregations

Test (org.testng.annotations.Test)53 Response (org.apache.tapestry5.http.services.Response)47 Request (org.apache.tapestry5.http.services.Request)25 Link (org.apache.tapestry5.http.Link)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)12 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)12 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)11 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)11 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 JSONObject (org.apache.tapestry5.json.JSONObject)8 Context (org.apache.tapestry5.http.services.Context)7 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)7 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)6 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)6 IOException (java.io.IOException)5