You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2006/08/01 18:43:48 UTC

svn commit: r427643 - in /myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators: ./ AbstractValidatorTestCase.java EmailValidatorTestCase.java EqualValidatorTestCase.java RegExprValidatorTestCase.java

Author: matzew
Date: Tue Aug  1 09:43:48 2006
New Revision: 427643

URL: http://svn.apache.org/viewvc?rev=427643&view=rev
Log:
added some test cases

Added:
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java   (with props)
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java   (with props)
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java   (with props)
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java   (with props)

Added: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java?rev=427643&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java (added)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java Tue Aug  1 09:43:48 2006
@@ -0,0 +1,50 @@
+package org.apache.myfaces.custom.validators;
+
+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;
+  
+  public void setUp()
+  {
+    super.setUp();
+    mockComponent = mock(UIComponent.class);
+    component = (UIComponent) mockComponent.proxy();
+    
+  }
+
+  public void tearDown()
+  {
+    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/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/AbstractValidatorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java?rev=427643&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java (added)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java Tue Aug  1 09:43:48 2006
@@ -0,0 +1,63 @@
+package org.apache.myfaces.custom.validators;
+
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.custom.emailvalidator.EmailValidator;
+
+public class EmailValidatorTestCase extends AbstractValidatorTestCase
+{
+
+  public EmailValidatorTestCase(String arg0) {
+    super(arg0);
+  }
+  
+  EmailValidator emailValidator;
+  
+  public void setUp()
+  {
+    super.setUp();
+    emailValidator = new EmailValidator();    
+  }
+
+  public void tearDown()
+  {
+    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/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EmailValidatorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java?rev=427643&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java (added)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java Tue Aug  1 09:43:48 2006
@@ -0,0 +1,91 @@
+package org.apache.myfaces.custom.validators;
+
+import javax.faces.component.UIInput;
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.custom.equalvalidator.EqualValidator;
+
+public class EqualValidatorTestCase extends AbstractValidatorTestCase
+{
+
+  public EqualValidatorTestCase(String arg0) {
+    super(arg0);
+  }
+  
+  EqualValidator equalValidator;
+  
+  public void setUp()
+  {
+    super.setUp();
+    equalValidator = new EqualValidator();
+    
+  }
+
+  public void tearDown()
+  {
+    super.tearDown();
+  }
+
+  public static Test suite()
+  {
+    return new TestSuite(EqualValidatorTestCase.class);
+  }
+  
+  /**
+   * Test when context is set to null
+   */
+  public void testNullContext()
+  {
+
+    doTestNullContext(component, equalValidator);
+  }
+  
+  public void testRightValue()
+  {
+    equalValidator.setFor("comp1");
+    
+    UIInput comp1 = new UIInput();
+    comp1.setValue("HANS");
+    comp1.setId("comp1");
+    facesContext.getViewRoot().getChildren().add(comp1);
+    
+    
+    UIInput comp2 = new UIInput ();
+    comp2.setId("comp2");
+    facesContext.getViewRoot().getChildren().add(comp2);
+
+    equalValidator.validate(facesContext, comp2, "HANS");
+
+  }
+
+  public void testWrongValue()
+  {
+    try
+    {
+      equalValidator.setFor("comp1");
+      
+      UIInput comp1 = new UIInput();
+      comp1.setValue("HANS");
+      comp1.setId("comp1");
+      facesContext.getViewRoot().getChildren().add(comp1);
+      
+      
+      UIInput comp2 = new UIInput ();
+      comp2.setId("comp2");
+      facesContext.getViewRoot().getChildren().add(comp2);
+
+      equalValidator.validate(facesContext, comp2, "BUUBA");
+      
+      fail("Expected ValidatorException");
+    }
+    catch (ValidatorException ve)
+    {
+      // if exception then fine.
+    }
+
+  }
+
+}

Propchange: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/EqualValidatorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java?rev=427643&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java (added)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java Tue Aug  1 09:43:48 2006
@@ -0,0 +1,82 @@
+package org.apache.myfaces.custom.validators;
+
+import javax.faces.component.UIInput;
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.custom.regexprvalidator.RegExprValidator;
+
+public class RegExprValidatorTestCase extends AbstractValidatorTestCase
+{
+
+  public RegExprValidatorTestCase(String arg0) {
+    super(arg0);
+  }
+  
+  RegExprValidator validator;
+  
+  public void setUp()
+  {
+    super.setUp();
+    validator = new RegExprValidator();
+    
+  }
+
+  public void tearDown()
+  {
+    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/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/validators/RegExprValidatorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL