public void testResumeEventNoModelInScope() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "5"); context.putRequestParameter("dateProperty", "2007-01-01"); context.putRequestParameter("beanProperty.name", "foo"); context.putRequestParameter("multipartFile", new MockMultipartFile("foo", new byte[0])); context.putRequestParameter("stringArrayProperty", new String[] { "foo", "bar", "baz" }); context.putRequestParameter("integerArrayProperty", new String[] { "1", "2", "3" }); context.putRequestParameter("primitiveArrayProperty", new String[] { "1", "2", "3" }); context.putRequestParameter("listProperty", new String[] { "1", "2", "3" }); Expression modelObject = new Expression() { public String getExpressionString() {
public void testResumeEventModelValidateOnBindingErrors() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "bogus"); context.putRequestParameter("dateProperty", "2007-01-01"); BindBean bindBean = new ValidatingBindBean(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); view.setMessageCodesResolver(new WebFlowMessageCodesResolver()); view.processUserEvent(); assertFalse(view.hasFlowEvent()); assertTrue(bindBean.validationMethodInvoked); }
public void testResumeEventModelBindingAllowedFields() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "5"); context.putRequestParameter("dateProperty", "2007-01-01"); context.putRequestParameter("beanProperty.name", "foo"); BindBean bindBean = new BindBean(); StaticExpression modelObject = new StaticExpression(bindBean);
public void testResumeEventModelBinding() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "5"); context.putRequestParameter("dateProperty", "2007-01-01"); context.putRequestParameter("beanProperty.name", "foo"); context.putRequestParameter("multipartFile", new MockMultipartFile("foo", new byte[0])); context.putRequestParameter("stringArrayProperty", new String[] { "foo", "bar", "baz" }); context.putRequestParameter("integerArrayProperty", new String[] { "1", "2", "3" }); context.putRequestParameter("primitiveArrayProperty", new String[] { "1", "2", "3" }); context.putRequestParameter("listProperty", new String[] { "1", "2", "3" }); BindBean bindBean = new BindBean(); StaticExpression modelObject = new StaticExpression(bindBean);
public void testResumeEventModelNoValidateOnBindingErrors() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "bogus"); context.putRequestParameter("dateProperty", "2007-01-01"); BindBean bindBean = new ValidatingBindBean(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getMockFlowExecutionContext().putAttribute("validateOnBindingErrors", false); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); view.setMessageCodesResolver(new WebFlowMessageCodesResolver()); view.processUserEvent(); assertFalse(view.hasFlowEvent()); assertFalse(bindBean.validationMethodInvoked); }
public void testResumeEventModelBindAndValidateDefaultValidatorFallback() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "5"); context.putRequestParameter("dateProperty", "2007-01-01"); BindBean bindBean = new ValidatingBindBeanFallback(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); assertTrue(view.userEventQueued()); view.processUserEvent(); assertFalse(view.userEventQueued()); assertTrue(view.hasFlowEvent()); assertEquals("submit", view.getFlowEvent().getId()); assertTrue(bindBean.validationMethodInvoked); }
public void testFormActionWithValidatorAndNoFormActionClass() throws Exception { FormAction action = new FormAction() { protected Object createFormObject(RequestContext context) throws Exception { return new TestBean(); } }; action.setValidator(new TestBeanValidator()); action.initAction(); MockRequestContext context = new MockRequestContext(); Event result = action.setupForm(context); assertEquals("success", result.getId()); context.putRequestParameter("prop", "foo"); context.getAttributeMap().put("validatorMethod", "validateTestBean"); result = action.bindAndValidate(context); }
public void testResumeEventModelBindAndValidate() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("stringProperty", "foo"); context.putRequestParameter("integerProperty", "5"); context.putRequestParameter("dateProperty", "2007-01-01"); BindBean bindBean = new ValidatingBindBean(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); assertTrue(view.userEventQueued()); view.processUserEvent(); assertFalse(view.userEventQueued()); assertTrue(view.hasFlowEvent()); assertEquals("submit", view.getFlowEvent().getId()); assertTrue(bindBean.validationMethodInvoked); }
public void testResumeEventModelBindingFieldMarkerFieldPresent() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("booleanProperty", "true"); context.putRequestParameter("_booleanProperty", "whatever"); BindBean bindBean = new BindBean(); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); assertTrue(view.userEventQueued()); view.processUserEvent(); assertFalse(view.userEventQueued()); assertEquals(true, bindBean.getBooleanProperty()); }
public void testResumeEventModelBindingCustomConverter() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("dateProperty", "01-01-2007"); BindBean bindBean = new BindBean(); StaticExpression modelObject = new StaticExpression(bindBean);
public void testProcessUserEvent() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId", "foo"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
public void testProcessUserEventButton() throws IOException { TestAction action = new TestAction(); ActionExecutingViewFactory factory = new ActionExecutingViewFactory(action); MockRequestContext context = new MockRequestContext(); View view = factory.getView(context); assertFalse(action.isExecuted()); view.render(); assertTrue(action.isExecuted()); context.putRequestParameter("_eventId_foo", "doesn't matter"); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("foo", view.getFlowEvent().getId()); }
context.putRequestParameter("prop", "1"); context.putRequestParameter("otherProp", "value"); context.setAttribute("method", "bind"); formAction.execute(context);
public void testResumeEventModelBindingFieldMarker() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.putRequestParameter("_booleanProperty", "whatever"); BindBean bindBean = new BindBean(); bindBean.setBooleanProperty(true); StaticExpression modelObject = new StaticExpression(bindBean); modelObject.setExpressionString("bindBean"); context.getCurrentState().getAttributes().put("model", modelObject); context.getFlowScope().put("bindBean", bindBean); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setExpressionParser(createExpressionParser()); view.processUserEvent(); assertEquals(false, bindBean.getBooleanProperty()); }
public void testSetupFormThenBindAndValidate() throws Exception { FormAction action = createFormAction("testBean"); MockRequestContext context = new MockRequestContext(); Event result = action.setupForm(context); assertEquals("success", result.getId()); Object formObject = action.getFormObject(context); assertSame(formObject, action.getFormObject(context)); assertTrue(formObject instanceof TestBean); context.putRequestParameter("prop", "foo"); context.getAttributeMap().put("validatorMethod", "validateTestBean"); result = action.bindAndValidate(context); assertEquals("success", result.getId()); assertSame(formObject, action.getFormObject(context)); assertEquals(true, ((TestBeanValidator) action.getValidator()).invoked); }
public void testResumeEventNoModelBinding() { MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); assertTrue(view.userEventQueued()); view.processUserEvent(); assertTrue(view.hasFlowEvent()); assertEquals("submit", view.getFlowEvent().getId()); }
public void testResumeEventObjectArrayValidationHint() { StubSmartValidator validator = new StubSmartValidator(); MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); TestModel testModel = new TestModel(); Object[] validationHints = new Object[] { TestModel.State1.class }; StaticExpression validationHintsExpression = new StaticExpression(validationHints); context.getCurrentState().getAttributes().put("validationHints", validationHintsExpression); StaticExpression modelExpression = new StaticExpression(testModel); modelExpression.setExpressionString("testModel"); context.getCurrentState().getAttributes().put("model", modelExpression); context.getFlowScope().put("testModel", testModel); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setValidator(validator); view.setExpressionParser(createExpressionParser()); view.processUserEvent(); assertFalse(view.userEventQueued()); assertTrue(view.hasFlowEvent()); assertEquals("submit", view.getFlowEvent().getId()); assertEquals(validationHints, validator.hints); assertTrue(validator.invoked); }
public void testResumeEventStringValidationHint() { StubSmartValidator validator = new StubSmartValidator(); MockRequestContext context = new MockRequestContext(); context.putRequestParameter("_eventId", "submit"); TestModel testModel = new TestModel(); StaticExpression validationHintsExpression = new StaticExpression("State1,AllStates"); context.getCurrentState().getAttributes().put("validationHints", validationHintsExpression); StaticExpression modelExpression = new StaticExpression(testModel); modelExpression.setExpressionString("testModel"); context.getCurrentState().getAttributes().put("model", modelExpression); context.getFlowScope().put("testModel", testModel); context.getMockExternalContext().setNativeContext(new MockServletContext()); context.getMockExternalContext().setNativeRequest(new MockHttpServletRequest()); context.getMockExternalContext().setNativeResponse(new MockHttpServletResponse()); context.getMockFlowExecutionContext().setKey(new MockFlowExecutionKey("c1v1")); org.springframework.web.servlet.View mvcView = new MockView(); AbstractMvcView view = new MockMvcView(mvcView, context); view.setValidator(validator); view.setExpressionParser(createExpressionParser()); view.processUserEvent(); assertFalse(view.userEventQueued()); assertTrue(view.hasFlowEvent()); assertEquals("submit", view.getFlowEvent().getId()); assertEquals(TestModel.State1.class, validator.hints[0]); assertEquals(TestModel.AllStates.class, validator.hints[1]); assertTrue(validator.invoked); }