Search in sources :

Example 1 with MockWEnvironment

use of com.github.bordertech.wcomponents.MockWEnvironment 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 2 with MockWEnvironment

use of com.github.bordertech.wcomponents.MockWEnvironment 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 3 with MockWEnvironment

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

the class WApplicationRenderer_Test method testRenderedFormatWithHiddenFields.

@Test
public void testRenderedFormatWithHiddenFields() throws XpathException, IOException, SAXException {
    MockWEnvironment environment = new MockWEnvironment();
    environment.setPostPath("WApplicationRendererTest.postPath");
    WApplication application = new WApplication();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    uic.setUI(application);
    setActiveContext(uic);
    WLabel label = new WLabel("dummy");
    application.add(label);
    Map<String, String> hiddenParameters = new HashMap<>();
    hiddenParameters.put("keyA", "valueA");
    hiddenParameters.put("keyB", "valueB");
    environment.setHiddenParameters(hiddenParameters);
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(label.getText(), "normalize-space(//ui:application/ui:label)", application);
    assertXpathEvaluatesTo("valueA", "//ui:application/ui:param[@name='keyA']/@value", application);
    assertXpathEvaluatesTo("valueB", "//ui:application/ui:param[@name='keyB']/@value", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) HashMap(java.util.HashMap) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 4 with MockWEnvironment

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

the class WApplicationRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WApplication application = new WApplication();
    MockWEnvironment environment = new MockWEnvironment();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    setActiveContext(uic);
    // Test with no unsavedChanges
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo("", "//ui:application/@unsavedChanges", application);
    // Test with unsavedChanges
    application.setUnsavedChanges(true);
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 5 with MockWEnvironment

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

the class WApplicationRenderer_Test method testDoPaintWithChildren.

@Test
public void testDoPaintWithChildren() throws IOException, SAXException, XpathException {
    WApplication application = new WApplication();
    WText text = new WText("test text");
    WButton button = new WButton("button");
    application.add(text);
    application.add(button);
    MockWEnvironment environment = new MockWEnvironment();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    setActiveContext(uic);
    application.setUnsavedChanges(true);
    // Check Schema
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
    // Check Children
    assertXpathEvaluatesTo("test text", "normalize-space(//ui:application/text()[1])", application);
    assertXpathEvaluatesTo("1", "count(//ui:application/html:button)", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)8 UIContext (com.github.bordertech.wcomponents.UIContext)6 WApplication (com.github.bordertech.wcomponents.WApplication)6 Test (org.junit.Test)6 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Before (org.junit.Before)2 WButton (com.github.bordertech.wcomponents.WButton)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WText (com.github.bordertech.wcomponents.WText)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 HashMap (java.util.HashMap)1