Search in sources :

Example 31 with MockResponse

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

the class WrongStepContentInterceptor_Test method testErrorDirectContent.

@Test
public void testErrorDirectContent() {
    Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, "http://test.test");
    MyApp app = new MyApp();
    app.setLocked(true);
    MockResponse response = sendContentRequest(app.appContent, 1, 99);
    Assert.assertEquals("Should have returned error", HttpServletResponse.SC_BAD_REQUEST, response.getErrorCode());
}
Also used : MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) Test(org.junit.Test)

Example 32 with MockResponse

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

the class WrongStepServerInterceptor_Test method testServiceRequestIncorrectSequenceWithRedirect.

@Test
public void testServiceRequestIncorrectSequenceWithRedirect() {
    // Set redirect parameter
    Configuration config = Config.copyConfiguration(originalConfig);
    config.addProperty(ConfigurationProperties.STEP_ERROR_URL, "test.url");
    Config.setConfiguration(config);
    uic.getEnvironment().setStep(3);
    request.setParameter(Environment.STEP_VARIABLE, "1");
    interceptor.attachResponse(new MockResponse());
    try {
        interceptor.serviceRequest(request);
        Assert.fail("Interceptor did not detect wrong step");
    } catch (ActionEscape e) {
        Assert.assertFalse("Action phase should not have occurred for step error with redirect", component.handleRequestCalled);
        Assert.assertFalse("Handle Step Error should not have occurred for redirect", component.handleStepErrorCalled);
        Assert.assertEquals("Step should not have been incremented", 3, uic.getEnvironment().getStep());
    }
}
Also used : MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) Configuration(org.apache.commons.configuration.Configuration) Test(org.junit.Test)

Aggregations

MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)32 Test (org.junit.Test)23 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)17 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)15 PrintWriter (java.io.PrintWriter)7 UIContext (com.github.bordertech.wcomponents.UIContext)6 WText (com.github.bordertech.wcomponents.WText)6 Configuration (org.apache.commons.configuration.Configuration)5 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)4 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 InterceptorComponent (com.github.bordertech.wcomponents.container.InterceptorComponent)3 StringWriter (java.io.StringWriter)3 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)2 ServletRequest (com.github.bordertech.wcomponents.servlet.ServletRequest)2 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)2 List (java.util.List)2 Locale (java.util.Locale)2 ContentEscape (com.github.bordertech.wcomponents.ContentEscape)1