You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/06/18 03:40:00 UTC
svn commit: r669047 [2/2] - in /myfaces/commons/trunk:
myfaces-commons-utils/src/main/java/org/apache/myfaces/commons/util/
myfaces-commons-validators/src/main/conf/
myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/
myfaces...
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidatorBaseTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidatorBaseTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java?rev=669047&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java Tue Jun 17 18:39:59 2008
@@ -0,0 +1,50 @@
+package org.apache.myfaces.commons.validator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.validator.Validator;
+
+import org.apache.shale.test.jmock.AbstractJmockJsfTestCase;
+import org.jmock.Mock;
+
+public abstract class AbstractValidatorTestCase extends AbstractJmockJsfTestCase
+{
+
+ public AbstractValidatorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ Mock mockComponent;
+ UIComponent component;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ mockComponent = mock(UIComponent.class);
+ component = (UIComponent) mockComponent.proxy();
+
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+
+ /**
+ * if contex or component = null then should throw NullPointerException
+ */
+ protected void doTestNullContext(
+ UIComponent component,
+ Validator validator) throws NullPointerException
+ {
+ try
+ {
+ validator.validate(null, component, "dummy");
+ fail("Expected NullpointerException - if context or component is null");
+ }
+ catch (NullPointerException npe)
+ {
+ // this is expected
+ }
+ }
+}
\ No newline at end of file
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/AbstractValidatorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java?rev=669047&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java Tue Jun 17 18:39:59 2008
@@ -0,0 +1,61 @@
+package org.apache.myfaces.commons.validator;
+
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class EmailValidatorTestCase extends AbstractValidatorTestCase
+{
+
+ public EmailValidatorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ EmailValidator emailValidator;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ emailValidator = new EmailValidator();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(EmailValidatorTestCase.class);
+ }
+
+ /**
+ * Test when context is set to null
+ */
+ public void testNullContext()
+ {
+
+ doTestNullContext(component, emailValidator);
+ }
+
+ public void testWrongEmailAddress()
+ {
+ try
+ {
+ emailValidator.validate(facesContext, component, "matzew@apache");
+ fail("Expected ValidatorException");
+ }
+ catch (ValidatorException ve)
+ {
+ // if exception then fine.
+ }
+
+ }
+
+ public void testGoodEmailAddress()
+ {
+ emailValidator.validate(facesContext, component, "foo@apache.org");
+ }
+
+}
\ No newline at end of file
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/EmailValidatorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java?rev=669047&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java Tue Jun 17 18:39:59 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.commons.validator;
+
+import javax.faces.component.UIInput;
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class RegExprValidatorTestCase extends AbstractValidatorTestCase
+{
+
+ public RegExprValidatorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ RegExprValidator validator;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ validator = new RegExprValidator();
+
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(RegExprValidatorTestCase.class);
+ }
+
+ /**
+ * Test when context is set to null
+ */
+ public void testNullContext()
+ {
+
+ doTestNullContext(component, validator);
+ }
+
+ public void testRightValue()
+ {
+ validator.setPattern("\\d{5}");
+
+ UIInput comp1 = new UIInput();
+ comp1.setValue("12345");
+ comp1.setId("comp1");
+ facesContext.getViewRoot().getChildren().add(comp1);
+
+ validator.validate(facesContext, comp1, comp1.getValue());
+
+ }
+
+ public void testWrongValue()
+ {
+ try
+ {
+ validator.setPattern("\\d{12}");
+
+ UIInput comp1 = new UIInput();
+ comp1.setValue("12345");
+ comp1.setId("comp1");
+ facesContext.getViewRoot().getChildren().add(comp1);
+
+ validator.validate(facesContext, comp1, comp1.getValue());
+
+ fail("Expected ValidatorException");
+ }
+ catch (ValidatorException ve)
+ {
+ // if exception then fine.
+ }
+
+ }
+
+
+}
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/RegExprValidatorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL