use of org.apache.wicket.mock.MockWebResponse in project wicket by apache.
the class BufferedWebResponseTest method testBufferedResponsePostponeWriteResponseAction.
/**
* Asserting that set header actions are invoked before write in response actions.
*
* WICKET-3618
*/
@Test
public void testBufferedResponsePostponeWriteResponseAction() {
final ArrayList<TestAction> actionsSequence = new ArrayList<TestAction>();
WebResponse originalResponse = new MockWebResponse() {
@Override
public void setContentLength(long length) {
actionsSequence.add(TestAction.SET_CONTENT_LENGTH);
}
@Override
public void write(CharSequence sequence) {
actionsSequence.add(TestAction.WRITE_RESPONSE);
}
/**
* WICKET-5863
*/
@Override
public void disableCaching() {
actionsSequence.add(TestAction.DISABLE_CACHING);
}
};
BufferedWebResponse response = new BufferedWebResponse(originalResponse);
response.setText("some text");
response.setContentLength(9);
response.disableCaching();
response.writeTo(originalResponse);
assertEquals(0, actionsSequence.indexOf(TestAction.SET_CONTENT_LENGTH));
assertEquals(1, actionsSequence.indexOf(TestAction.DISABLE_CACHING));
assertEquals(2, actionsSequence.indexOf(TestAction.WRITE_RESPONSE));
}
use of org.apache.wicket.mock.MockWebResponse in project wicket by apache.
the class HeaderBufferingWebResponseTest method resetAfterWrittenContent.
/**
*/
@Test
public void resetAfterWrittenContent() {
MockWebResponse originalResponse = new MockWebResponse();
HeaderBufferingWebResponse response = new HeaderBufferingWebResponse(originalResponse);
response.addHeader("key1", "value1");
assertNull(originalResponse.getHeader("key1"));
response.reset();
response.write("written");
try {
response.reset();
fail();
} catch (IllegalStateException expected) {
}
}
use of org.apache.wicket.mock.MockWebResponse in project wicket by apache.
the class HeaderBufferingWebResponseTest method additionalHeaderAfterWrittenContent.
/**
* WICKET-4927
*/
@Test
public void additionalHeaderAfterWrittenContent() {
MockWebResponse originalResponse = new MockWebResponse();
HeaderBufferingWebResponse response = new HeaderBufferingWebResponse(originalResponse);
response.addHeader("key1", "value1");
assertNull(originalResponse.getHeader("key1"));
response.write("written");
assertEquals("value1", originalResponse.getHeader("key1"));
response.addHeader("key2", "value2");
assertEquals("value2", originalResponse.getHeader("key2"));
}
use of org.apache.wicket.mock.MockWebResponse in project wicket by apache.
the class XmlPartialPageUpdateTest method encodeCdataEnd.
/**
* CData start "]]>" has to be encoded in "]]]]><![CDATA[>".
*/
@Test
public void encodeCdataEnd() {
PageForPartialUpdate page = new PageForPartialUpdate();
XmlPartialPageUpdate update = new XmlPartialPageUpdate(page);
update.add(page.container, page.container.getMarkupId());
MockWebResponse response = new MockWebResponse();
update.writeTo(response, "UTF-8");
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax-response><component id=\"container1\" ><![CDATA[<span wicket:id=\"container\" id=\"container1\"> two brackets: ]] greater than: > CDATA end: ]]]]><![CDATA[> </span>]]></component><header-contribution><![CDATA[<head xmlns:wicket=\"http://wicket.apache.org\"><script type=\"text/javascript\" >\n" + "/*<![CDATA[*/\n" + "// two brackets: ]] greater than: > CDATA end: ]]]]><![CDATA[>\n" + "/*]]]]><![CDATA[>*/\n" + "</script>\n" + "</head>]]></header-contribution></ajax-response>";
assertEquals(expected, response.getTextResponse().toString());
}
use of org.apache.wicket.mock.MockWebResponse in project wicket by apache.
the class XmlPartialPageUpdateTest method keepTheSameHeaderContainer.
/**
* see https://issues.apache.org/jira/browse/WICKET-6162
*/
@Test
public void keepTheSameHeaderContainer() throws Exception {
PageForPartialUpdate page = new PageForPartialUpdate();
tester.startPage(page);
Component originalHeader = page.get(HtmlHeaderSectionHandler.HEADER_ID);
XmlPartialPageUpdate update = new XmlPartialPageUpdate(page);
update.add(page.container, page.container.getMarkupId());
MockWebResponse response = new MockWebResponse();
update.writeTo(response, "UTF-8");
assertEquals(originalHeader, page.get(HtmlHeaderSectionHandler.HEADER_ID));
}
Aggregations