/** * Increments the step that is recorded in session. * * @param uic the current user's session */ public static void incrementSessionStep(final UIContext uic) { int step = uic.getEnvironment().getStep(); uic.getEnvironment().setStep(step + 1); }
@Override public void serviceRequest(final Request request) { Environment env = UIContextHolder.getCurrent().getEnvironment(); env.setStep(env.getStep() + 1); }
@Override public void preparePaint(final Request request) { Environment env = UIContextHolder.getCurrent().getEnvironment(); env.setStep(env.getStep() + 1); }
@Test public void testServiceRequestIncorrectSequence() { uic.getEnvironment().setStep(3); request.setParameter(Environment.STEP_VARIABLE, "1"); interceptor.serviceRequest(request); Assert.assertTrue("Handle Step Error should have been called for step error", component.handleStepErrorCalled); Assert.assertFalse("Action phase should not have occurred for step error", component.handleRequestCalled); Assert.assertEquals("Step should not have been incremented", 3, uic.getEnvironment(). getStep()); interceptor.preparePaint(request); Assert.assertEquals("Step should have been incremented", 4, uic.getEnvironment().getStep()); }
@Override public void paint(final RenderContext renderContext) { Environment env = UIContextHolder.getCurrent().getEnvironment(); env.setStep(env.getStep() + 1); hiddenParams = env.getHiddenParameters(); } }
@Test public void testServiceRequestCorrectSequence() { uic.getEnvironment().setStep(3); request.setParameter(Environment.STEP_VARIABLE, "3"); interceptor.serviceRequest(request); Assert.assertTrue("Action phase should have occurred for no step error", component.handleRequestCalled); Assert.assertEquals("Step should not have been incremented", 3, uic.getEnvironment(). getStep()); interceptor.preparePaint(request); Assert.assertEquals("Step should have been incremented", 4, uic.getEnvironment().getStep()); }
@Test public void testServiceRequestIncorrectToken() { uic.getEnvironment().setSessionToken("X"); uic.getEnvironment().setStep(10); request.setParameter(Environment.SESSION_TOKEN_VARIABLE, "Y"); try { interceptor.serviceRequest(request); Assert.fail("Should have thrown an excpetion for incorrect token"); } catch (SystemException e) { Assert.assertFalse("Action phase should not have occurred for token error", component.handleRequestCalled); Assert.assertEquals("Step count should not have been incremented for token error", 10, uic.getEnvironment() .getStep()); } }
@Test public void testServiceRequestCorrectToken() { uic.getEnvironment().setSessionToken("X"); uic.getEnvironment().setStep(10); request.setParameter(Environment.SESSION_TOKEN_VARIABLE, "X"); interceptor.serviceRequest(request); Assert.assertTrue("Action phase should have occurred for corret token", component.handleRequestCalled); Assert.assertEquals("Step count should not have been incremented for correct token", 10, uic.getEnvironment() .getStep()); }
@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()); } }
uic1.setUI(ui); uic1.getEnvironment().setSessionToken("1"); uic1.getEnvironment().setStep(1);