You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/02/13 01:33:40 UTC

svn commit: r743938 - in /myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator: ./ crossval/

Author: gpetracek
Date: Fri Feb 13 00:33:39 2009
New Revision: 743938

URL: http://svn.apache.org/viewvc?rev=743938&view=rev
Log:
EXTVAL-35 tests for el referencing syntax

Added:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossComponentValidationTest.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestDateBean.java
Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/AbstractExValViewControllerTestCase.java

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/AbstractExValViewControllerTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/AbstractExValViewControllerTestCase.java?rev=743938&r1=743937&r2=743938&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/AbstractExValViewControllerTestCase.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/AbstractExValViewControllerTestCase.java Fri Feb 13 00:33:39 2009
@@ -40,6 +40,7 @@
 import org.apache.myfaces.extensions.validator.core.startup.ExtValStartupListener;
 import org.apache.myfaces.extensions.validator.crossval.CrossValidationPhaseListener;
 import org.apache.myfaces.extensions.validator.util.TestUtils;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 import org.apache.myfaces.shared_impl.config.MyfacesConfig;
 import org.apache.shale.test.mock.MockApplication;
 import org.apache.shale.test.mock.MockExternalContext;
@@ -245,4 +246,15 @@
             uiInput.setValueBinding(name, valueBinding);
         }
     }
+
+    protected void createRequestScopedBean(String name, Object instance)
+    {
+        createValueBinding(null, "value", "#{" + name + "}");
+        facesContext.getExternalContext().getRequestMap().put(name, instance);
+    }
+
+    protected <T> T resolveBean(String name, Class<T> targetClass)
+    {
+        return (T) ExtValUtils.getELHelper().getBean(name);
+    }
 }

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossComponentValidationTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossComponentValidationTest.java?rev=743938&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossComponentValidationTest.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossComponentValidationTest.java Fri Feb 13 00:33:39 2009
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.crossval;
+
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.convert.DateTimeConverter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.extensions.validator.AbstractExValViewControllerTestCase;
+
+import java.util.Date;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ELCrossComponentValidationTest extends AbstractExValViewControllerTestCase
+{
+    HtmlInputText inputComponent1 = null;
+    HtmlInputText inputComponent2 = null;
+
+    UIViewRoot rootComponent = null;
+
+    public ELCrossComponentValidationTest(String name)
+    {
+        super(name);
+        inputComponent1 = null;
+        inputComponent2 = null;
+        rootComponent = null;
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(ELCrossComponentValidationTest.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        createRequestScopedBean("bean1", new ELCrossValTestDateBean());
+        createRequestScopedBean("bean2", new ELCrossValTestDateBean());
+
+
+        rootComponent = new UIViewRoot();
+        HtmlForm form = new HtmlForm();
+        form.setId("form");
+        rootComponent.getChildren().add(form);
+
+        //input1
+        inputComponent1 = new HtmlInputText();
+        inputComponent1.setId("input1");
+        inputComponent1.setConverter(new DateTimeConverter());
+        ((DateTimeConverter)inputComponent1.getConverter()).setPattern("dd.MM.yyyy");
+        form.getChildren().add(inputComponent1);
+
+        //input2
+        inputComponent2 = new HtmlInputText();
+        inputComponent2.setId("input2");
+        inputComponent2.setConverter(new DateTimeConverter());
+        ((DateTimeConverter)inputComponent2.getConverter()).setPattern("dd.MM.yyyy");
+        form.getChildren().add(inputComponent2);
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testCrossComponentEqualsValidationCorrect() throws Exception
+    {
+        validateELCrossComponentValidationUseCase("14.05.1983", "14.05.1983", "14.05.1983", "14.05.1983");
+
+        checkMessageCount(0);
+    }
+
+    public void testCrossComponentEqualsValidationFailedValidation() throws Exception
+    {
+        validateELCrossComponentValidationUseCase("14.05.1983", "14.05.1983", "14.05.1983", "12.12.2008");
+
+        checkMessageCount(2);
+    }
+
+    private void validateELCrossComponentValidationUseCase(String valueBean1Property1, String valueBean1Property2, String valueBean2Property1, String valueBean2Property2)
+    {
+        createValueBinding(inputComponent1, "value", "#{bean1.date1}");
+        createValueBinding(inputComponent2, "value", "#{bean2.date2}");
+
+        //set model values
+        resolveBean("bean1", ELCrossValTestDateBean.class).setDate2((Date)inputComponent1.getConverter().getAsObject(facesContext, inputComponent1, valueBean1Property2));
+        resolveBean("bean2", ELCrossValTestDateBean.class).setDate1((Date)inputComponent2.getConverter().getAsObject(facesContext, inputComponent2, valueBean2Property1));
+
+
+        //decode
+        inputComponent1.setSubmittedValue(valueBean1Property1);
+        inputComponent2.setSubmittedValue(valueBean2Property2);
+
+        //validate
+        inputComponent1.validate(facesContext);
+        inputComponent2.validate(facesContext);
+
+        processCrossValValidation();
+
+        //no update model needed
+    }
+
+    public void testModelAwareCrossEqualsValidationCorrect() throws Exception
+    {
+        validateELModelAwareCrossValidationUseCase("14.05.1983", "14.05.1983", "14.05.1983", "14.05.1983");
+
+        checkMessageCount(0);
+    }
+
+    public void testModelAwareCrossEqualsValidationFailedValidation() throws Exception
+    {
+        validateELModelAwareCrossValidationUseCase("14.05.1983", "14.05.1983", "14.05.1983", "12.12.2008");
+
+        checkMessageCount(1);
+    }
+
+    private void validateELModelAwareCrossValidationUseCase(String valueBean1Property1, String valueBean1Property2, String valueBean2Property1, String valueBean2Property2)
+    {
+        createValueBinding(inputComponent1, "value", "#{bean1.date1}");
+        createValueBinding(inputComponent2, "value", "#{bean2.date2}");
+
+        //set model values
+        resolveBean("bean1", ELCrossValTestDateBean.class).setDate2((Date)inputComponent1.getConverter().getAsObject(facesContext, inputComponent1, valueBean1Property2));
+        resolveBean("bean2", ELCrossValTestDateBean.class).setDate1((Date)inputComponent2.getConverter().getAsObject(facesContext, inputComponent2, valueBean2Property1));
+        resolveBean("bean2", ELCrossValTestDateBean.class).setDate2((Date)inputComponent2.getConverter().getAsObject(facesContext, inputComponent2, valueBean2Property2));
+
+
+        //decode
+        inputComponent1.setSubmittedValue(valueBean1Property1);
+
+        //validate
+        inputComponent1.validate(facesContext);
+
+        processCrossValValidation();
+
+        //no update model needed
+    }
+}

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestDateBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestDateBean.java?rev=743938&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestDateBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestDateBean.java Fri Feb 13 00:33:39 2009
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.crossval;
+
+import org.apache.myfaces.extensions.validator.crossval.annotation.Equals;
+
+import java.util.Date;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class ELCrossValTestDateBean
+{
+    private static final Date DEFAULT_DATE = new Date();
+
+    @Equals("#{bean2.date2}")
+    private Date date1 = DEFAULT_DATE;
+
+    private Date date2 = DEFAULT_DATE;
+
+    public Date getDate1()
+    {
+        return date1;
+    }
+
+    public void setDate1(Date date1)
+    {
+        this.date1 = date1;
+    }
+
+    public Date getDate2()
+    {
+        return date2;
+    }
+
+    public void setDate2(Date date2)
+    {
+        this.date2 = date2;
+    }
+}