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 09:53:12 UTC
svn commit: r744038 - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src:
main/java/org/apache/myfaces/extensions/validator/crossval/strategy/
test/java/org/apache/myfaces/extensions/validator/crossval/
Author: gpetracek
Date: Fri Feb 13 08:53:12 2009
New Revision: 744038
URL: http://svn.apache.org/viewvc?rev=744038&view=rev
Log:
EXTVAL-35 tests and adjustments for property chain 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/PropertyChainCrossValTestCase.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateBean.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateSubBean.java
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestCase.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java?rev=744038&r1=744037&r2=744038&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/LocalPropertyChainCompareStrategy.java Fri Feb 13 08:53:12 2009
@@ -73,9 +73,8 @@
if (keyConvertedValueMapping.containsKey(newKey))
{
ProcessedInformationEntry validationTargetEntry = keyConvertedValueMapping.get(newKey);
- Object targetValue = validationTargetEntry.getConvertedValue();
- processCrossComponentValidation(compareStrategy, crossValidationStorageEntry, targetValue);
+ processCrossComponentValidation(compareStrategy, crossValidationStorageEntry, validationTargetEntry);
}
//no target - because there is no target component - value was validated against the model
else
@@ -89,16 +88,17 @@
private void processCrossComponentValidation(
AbstractCompareStrategy compareStrategy,
CrossValidationStorageEntry crossValidationStorageEntry,
- Object targetValue)
+ ProcessedInformationEntry targetInformationEntry)
{
- //no target - because there is no target component - value was validated against the model
- if (compareStrategy.isViolation(crossValidationStorageEntry.getConvertedObject(),
- targetValue, crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class)))
+ if (compareStrategy.isViolation(
+ crossValidationStorageEntry.getConvertedObject(),
+ targetInformationEntry.getConvertedValue(),
+ crossValidationStorageEntry.getMetaDataEntry().getValue(Annotation.class)))
{
CrossValidationStorageEntry tmpCrossValidationStorageEntry = new CrossValidationStorageEntry();
tmpCrossValidationStorageEntry.setComponent(crossValidationStorageEntry.getComponent());
- tmpCrossValidationStorageEntry.setClientId(crossValidationStorageEntry.getClientId());
- tmpCrossValidationStorageEntry.setConvertedObject(targetValue);
+ tmpCrossValidationStorageEntry.setClientId(targetInformationEntry.getClientId());
+ tmpCrossValidationStorageEntry.setConvertedObject(targetInformationEntry.getConvertedValue());
tmpCrossValidationStorageEntry.setValidationStrategy(compareStrategy);
//process after violation
@@ -144,4 +144,4 @@
.crossValidateCompareStrategy(
compareStrategy, crossValidationStorageEntry, targetEntry, true);
}
-}
\ No newline at end of file
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestCase.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/ELCrossValTestCase.java?rev=744038&r1=744037&r2=744038&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestCase.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/ELCrossValTestCase.java Fri Feb 13 08:53:12 2009
@@ -141,7 +141,6 @@
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", getEntityInstance().getClass()).setDate2((Date)inputComponent1.getConverter().getAsObject(facesContext, inputComponent1, valueBean1Property2));
@@ -164,4 +163,4 @@
{
return new ELCrossValTestDateBean();
}
-}
\ No newline at end of file
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestCase.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/PropertyChainCrossValTestCase.java?rev=744038&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestCase.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestCase.java Fri Feb 13 08:53:12 2009
@@ -0,0 +1,155 @@
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.myfaces.extensions.validator.AbstractExValViewControllerTestCase;
+
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.component.UIViewRoot;
+import javax.faces.convert.DateTimeConverter;
+import java.util.Date;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class PropertyChainCrossValTestCase extends AbstractExValViewControllerTestCase
+{
+ HtmlInputText inputComponent1 = null;
+ HtmlInputText inputComponent2 = null;
+
+ UIViewRoot rootComponent = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(PropertyChainCrossValTestCase.class);
+ }
+
+ public PropertyChainCrossValTestCase(String name)
+ {
+ super(name);
+ inputComponent1 = null;
+ inputComponent2 = null;
+ rootComponent = null;
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ createRequestScopedBean("bean1", getEntityInstance());
+
+ 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
+ {
+ validatePropertyChainCrossComponentValidationUseCase("14.05.1983", "14.05.1983");
+
+ checkMessageCount(0);
+ }
+
+ public void testCrossComponentEqualsValidationFailedValidation() throws Exception
+ {
+ validatePropertyChainCrossComponentValidationUseCase("14.05.1983", "12.12.2008");
+
+ checkMessageCount(2);
+ }
+
+ private void validatePropertyChainCrossComponentValidationUseCase(String valueBean1Property1, String valueBean2Property2)
+ {
+ createValueBinding(inputComponent1, "value", "#{bean1.date1}");
+ createValueBinding(inputComponent2, "value", "#{bean1.subBean.date2}");
+
+ //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");
+
+ checkMessageCount(0);
+ }
+
+ public void testModelAwareCrossEqualsValidationFailedValidation() throws Exception
+ {
+ validateELModelAwareCrossValidationUseCase("14.05.1983", "12.12.2008");
+
+ checkMessageCount(1);
+ }
+
+ private void validateELModelAwareCrossValidationUseCase(String valueBean1Property1, String valueBean2Property1)
+ {
+ createValueBinding(inputComponent1, "value", "#{bean1.date1}");
+
+ //set model values
+ resolveBean("bean1", getEntityInstance().getClass()).getSubBean().setDate2((Date)inputComponent2.getConverter().getAsObject(facesContext, inputComponent2, valueBean2Property1));
+
+
+ //decode
+ inputComponent1.setSubmittedValue(valueBean1Property1);
+
+ //validate
+ inputComponent1.validate(facesContext);
+
+ processCrossValValidation();
+
+ //no update model needed
+ }
+
+ protected PropertyChainCrossValTestDateBean getEntityInstance()
+ {
+ return new PropertyChainCrossValTestDateBean();
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateBean.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/PropertyChainCrossValTestDateBean.java?rev=744038&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateBean.java Fri Feb 13 08:53:12 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 PropertyChainCrossValTestDateBean
+{
+ private static final Date DEFAULT_DATE = new Date();
+
+ @Equals("subBean.date2")
+ private Date date1 = DEFAULT_DATE;
+
+ private PropertyChainCrossValTestDateSubBean subBean = new PropertyChainCrossValTestDateSubBean();
+
+ public Date getDate1()
+ {
+ return date1;
+ }
+
+ public void setDate1(Date date1)
+ {
+ this.date1 = date1;
+ }
+
+ public PropertyChainCrossValTestDateSubBean getSubBean()
+ {
+ return subBean;
+ }
+
+ public void setSubBean(PropertyChainCrossValTestDateSubBean subBean)
+ {
+ this.subBean = subBean;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateSubBean.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/PropertyChainCrossValTestDateSubBean.java?rev=744038&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateSubBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/crossval/PropertyChainCrossValTestDateSubBean.java Fri Feb 13 08:53:12 2009
@@ -0,0 +1,41 @@
+/*
+ * 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 java.util.Date;
+
+/**
+ * @author Gerhard Petracek
+ */
+public class PropertyChainCrossValTestDateSubBean
+{
+ private static final Date DEFAULT_DATE = new Date();
+
+ private Date date2 = DEFAULT_DATE;
+
+ public Date getDate2()
+ {
+ return date2;
+ }
+
+ public void setDate2(Date date2)
+ {
+ this.date2 = date2;
+ }
+}