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/11/11 02:03:12 UTC
svn commit: r834734 - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval:
./ model/ view/
Author: gpetracek
Date: Wed Nov 11 01:03:12 2009
New Revision: 834734
URL: http://svn.apache.org/viewvc?rev=834734&view=rev
Log:
EXTVAL-30 bv model validation and group validation test cases
Added:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/RestrictGroupsTestCase.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/SimulatedUserInformation.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/RestrictGroupValidationTestCase1PageBean.java
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/ModelValidation1TestCase.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/UseGroupValidation1TestCase.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/ModelValidationTestCase1PageBean.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/ModelValidation1TestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/ModelValidation1TestCase.java?rev=834734&r1=834733&r2=834734&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/ModelValidation1TestCase.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/ModelValidation1TestCase.java Wed Nov 11 01:03:12 2009
@@ -19,6 +19,7 @@
package org.apache.myfaces.extensions.validator.test.beanval;
import org.apache.myfaces.extensions.validator.test.beanval.view.ModelValidationTestCase1PageBean;
+import org.apache.myfaces.extensions.validator.test.beanval.model.SimulatedUserInformation;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -136,4 +137,43 @@
checkMessageCount(2);
checkMessageSeverities(FacesMessage.SEVERITY_ERROR, FacesMessage.SEVERITY_ERROR);
}
-}
+
+ public void testModelViolationWithAdminRole()
+ {
+ createRequestScopedBean("currentUser", new SimulatedUserInformation("admin"));
+
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model5.property1}");
+ setValueToValidate(this.inputComponent1, "123");
+
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model5.property2}");
+ setValueToValidate(this.inputComponent2, "456");
+
+ validateComponents();
+ updateComponents();
+ processModelValidation();
+
+ assertNavigationBlocked(false);
+
+ checkMessageCount(0);
+ }
+
+ public void testModelViolationWithUserRole()
+ {
+ createRequestScopedBean("currentUser", new SimulatedUserInformation("user"));
+
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model5.property1}");
+ setValueToValidate(this.inputComponent1, "123");
+
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model5.property2}");
+ setValueToValidate(this.inputComponent2, "456");
+
+ validateComponents();
+ updateComponents();
+ processModelValidation();
+
+ assertNavigationBlocked(true);
+
+ checkMessageCount(1);
+ checkMessageSeverities(FacesMessage.SEVERITY_ERROR);
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/RestrictGroupsTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/RestrictGroupsTestCase.java?rev=834734&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/RestrictGroupsTestCase.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/RestrictGroupsTestCase.java Wed Nov 11 01:03:12 2009
@@ -0,0 +1,147 @@
+/*
+ * 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.test.beanval;
+
+import org.apache.myfaces.extensions.validator.test.beanval.view.RestrictGroupValidationTestCase1PageBean;
+import org.apache.myfaces.extensions.validator.test.beanval.model.SimulatedUserInformation;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+public class RestrictGroupsTestCase extends BaseBeanValPropertyValidationTestCase<RestrictGroupValidationTestCase1PageBean>
+{
+ public RestrictGroupsTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(RestrictGroupsTestCase.class);
+ }
+
+ protected RestrictGroupValidationTestCase1PageBean getBeanToTest()
+ {
+ return new RestrictGroupValidationTestCase1PageBean();
+ }
+
+ public void testRestrictedGroup()
+ {
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model1.property1}");
+ setValueToValidate(this.inputComponent1, "");
+
+ validateComponents();
+
+ assertComponentValid(this.inputComponent1);
+ assertNavigationBlocked(false);
+
+ checkMessageCount(0);
+ }
+
+ public void testRestrictedGroupWithAdminRole()
+ {
+ createRequestScopedBean("currentUser", new SimulatedUserInformation("admin"));
+
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model2.property1}");
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model2.property2}");
+ setValueToValidate(this.inputComponent1, "");
+ setValueToValidate(this.inputComponent2, "");
+
+ validateComponents();
+
+ assertComponentValid(this.inputComponent1);
+ assertComponentValid(this.inputComponent2);
+
+ assertNavigationBlocked(false);
+ checkMessageCount(0);
+ }
+
+ public void testRestrictedGroupWithUserRole()
+ {
+ createRequestScopedBean("currentUser", new SimulatedUserInformation("user"));
+
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model2.property1}");
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model2.property2}");
+ setValueToValidate(this.inputComponent1, "");
+ setValueToValidate(this.inputComponent2, "");
+
+ validateComponents();
+
+ assertComponentInvalid(this.inputComponent1);
+ assertComponentValid(this.inputComponent2);
+
+ assertNavigationBlocked(true);
+ checkMessageCount(1);
+ checkMessageSeverities(FacesMessage.SEVERITY_ERROR);
+ }
+
+ public void testRestrictedGroupWithCorrectViewId()
+ {
+ FacesContext.getCurrentInstance().getViewRoot().setViewId("/pages/groupValidationAwarePage.xhtml");
+
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model3.property1}");
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model3.property2}");
+ setValueToValidate(this.inputComponent1, "");
+ setValueToValidate(this.inputComponent2, "");
+
+ validateComponents();
+
+ assertComponentValid(this.inputComponent1);
+ assertComponentValid(this.inputComponent2);
+
+ assertNavigationBlocked(false);
+ checkMessageCount(0);
+ }
+
+ public void testRestrictedGroupWithWrongViewId()
+ {
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model3.property1}");
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model3.property2}");
+ setValueToValidate(this.inputComponent1, "");
+ setValueToValidate(this.inputComponent2, "");
+
+ validateComponents();
+
+ assertComponentInvalid(this.inputComponent1);
+ assertComponentValid(this.inputComponent2);
+
+ assertNavigationBlocked(true);
+ checkMessageCount(1);
+ checkMessageSeverities(FacesMessage.SEVERITY_ERROR);
+ }
+
+ public void testUsedAndRestrictedGroup()
+ {
+ createValueBindingForComponent(this.inputComponent1, "#{testBean.model4.property1}");
+ createValueBindingForComponent(this.inputComponent2, "#{testBean.model4.property2}");
+ setValueToValidate(this.inputComponent1, "");
+ setValueToValidate(this.inputComponent2, "");
+
+ validateComponents();
+
+ assertComponentValid(this.inputComponent1);
+ assertComponentInvalid(this.inputComponent2);
+
+ assertNavigationBlocked(true);
+ checkMessageCount(1);
+ checkMessageSeverities(FacesMessage.SEVERITY_ERROR);
+ }
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/UseGroupValidation1TestCase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/UseGroupValidation1TestCase.java?rev=834734&r1=834733&r2=834734&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/UseGroupValidation1TestCase.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/UseGroupValidation1TestCase.java Wed Nov 11 01:03:12 2009
@@ -21,6 +21,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.myfaces.extensions.validator.test.beanval.view.UseGroupValidationTestCase1PageBean;
+import org.apache.myfaces.extensions.validator.test.beanval.model.SimulatedUserInformation;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
@@ -163,24 +164,4 @@
checkMessageCount(2);
checkMessageSeverities(FacesMessage.SEVERITY_ERROR, FacesMessage.SEVERITY_ERROR);
}
-
- public class SimulatedUserInformation
- {
- private String value;
-
- SimulatedUserInformation(String value)
- {
- this.value = value;
- }
-
- public boolean isAdminRole()
- {
- return "admin".equals(value);
- }
-
- public boolean isUserRole()
- {
- return "user".equals(value);
- }
- }
-}
+}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/SimulatedUserInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/SimulatedUserInformation.java?rev=834734&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/SimulatedUserInformation.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/model/SimulatedUserInformation.java Wed Nov 11 01:03:12 2009
@@ -0,0 +1,39 @@
+/*
+ * 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.test.beanval.model;
+
+public class SimulatedUserInformation
+{
+ private String value;
+
+ public SimulatedUserInformation(String value)
+ {
+ this.value = value;
+ }
+
+ public boolean isAdminRole()
+ {
+ return "admin".equals(value);
+ }
+
+ public boolean isUserRole()
+ {
+ return "user".equals(value);
+ }
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/ModelValidationTestCase1PageBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/ModelValidationTestCase1PageBean.java?rev=834734&r1=834733&r2=834734&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/ModelValidationTestCase1PageBean.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/ModelValidationTestCase1PageBean.java Wed Nov 11 01:03:12 2009
@@ -34,6 +34,9 @@
@BeanValidation(modelValidation = @ModelValidation(isActive = true, displayInline = true))
private ModelValidationTestCase1Bean model4 = new ModelValidationTestCase1Bean();
+ @BeanValidation(conditions = "#{currentUser.userRole}", modelValidation = @ModelValidation(isActive = true))
+ private ModelValidationTestCase1Bean model5 = new ModelValidationTestCase1Bean();
+
@BeanValidation(modelValidation = @ModelValidation(isActive = true))
public ModelValidationTestCase1Bean getModel1()
{
@@ -55,4 +58,9 @@
{
return model4;
}
+
+ public ModelValidationTestCase1Bean getModel5()
+ {
+ return model5;
+ }
}
\ No newline at end of file
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/RestrictGroupValidationTestCase1PageBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/RestrictGroupValidationTestCase1PageBean.java?rev=834734&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/RestrictGroupValidationTestCase1PageBean.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/test-modules/bean-validation-tests/src/test/java/org/apache/myfaces/extensions/validator/test/beanval/view/RestrictGroupValidationTestCase1PageBean.java Wed Nov 11 01:03:12 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.test.beanval.view;
+
+import org.apache.myfaces.extensions.validator.test.beanval.model.GroupValidationTestCase1Bean;
+import org.apache.myfaces.extensions.validator.test.beanval.validation.Group1;
+import org.apache.myfaces.extensions.validator.test.beanval.validation.Group2;
+import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation;
+
+@BeanValidation(useGroups = Group1.class)
+public class RestrictGroupValidationTestCase1PageBean
+{
+ @BeanValidation(restrictGroups = Group1.class)
+ private GroupValidationTestCase1Bean model1 = new GroupValidationTestCase1Bean();
+
+ private GroupValidationTestCase1Bean model2 = new GroupValidationTestCase1Bean();
+
+ @BeanValidation(viewIds = "/pages/groupValidationAwarePage.xhtml", restrictGroups = Group1.class)
+ private GroupValidationTestCase1Bean model3 = new GroupValidationTestCase1Bean();
+
+ @BeanValidation(restrictGroups = Group1.class, useGroups = Group2.class)
+ private GroupValidationTestCase1Bean model4 = new GroupValidationTestCase1Bean();
+
+ public GroupValidationTestCase1Bean getModel1()
+ {
+ return model1;
+ }
+
+ @BeanValidation(conditions = "#{currentUser.adminRole}", restrictGroups = Group1.class)
+ public GroupValidationTestCase1Bean getModel2()
+ {
+ return model2;
+ }
+
+ public GroupValidationTestCase1Bean getModel3()
+ {
+ return model3;
+ }
+
+ public GroupValidationTestCase1Bean getModel4()
+ {
+ return model4;
+ }
+}