Search in sources :

Example 41 with WText

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

the class WTextRenderer_Test method testEncodeText.

@Test
public void testEncodeText() throws IOException, SAXException, XpathException {
    String value = "T1<b>T2</b>T3";
    String encoded = WebUtilities.encode(value);
    WText text = new WText();
    text.setText(value);
    // Encoded (default)
    String xml = toXHtml(text);
    Assert.assertTrue("XML should have encoded text", xml.contains(encoded));
    // Not encoded
    text.setEncodeText(false);
    xml = toXHtml(text);
    Assert.assertTrue("XML should have not encoded text", xml.contains(value));
}
Also used : WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 42 with WText

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

the class WTextRenderer_Test method testDoPaintWhenEmpty.

@Test
public void testDoPaintWhenEmpty() throws IOException, SAXException, XpathException {
    WText text = new WText();
    String xml = toXHtml(text);
    Assert.assertEquals("Text output should be empty by default", "", xml);
}
Also used : WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 43 with WText

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

the class WTextRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WText text = new WText();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(text) instanceof WTextRenderer);
}
Also used : WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Example 44 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 45 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)

Aggregations

WText (com.github.bordertech.wcomponents.WText)100 Test (org.junit.Test)63 WPanel (com.github.bordertech.wcomponents.WPanel)18 WCollapsible (com.github.bordertech.wcomponents.WCollapsible)10 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)10 WHeading (com.github.bordertech.wcomponents.WHeading)10 UIContext (com.github.bordertech.wcomponents.UIContext)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 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)5 WImage (com.github.bordertech.wcomponents.WImage)5 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)5 WTextField (com.github.bordertech.wcomponents.WTextField)5 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)5