protected Flow createFlow() { String flowId = getContext().getFlowId(); AttributeMap<Object> flowAttributes = parseFlowMetaAttributes(flowModel); flowAttributes = getContext().getFlowAttributes().union(flowAttributes); if (IS_SPRING_FACES_PRESENT) { flowAttributes.asMap().put(VALIDATOR_FLOW_ATTR, getLocalContext().getValidator()); flowAttributes.asMap().put(VALIDATION_HINT_RESOLVER_FLOW_ATTR, getLocalContext().getValidationHintResolver()); } Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes); flow.setApplicationContext(getLocalContext().getApplicationContext()); return flow; }
protected Flow createFlow() { String flowId = getContext().getFlowId(); AttributeMap<Object> flowAttributes = parseFlowMetaAttributes(flowModel); flowAttributes = getContext().getFlowAttributes().union(flowAttributes); if (IS_SPRING_FACES_PRESENT) { flowAttributes.asMap().put(VALIDATOR_FLOW_ATTR, getLocalContext().getValidator()); flowAttributes.asMap().put(VALIDATION_HINT_RESOLVER_FLOW_ATTR, getLocalContext().getValidationHintResolver()); } Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes); flow.setApplicationContext(getLocalContext().getApplicationContext()); return flow; }
protected Flow createFlow() { String flowId = getContext().getFlowId(); AttributeMap flowAttributes = parseFlowMetaAttributes(flowModel); flowAttributes = getContext().getFlowAttributes().union(flowAttributes); Flow flow = getLocalContext().getFlowArtifactFactory().createFlow(flowId, flowAttributes); flow.setApplicationContext(getLocalContext().getApplicationContext()); return flow; }
public void testValidateWithErrorsForBeanValidatorOverridden() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("modelValidator", StubModelErrorsOverridden.class); ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext); ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, this.codesResolver, null); helper.validate(); MessageContext messages = requestContext.getMessageContext(); assertEquals(1, messages.getAllMessages().length); assertEquals(1, messages.getMessagesBySource("validationcontext-external").length); }
public void testValidateWithValidationContextForBeanValidator() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("modelValidator", StubModelValidationContext.class); ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext); ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, this.codesResolver, null); helper.validate(); MessageContext messages = requestContext.getMessageContext(); assertEquals(1, messages.getAllMessages().length); assertEquals(1, messages.getMessagesBySource("validationcontext-external").length); }
public void testValidateWithMessageContextForBeanValidator() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("modelValidator", StubModelMessageContext.class); ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext); ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, this.codesResolver, null); helper.validate(); MessageContext messages = requestContext.getMessageContext(); assertEquals(1, messages.getAllMessages().length); assertEquals(1, messages.getMessagesBySource("messagecontext-external").length); }
public void testValidateWithErrorsForBeanValidator() { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("modelValidator", StubModelErrors.class); ((Flow) requestContext.getActiveFlow()).setApplicationContext(applicationContext); ValidationHelper helper = new ValidationHelper(new Object(), requestContext, eventId, modelName, null, this.codesResolver, null); helper.validate(); MessageContext messages = requestContext.getMessageContext(); assertEquals(1, messages.getAllMessages().length); assertEquals(1, messages.getMessagesBySource("errors-external").length); }
public void testDestroy() { GenericApplicationContext context = new GenericApplicationContext(); context.refresh(); flow.setApplicationContext(context); assertTrue(context.isActive()); flow.destroy(); assertFalse(context.isActive()); }
public void testFlowResourceResolve() { ApplicationContext applicationContext = new StaticWebApplicationContext(); ((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext); Object actual = this.resolver.getValue(this.elContext, null, "resourceBundle"); assertTrue(this.elContext.isPropertyResolved()); assertNotNull(actual); assertSame(applicationContext, actual); }
public void testResolveSpringBean() { MockRequestContext context = new MockRequestContext(); StaticApplicationContext ac = new StaticApplicationContext(); ac.getBeanFactory().registerSingleton("testBean", new TestBean()); context.getRootFlow().setApplicationContext(ac); Expression exp = parser.parseExpression("testBean", new FluentParserContext().evaluate(RequestContext.class)); assertSame(ac.getBean("testBean"), exp.getValue(context)); }
public void testResolveAction() { MockRequestContext context = new MockRequestContext(); StaticApplicationContext ac = new StaticApplicationContext(); ac.getBeanFactory().registerSingleton("action", new TestAction()); context.getRootFlow().setApplicationContext(ac); Expression exp = parser.parseExpression("action", new FluentParserContext().evaluate(RequestContext.class)); assertSame(ac.getBean("action"), exp.getValue(context)); }
public void testBeanResolveWithRequestContext() { StaticWebApplicationContext applicationContext = new StaticWebApplicationContext(); ((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext); applicationContext.registerSingleton("test", Bean.class); Object actual = this.resolver.getValue(this.elContext, null, "test"); assertTrue(this.elContext.isPropertyResolved()); assertNotNull(actual); assertTrue(actual instanceof Bean); }
public void testGetValue_BaseVariable() { MockRequestContext requestContext = new MockRequestContext(); ((Flow) requestContext.getActiveFlow()).setApplicationContext(new StaticWebApplicationContext()); RequestContextHolder.setRequestContext(requestContext); assertTrue(getBaseVariable() + " should resolve to an instance of MessageSource", context.getELResolver() .getValue(context, null, getBaseVariable()) instanceof MessageSource); }
public void testResolveMultiAction() { MockRequestContext context = new MockRequestContext(); StaticApplicationContext ac = new StaticApplicationContext(); ac.getBeanFactory().registerSingleton("multiAction", new FormAction()); context.getRootFlow().setApplicationContext(ac); Expression exp = parser.parseExpression("multiAction.setupForm", new FluentParserContext().evaluate(RequestContext.class)); AnnotatedAction action = (AnnotatedAction) exp.getValue(context); assertSame(ac.getBean("multiAction"), action.getTargetAction()); assertEquals("setupForm", action.getMethod()); }
public void testStateAndFallbackLegacyValidatorInvoked() { LegacyModelValidator validator = new LegacyModelValidator(); StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getBeanFactory().registerSingleton("modelValidator", validator); requestContext.getRootFlow().setApplicationContext(applicationContext); Model model = new Model(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertTrue(validator.state1Invoked); assertTrue(validator.fallbackInvoked); }
public void testStateAndFallbackErrorsValidatorInvoked() { ErrorsModelValidator validator = new ErrorsModelValidator(); StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getBeanFactory().registerSingleton("modelValidator", validator); requestContext.getRootFlow().setApplicationContext(applicationContext); Model model = new Model(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertTrue(validator.state1Invoked); assertTrue(validator.fallbackInvoked); }
public void testStateAndFallbackValidatorInvokedForSubclass() { ModelValidator validator = new ModelValidator(); StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getBeanFactory().registerSingleton("modelValidator", validator); requestContext.getRootFlow().setApplicationContext(applicationContext); ExtendedModel model = new ExtendedModel(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state1", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertTrue(validator.state1Invoked); assertTrue(validator.fallbackInvoked); }
public void testFallbackErrorsValidatorInvokedForSubclass() { ErrorsModelValidator validator = new ErrorsModelValidator(); StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.getBeanFactory().registerSingleton("modelValidator", validator); requestContext.getRootFlow().setApplicationContext(applicationContext); Model model = new Model(); ValidationHelper helper = new ValidationHelper(model, requestContext, eventId, modelName, null, this.codesResolver, null); ViewState state1 = new ViewState(requestContext.getRootFlow(), "state2", new StubViewFactory()); requestContext.setCurrentState(state1); helper.validate(); assertFalse(validator.state1Invoked); assertTrue(validator.fallbackInvoked); }
public void testResourceBundle() throws Exception { Flow flow = (Flow) requestContext.getActiveFlow(); flow.setApplicationContext(new StaticApplicationContext()); assertTrue(accessor.canRead(null, null, "resourceBundle")); assertNotNull(accessor.read(null, null, "resourceBundle").getValue()); assertEquals(requestContext.getActiveFlow().getApplicationContext(), accessor .read(null, null, "resourceBundle").getValue()); }
public void testResolveMessage() { MockRequestContext context = new MockRequestContext(); StaticApplicationContext ac = new StaticApplicationContext(); ac.getStaticMessageSource().addMessage("foo", Locale.FRANCE, "bar"); ac.refresh(); context.getRootFlow().setApplicationContext(ac); context.getMockExternalContext().setLocale(Locale.FRANCE); Expression exp = parser.parseExpression("resourceBundle.foo", new FluentParserContext().evaluate(RequestContext.class)); assertEquals("bar", exp.getValue(context)); } }