Search in sources :

Example 1 with MockWebResponse

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));
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) MockWebResponse(org.apache.wicket.mock.MockWebResponse) WebResponse(org.apache.wicket.request.http.WebResponse) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with MockWebResponse

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) {
    }
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) Test(org.junit.Test)

Example 3 with MockWebResponse

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"));
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) Test(org.junit.Test)

Example 4 with MockWebResponse

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());
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) Test(org.junit.Test)

Example 5 with MockWebResponse

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));
}
Also used : MockWebResponse(org.apache.wicket.mock.MockWebResponse) Component(org.apache.wicket.Component) Test(org.junit.Test)

Aggregations

MockWebResponse (org.apache.wicket.mock.MockWebResponse)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)1 IApplication (org.apache.openmeetings.IApplication)1 IWebSession (org.apache.openmeetings.IWebSession)1 Application (org.apache.wicket.Application)1 Component (org.apache.wicket.Component)1 Label (org.apache.wicket.markup.html.basic.Label)1 WebApplication (org.apache.wicket.protocol.http.WebApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)1 MockHttpSession (org.apache.wicket.protocol.http.mock.MockHttpSession)1 ServletWebRequest (org.apache.wicket.protocol.http.servlet.ServletWebRequest)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 RequestCycleContext (org.apache.wicket.request.cycle.RequestCycleContext)1 WebResponse (org.apache.wicket.request.http.WebResponse)1