Search in sources :

Example 91 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class TargetableInterceptor_Test method testServiceRequestWithTarget.

@Test
public void testServiceRequestWithTarget() {
    // Setup interceptor
    MyApp root = new MyApp();
    TargetableInterceptor interceptor = new TargetableInterceptor();
    interceptor.attachUI(root);
    UIContextHolder.getCurrent().setUI(root);
    // UI should change when a target is present in a request
    MockRequest request = new MockRequest();
    request.setParameter(Environment.TARGET_ID, root.targetUI.getId());
    // Check UI
    Assert.assertSame("Incorrect UI returned", root, interceptor.getUI());
    // Process Request
    interceptor.serviceRequest(request);
    // UI should be the target
    Assert.assertSame("Incorrect new UI after serviceRequest with a target set", root.targetUI, interceptor.getUI());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 92 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class TargetableInterceptor_Test method testServiceRequestInvalidTarget.

@Test(expected = TargetableIdException.class)
public void testServiceRequestInvalidTarget() {
    // Setup interceptor
    MyApp root = new MyApp();
    TargetableInterceptor interceptor = new TargetableInterceptor();
    interceptor.setBackingComponent(root);
    UIContextHolder.getCurrent().setUI(root);
    // Invalid Target ID on request
    MockRequest request = new MockRequest();
    request.setParameter(Environment.TARGET_ID, "X-BAD");
    // Process request
    interceptor.serviceRequest(request);
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 93 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class TargetableInterceptor_Test method testServiceRequestNoTarget.

@Test(expected = SystemException.class)
public void testServiceRequestNoTarget() {
    MyApp root = new MyApp();
    TargetableInterceptor interceptor = new TargetableInterceptor();
    interceptor.attachUI(root);
    interceptor.serviceRequest(new MockRequest());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 94 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class TargetableInterceptor_Test method testServiceRequestInvisibleTarget.

@Test(expected = TargetableIdException.class)
public void testServiceRequestInvisibleTarget() {
    // Setup interceptor
    MyApp root = new MyApp();
    TargetableInterceptor interceptor = new TargetableInterceptor();
    interceptor.setBackingComponent(root);
    UIContextHolder.getCurrent().setUI(root);
    // Setup request
    MockRequest request = new MockRequest();
    request.setParameter(Environment.TARGET_ID, root.targetUI.getId());
    // Make target invisible
    root.targetUI.setVisible(false);
    // Process request
    interceptor.serviceRequest(request);
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 95 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class SessionTokenInterceptor_Test method testServiceRequestCorrectToken.

@Test
public void testServiceRequestCorrectToken() {
    // Setup interceptor
    SessionTokenInterceptor interceptor = setupInterceptor();
    MyBackingComponent component = (MyBackingComponent) interceptor.getBackingComponent();
    UIContext uic = UIContextHolder.getCurrent();
    MockRequest request = new MockRequest();
    // Setup matching tokens on session and request
    uic.getEnvironment().setSessionToken("X");
    request.setParameter(Environment.SESSION_TOKEN_VARIABLE, "X");
    // Process request
    interceptor.serviceRequest(request);
    Assert.assertTrue("Action phase should have occurred for corret token", component.handleRequestCalled);
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)250 Test (org.junit.Test)216 UIContext (com.github.bordertech.wcomponents.UIContext)22 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)16 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)13 PrintWriter (java.io.PrintWriter)13 Request (com.github.bordertech.wcomponents.Request)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 StringWriter (java.io.StringWriter)7 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)6 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 BigDecimal (java.math.BigDecimal)5 Escape (com.github.bordertech.wcomponents.Escape)4 WTextField (com.github.bordertech.wcomponents.WTextField)4 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3