Search in sources :

Example 56 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WServlet_Test method testSubSessionsDisabled.

@Test
public void testSubSessionsDisabled() throws ServletException, IOException {
    Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "false");
    MyWServlet servlet = new MyWServlet(new WText("test"));
    servlet.init(new MockServletConfig());
    MockHttpSession session = new MockHttpSession();
    MockHttpServletRequest request = new MockHttpServletRequest(session);
    request.setParameter("ssid", "1");
    servlet.service(request, new MockHttpServletResponse());
    Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
    request = new MockHttpServletRequest(session);
    request.setParameter("ssid", "2");
    servlet.service(request, new MockHttpServletResponse());
    Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount);
    request = new MockHttpServletRequest(session);
    request.setParameter("ssid", "1");
    servlet.service(request, new MockHttpServletResponse());
    Assert.assertEquals("Incorrect invocation count", 3, servlet.lastInvocationCount);
}
Also used : WText(com.github.bordertech.wcomponents.WText) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 57 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WServlet_Test method testServiceNormalRequest.

@Test
public void testServiceNormalRequest() throws ServletException, IOException {
    MockServletConfig config = new MockServletConfig();
    config.setInitParameter(WServlet.WServletHelper.ONGOING_URL_SUFFIX, "foo");
    MockContainer content = new MockContainer();
    content.add(new WText(LABEL_TEXT));
    content.setLocked(true);
    MyWServlet servlet = new MyWServlet(content);
    servlet.init(config);
    MockHttpSession session1 = new MockHttpSession();
    MockHttpSession session2 = new MockHttpSession();
    sendRequest(session1, servlet);
    sendRequest(session2, servlet);
    sendRequest(session1, servlet);
    // check handle request / paint counts for each session
    UIContext uic = getContextForSession(servlet, session1);
    setActiveContext(uic);
    Assert.assertEquals("Incorrect handle request count for session1", 2, content.getHandleRequestCount());
    Assert.assertEquals("Incorrect paint count for session1", 2, content.getPaintCount());
    uic = getContextForSession(servlet, session2);
    setActiveContext(uic);
    Assert.assertEquals("Incorrect handle request count for session2", 1, content.getHandleRequestCount());
    Assert.assertEquals("Incorrect paint count for session2", 1, content.getPaintCount());
}
Also used : MockContainer(com.github.bordertech.wcomponents.MockContainer) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 58 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WServlet_Test method testHttpMethodTypes.

@Test
public void testHttpMethodTypes() throws ServletException, IOException {
    MyWServlet servlet = new MyWServlet(new WText("test"));
    servlet.init(new MockServletConfig());
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("http://localhost/foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    servlet.service(request, response);
    Assert.assertEquals("Incorrect status code", 200, response.getStatus());
    Assert.assertTrue("Should have written content", response.getOutput().length > 0);
    response = new MockHttpServletResponse();
    request.setMethod("POST");
    servlet.service(request, response);
    Assert.assertEquals("Incorrect status code", 200, response.getStatus());
    Assert.assertTrue("Should have written content", response.getOutput().length > 0);
    response = new MockHttpServletResponse();
    request.setMethod("HEAD");
    servlet.service(request, response);
    Assert.assertEquals("Incorrect status code", 200, response.getStatus());
    Assert.assertNull("Should not have written any content for HEAD request", response.getOutput());
    response = new MockHttpServletResponse();
    request.setMethod("DELETE");
    servlet.service(request, response);
    Assert.assertEquals("Incorrect status code", 501, response.getStatus());
    Assert.assertNull("Should not have written any content for HEAD request", response.getOutput());
}
Also used : WText(com.github.bordertech.wcomponents.WText) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 59 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WServlet_Test method testSubSessionsEnabledNoSSID.

@Test
public void testSubSessionsEnabledNoSSID() throws ServletException, IOException {
    Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "true");
    MyWServlet servlet = new MyWServlet(new WText("test"));
    servlet.init(new MockServletConfig());
    MockHttpSession session = new MockHttpSession();
    servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
    Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
    // No SSID should trigger a new subsession
    servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse());
    Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount);
}
Also used : WText(com.github.bordertech.wcomponents.WText) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Example 60 with WText

use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.

the class WTextRenderer method doRender.

/**
 * Paints the given WText.
 *
 * @param component the WText to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WText text = (WText) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String textString = text.getText();
    if (textString != null) {
        if (text.isEncodeText()) {
            xml.print(WebUtilities.encode(textString));
        } else {
            // If we are outputting unencoded content it must be XML valid.
            xml.print(HtmlToXMLUtil.unescapeToXML(textString));
        }
    }
}
Also used : WText(com.github.bordertech.wcomponents.WText) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

WText (com.github.bordertech.wcomponents.WText)97 Test (org.junit.Test)63 WPanel (com.github.bordertech.wcomponents.WPanel)17 WCollapsible (com.github.bordertech.wcomponents.WCollapsible)10 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)10 UIContext (com.github.bordertech.wcomponents.UIContext)9 WHeading (com.github.bordertech.wcomponents.WHeading)9 WTabSet (com.github.bordertech.wcomponents.WTabSet)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)6 WList (com.github.bordertech.wcomponents.WList)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)6 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)5 WComponent (com.github.bordertech.wcomponents.WComponent)5 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)5 WImage (com.github.bordertech.wcomponents.WImage)5 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)5 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)5