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);
}
}
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());
}
}
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());
}
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());
}
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);
}
Aggregations