use of org.apache.tapestry5.internal.test.TestableResponse in project tapestry-5 by apache.
the class PageTesterModule method setupTestableOverrides.
@Contribute(ServiceOverride.class)
public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local TestableRequest request, @Local TestableResponse response, final ObjectLocator locator) {
configuration.add(Request.class, request);
configuration.add(Response.class, response);
TestableCookieSinkSource cookies = new TestableCookieSinkSource();
configuration.add(CookieSink.class, cookies);
configuration.add(CookieSource.class, cookies);
// With the significant changes to the handling of assets in 5.4, we introduced a problem:
// We were checking at page render time whether to generate URLs for normal or compressed
// assets and that peeked at the HttpServletRequest global, which isn't set up by PageTester.
// What we're doing here is using a hacked version of that code to force GZip support
// on.
configuration.add(ResponseCompressionAnalyzer.class, new ResponseCompressionAnalyzer() {
public boolean isGZipEnabled(ContentType contentType) {
return locator.getObject(CompressionAnalyzer.class, null).isCompressable(contentType.getMimeType());
}
public boolean isGZipSupported() {
return true;
}
});
}
use of org.apache.tapestry5.internal.test.TestableResponse in project tapestry-5 by apache.
the class TestableResponseImplTest method http_headers.
@Test
public void http_headers() {
Document document = tester.renderPage(TestPageForHttpHeaders.class.getSimpleName());
assertTrue(document.toString().contains("Test page for HTTP headers"));
TestableResponse response = tester.getService(TestableResponse.class);
assertEquals(response.getHeader(TestPageForHttpHeaders.DATE_HEADER_NAME), 12345L);
assertEquals(response.getHeader(TestPageForHttpHeaders.INT_HEADER_NAME), 6789);
assertEquals(response.getHeader(TestPageForHttpHeaders.STRING_HEADER_NAME), "foo-bar-baz-barney");
}
use of org.apache.tapestry5.internal.test.TestableResponse in project tapestry-5 by apache.
the class PageTester method runComponentEventRequest.
private TestableResponse runComponentEventRequest() {
while (true) {
response.clear();
try {
boolean handled = requestHandler.service(request, response);
if (!handled)
throw new RuntimeException(String.format("Request for path '%s' was not handled by Tapestry.", request.getPath()));
Link link = response.getRedirectLink();
if (link != null) {
setupRequestFromLink(link);
continue;
}
return response;
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
registry.cleanupThread();
}
}
}
use of org.apache.tapestry5.internal.test.TestableResponse in project tapestry-5 by apache.
the class PageTester method renderPageAndReturnResponse.
/**
* Renders a page specified by its name and returns the response.
*
* @param pageName
* The name of the page to be rendered.
* @return The response object to assert against
* @since 5.2.3
*/
public TestableResponse renderPageAndReturnResponse(String pageName) {
request.clear().setPath("/" + pageName);
while (true) {
try {
response.clear();
boolean handled = requestHandler.service(request, response);
if (!handled) {
throw new RuntimeException(String.format("Request was not handled: '%s' may not be a valid page name.", pageName));
}
Link link = response.getRedirectLink();
if (link != null) {
setupRequestFromLink(link);
continue;
}
return response;
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
registry.cleanupThread();
}
}
}
use of org.apache.tapestry5.internal.test.TestableResponse in project tapestry-5 by apache.
the class PageTester method clickSubmitAndReturnResponse.
/**
* Simulates a submission of the form by clicking the specified submit button. The caller can
* specify values for the
* form fields.
*
* @param submitButton
* the submit button to be clicked.
* @param fieldValues
* the field values keyed on field names.
* @return The response object to assert against.
* @since 5.2.3
*/
public TestableResponse clickSubmitAndReturnResponse(Element submitButton, Map<String, String> fieldValues) {
assert submitButton != null;
assertIsSubmit(submitButton);
Element form = getFormAncestor(submitButton);
request.clear().setPath(stripContextFromPath(extractNonBlank(form, "action")));
pushFieldValuesIntoRequest(form);
overrideParameters(fieldValues);
String value = submitButton.getAttribute("value");
if (value == null)
value = DEFAULT_SUBMIT_VALUE_ATTRIBUTE;
request.overrideParameter(extractNonBlank(submitButton, "name"), value);
return runComponentEventRequest();
}
Aggregations