Search in sources :

Example 1 with MockContentAccess

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

the class WContentRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    MockRequest request = new MockRequest();
    MockContentAccess content = new MockContentAccess();
    content.setBytes(new byte[] { 1, 2, 3 });
    // Shouldn't display have any content by default
    WContent wContent = new WContent();
    setActiveContext(createUIContext());
    wContent.setContentAccess(content);
    // this test needs the URLs to be consistent
    wContent.setCacheKey("abcd{}<>");
    wContent.handleRequest(request);
    String xml = render(wContent);
    Assert.assertEquals("Should not have painted any content", "", xml);
    // Should produce mark-up when displayed
    wContent.handleRequest(request);
    wContent.display();
    assertSchemaMatch(wContent);
    // Display again (as reset after paint)
    wContent.display();
    assertXpathUrlEvaluatesTo(wContent.getUrl(), "//ui:popup/@url", wContent);
    // Display again (as reset after paint)
    wContent.display();
    assertXpathNotExists("ui:redirect", wContent);
    // Test all options
    String width = "111";
    String height = "222";
    wContent.setWidth(width);
    wContent.setHeight(height);
    wContent.setResizable(true);
    wContent.setDisplayMode(WContent.DisplayMode.PROMPT_TO_SAVE);
    assertSchemaMatch(wContent);
    // Display again (as reset after paint)
    wContent.display();
    assertXpathNotExists("//ui:popup", wContent);
    // Display again (as reset after paint)
    wContent.display();
    assertXpathUrlEvaluatesTo(wContent.getUrl(), "//ui:redirect/@url", wContent);
    // Test null content
    wContent.setContentAccess(null);
    xml = render(wContent);
    Assert.assertEquals("Should not have painted any content", "", xml);
}
Also used : MockContentAccess(com.github.bordertech.wcomponents.MockContentAccess) WContent(com.github.bordertech.wcomponents.WContent) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

MockContentAccess (com.github.bordertech.wcomponents.MockContentAccess)1 WContent (com.github.bordertech.wcomponents.WContent)1 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1 Test (org.junit.Test)1