Search in sources :

Example 96 with MockRequest

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

the class SessionTokenInterceptor_Test method testServiceRequestIncorrectToken.

@Test
public void testServiceRequestIncorrectToken() {
    // Setup interceptor
    SessionTokenInterceptor interceptor = setupInterceptor();
    MyBackingComponent component = (MyBackingComponent) interceptor.getBackingComponent();
    UIContext uic = UIContextHolder.getCurrent();
    MockRequest request = new MockRequest();
    // Setup tokens that dont match on session and request
    uic.getEnvironment().setSessionToken("X");
    request.setParameter(Environment.SESSION_TOKEN_VARIABLE, "Y");
    try {
        // Process request
        interceptor.serviceRequest(request);
        Assert.fail("Should have thrown an excpetion for incorrect token");
    } catch (SessionTokenException e) {
        Assert.assertFalse("Action phase should not have occurred for token error", component.handleRequestCalled);
    }
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 97 with MockRequest

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

the class SessionTokenInterceptor_Test method testSessionTimeout.

@Test
public void testSessionTimeout() {
    // Setup interceptor
    SessionTokenInterceptor interceptor = setupInterceptor();
    MyBackingComponent component = (MyBackingComponent) interceptor.getBackingComponent();
    UIContext uic = UIContextHolder.getCurrent();
    MockRequest request = new MockRequest();
    // Simulate request parameter from previous session (new session has null token)
    request.setParameter(Environment.SESSION_TOKEN_VARIABLE, "X");
    try {
        // Process request
        interceptor.serviceRequest(request);
        Assert.fail("Should have thrown an excpetion for incorrect token");
    } catch (SessionTokenException e) {
        Assert.assertFalse("Action phase should not have occurred for session timeout", component.handleRequestCalled);
        Assert.assertEquals("Step count should not have been incremented for session timeout", 0, uic.getEnvironment().getStep());
    }
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 98 with MockRequest

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

the class TargetableErrorInterceptor_Test method testHandleActionEscape.

@Test(expected = Escape.class)
public void testHandleActionEscape() throws IOException {
    // Throw escape exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void serviceRequest(final Request request) {
            throw new Escape();
        }
    };
    // Setup interceptor
    TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
    interceptor.setBackingComponent(chain);
    // Process Action
    interceptor.serviceRequest(new MockRequest());
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 99 with MockRequest

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

the class TargetableErrorInterceptor_Test method testHandlePreparePaintEscape.

@Test(expected = Escape.class)
public void testHandlePreparePaintEscape() throws IOException {
    // Throw escape exception in chain
    InterceptorComponent chain = new InterceptorComponent() {

        @Override
        public void preparePaint(final Request request) {
            throw new Escape();
        }
    };
    // Setup interceptor
    TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
    interceptor.setBackingComponent(chain);
    // Prepare paint
    interceptor.preparePaint(new MockRequest());
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 100 with MockRequest

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

the class TargetableErrorInterceptor_Test method testNoErrors.

@Test
public void testNoErrors() {
    // Setup interceptor
    MyBackingComponent component = new MyBackingComponent();
    TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
    interceptor.setBackingComponent(component);
    MockRequest request = new MockRequest();
    // Process request
    interceptor.serviceRequest(request);
    interceptor.preparePaint(request);
    Assert.assertTrue("Handle request not called", component.handleRequestCalled);
    Assert.assertTrue("Prepare paint not called", component.preparePaintCalled);
}
Also used : 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