Search in sources :

Example 6 with UIContextImpl

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

the class SessionTokenInterceptor_Test method setUp.

@Before
public void setUp() {
    component = new MyBackingComponent();
    interceptor = new SessionTokenInterceptor();
    interceptor.setBackingComponent(component);
    uic = new UIContextImpl();
    uic.setUI(component);
    uic.setEnvironment(new MockWEnvironment());
    setActiveContext(uic);
    request = new MockRequest();
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Before(org.junit.Before)

Example 7 with UIContextImpl

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

the class TargetableInterceptor_Test method setUp.

@Before
public void setUp() {
    UIContext uic = new UIContextImpl();
    WPanel root = new WPanel();
    originalUI = new WLabel();
    targetUI = new TargetableWLabel();
    root.add(originalUI);
    root.add(targetUI);
    uic.setUI(root);
    setActiveContext(uic);
    interceptor = new TargetableInterceptor();
    interceptor.setBackingComponent(originalUI);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WPanel(com.github.bordertech.wcomponents.WPanel) WLabel(com.github.bordertech.wcomponents.WLabel) Before(org.junit.Before)

Example 8 with UIContextImpl

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

the class WrongStepServerInterceptor_Test method setUp.

@Before
public void setUp() {
    component = new MyBackingComponent();
    interceptor = new WrongStepServerInterceptor();
    interceptor.setBackingComponent(component);
    uic = new UIContextImpl();
    uic.setUI(component);
    uic.setEnvironment(new MockWEnvironment());
    setActiveContext(uic);
    request = new MockRequest();
    // Default to GET method
    request.setMethod("GET");
    originalConfig = Config.getInstance();
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Before(org.junit.Before)

Example 9 with UIContextImpl

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

the class ProfileContainer_Test method testAfterPaint.

/**
 * Test afterPaint.
 */
@Test
public void testAfterPaint() {
    ProfileContainer app = new ProfileContainer();
    app.setLocked(true);
    UIContext uic = new UIContextImpl();
    uic.setUI(app);
    setActiveContext(uic);
    WButton button = new WButton("PUSH");
    app.add(button);
    WLabel label = new WLabel("HERE");
    app.add(label);
    StringWriter outStr = new StringWriter();
    PrintWriter writer = new PrintWriter(outStr);
    RenderContext renderContext = new WebXmlRenderContext(writer);
    app.afterPaint(renderContext);
    // expecting 1 root class, 3 components, class names as shown, profiler
    // class
    String profileLine0 = PROFILER_UIC_HEADER;
    String profileLine1 = PROFILER_LINE1.replaceAll("<<NUM_ROOTS>>", "1");
    String profileLine2 = PROFILER_LINE2.replaceAll("<<NUM_COMPONENTS>>", "4");
    String profileLine31 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
    String profileLine32 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String profileLine33 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
    String profileLine4 = PROFILER_PROFILE_HEADER.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String[] expectedResults = { profileLine0, profileLine1, profileLine2, profileLine31, profileLine32, profileLine33, profileLine4 };
    String result = outStr.toString();
    for (int i = 0; i < expectedResults.length; i++) {
        Assert.assertTrue("result should contain substring " + i + "  ", result.indexOf(expectedResults[i]) != -1);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 10 with UIContextImpl

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

the class UicStatsAsHtml_Test method testWriter.

/**
 * Test writer.
 */
@Test
public void testWriter() {
    // Set up a mock UI to test
    WApplication app = new WApplication();
    app.setLocked(true);
    UIContext uic = new UIContextImpl();
    uic.setUI(app);
    setActiveContext(uic);
    WButton button = new WButton("PUSH");
    app.add(button);
    WLabel label = new WLabel("HERE");
    app.add(label);
    // Run the UIStats extract
    UicStats stats = new UicStats(uic);
    stats.analyseWC(app);
    StringWriter outStr = new StringWriter();
    PrintWriter writer = new PrintWriter(outStr);
    UicStatsAsHtml.write(writer, stats);
    // expecting 1 root class, 3 components, class names as shown
    String uicStatsHtml1 = UICSTATS_HTML1.replaceAll("<<NUM_ROOTS>>", "1");
    String uicStatsHtml2 = UICSTATS_HTML2.replaceAll("<<NUM_COMPONENTS>>", "4");
    String uicStatsHtml31 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WApplication");
    String uicStatsHtml32 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
    String uicStatsHtml33 = UICSTATS_HTML3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
    String[] expectedResults = { uicStatsHtml1, uicStatsHtml2, uicStatsHtml31, uicStatsHtml32, uicStatsHtml33 };
    String result = outStr.toString();
    for (int i = 0; i < expectedResults.length; i++) {
        Assert.assertTrue("result should contain substring " + i + "  ", result.indexOf(expectedResults[i]) != -1);
    }
}
Also used : StringWriter(java.io.StringWriter) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)17 UIContext (com.github.bordertech.wcomponents.UIContext)11 Test (org.junit.Test)7 Before (org.junit.Before)6 WLabel (com.github.bordertech.wcomponents.WLabel)5 WTextField (com.github.bordertech.wcomponents.WTextField)4 PrintWriter (java.io.PrintWriter)4 WApplication (com.github.bordertech.wcomponents.WApplication)3 WButton (com.github.bordertech.wcomponents.WButton)3 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)2 RenderContext (com.github.bordertech.wcomponents.RenderContext)2 WText (com.github.bordertech.wcomponents.WText)2 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)2 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 FatalErrorPage (com.github.bordertech.wcomponents.FatalErrorPage)1 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)1