Hi,

I had a look into https://issues.apache.org/jira/browse/EXTVAL-4, which is 
about testing ExtVal itself using Shale.

Adopting this for testing my own custom ExtVal contraints using Myfaces Test 
1.0.0 doesn't work, it seems ExtVal and the mock value expressions do not work 
together. Or am I missing something?

Thanks,
Tom

---

public class CustomCrossValidationsTest extends 
AbstractJsfConfigurableMockTestCase {

        // simple class with 2 string properties
        private DummyDialogDaten daten;

        private HtmlInputText input1;
        private HtmlInputText input2;

        @Override
        protected void setUpRenderKit() throws Exception {

                RenderKitFactory renderKitFactory = (RenderKitFactory) 
FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
                renderKit = new ExtValRenderKit(new MockRenderKit());
                
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, 
renderKit);

                Renderer renderer = new TextRenderer();
                renderKit.addRenderer("javax.faces.Input", "javax.faces.Text", 
renderer);
        }

        @Before
        @Override
        public void setUp() throws Exception {

                super.setUp();

                lifecycle.addPhaseListener(new BeanValidationStartupListener());
                lifecycle.addPhaseListener(new 
PropertyValidationModuleStartupListener());
                lifecycle.addPhaseListener(new ExtValStartupListener());

                daten = new DummyDialogDaten();

                HtmlForm form = new HtmlForm();
                form.setId("form");
                facesContext.getViewRoot().getChildren().add(form);
                input1 = new HtmlInputText();
                input1.setId("input1");
                input1.addValidator(new BeanValidator());
                form.getChildren().add(input1);
                input2 = new HtmlInputText();
                input2.setId("input2");
                input1.addValidator(new BeanValidator());
                form.getChildren().add(input2);
        }

        @Override
        public void tearDown() throws Exception {
                super.tearDown();
                daten = null;
                input1 = null;
                input2 = null;
        }

        @Test
        public void test() {

                
facesContext.getExternalContext().getRequestMap().put("testBean", daten);

                // Startup-Listener ausfuehren
                lifecycle.execute(facesContext);

                ValueExpression exp = 
createValueExpression("#{testBean.string1}");
                input1.setValueExpression("value", exp);

                exp = createValueExpression("#{testBean.string2}");
                input2.setValueExpression("value", exp);

                input1.setSubmittedValue("");
                input2.setSubmittedValue("");

                // validate
                input1.validate(facesContext);
                input2.validate(facesContext);

        // update model since it is necessary for crossval
                input1.updateModel(facesContext);
                input2.updateModel(facesContext);

                processCrossValidation();
        }

        protected ValueExpression createValueExpression(String valueExp) {
                return new MockValueExpression(valueExp, String.class);
                // or using which returns MockCompositeValueExpression
                // ExpressionFactory factory =
                // facesContext.getApplication().getExpressionFactory();
                // return 
factory.createValueExpression(facesContext.getELContext(),
                // valueExp, String.class);
        }

        protected void processCrossValidation() {
                new CrossValidationPhaseListener().afterPhase(new 
PhaseEvent(facesContext, PhaseId.ANY_PHASE, lifecycle));
        }
}

  

Heute erleben, was morgen Trend wird - das kann man auf der IFA in Berlin. Oder 
auf arcor.de: Wir stellen Ihnen die wichtigsten News, Trends und Gadgets der 
IFA vor. Natürlich mit dabei: das brandneue IPTV-Angebot von Vodafone! Alles 
rund um die Internationale Funkausstellung in Berlin finden Sie hier: 
http://www.arcor.de/rd/footer.ifa2010

Reply via email to