use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class DataListInterceptor_Test method testInterecptor.
@Test
public void testInterecptor() throws XpathException, SAXException, IOException {
String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE;
// Create interceptor
DataListInterceptor interceptor = new DataListInterceptor();
interceptor.attachUI(new DefaultWComponent());
// Action phase
MockRequest request = new MockRequest();
request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey);
interceptor.serviceRequest(request);
// Render phase
MockResponse response = new MockResponse();
interceptor.attachResponse(response);
interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter())));
String xml = response.getWriterOutput();
// Ensure that the data matches the test table.
List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory.newInstance(LookupTable.class).getTable(tableKey);
assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml);
for (int i = 0; i < table.size(); i++) {
assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
}
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AjaxErrorInterceptor_Test method testHandleActionAjaxError.
@Test
public void testHandleActionAjaxError() throws IOException {
final AjaxTriggerException excp = new AjaxTriggerException("Simulate ajax trigger error");
// Throw trigger exception in chain
InterceptorComponent chain = new InterceptorComponent() {
@Override
public void serviceRequest(final Request request) {
throw excp;
}
};
// Setup interceptor
AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
ajax.setBackingComponent(chain);
// Process Action
try {
ajax.serviceRequest(new MockRequest());
Assert.fail("Trigger exception not handled correctly");
} catch (ErrorCodeEscape e) {
Assert.assertTrue("Incorrect trigger exception message", e.getMessage().contains(AJAX_ERROR));
Assert.assertEquals("Incorrect escape code for trigger exception", HttpServletResponse.SC_BAD_REQUEST, e.getCode());
Assert.assertEquals("Cause should be the original trigger exception", excp, e.getCause());
}
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AjaxErrorInterceptor_Test method testHandleActionSessionToken.
@Test
public void testHandleActionSessionToken() throws IOException {
final SessionTokenException excp = new SessionTokenException("Simulate session error");
// Throw session exception in chain
InterceptorComponent chain = new InterceptorComponent() {
@Override
public void serviceRequest(final Request request) {
throw excp;
}
};
// Setup interceptor
AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
ajax.setBackingComponent(chain);
// Process Action
try {
ajax.serviceRequest(new MockRequest());
Assert.fail("Session exception not handled correctly");
} catch (ErrorCodeEscape e) {
Assert.assertTrue("Incorrect session exception message", e.getMessage().contains(SESSION_ERROR));
Assert.assertEquals("Incorrect escape code for session exception", HttpServletResponse.SC_BAD_REQUEST, e.getCode());
Assert.assertEquals("Cause should be the original session exception", excp, e.getCause());
}
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AjaxErrorInterceptor_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
AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
ajax.setBackingComponent(chain);
// Process Action
ajax.serviceRequest(new MockRequest());
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class AjaxSetupInterceptor_Test method testTriggerIdValid.
@Test
public void testTriggerIdValid() throws IOException {
// Setup App
MyApp app = setupApp();
// Setup request
MockRequest request = setupRequest(app);
// Do Service Request
doAjaxServiceRequest(app, request);
}
Aggregations