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 04:24:15 UTC
svn commit: r669051 -
/myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java
Author: lu4242
Date: Tue Jun 17 19:24:15 2008
New Revision: 669051
URL: http://svn.apache.org/viewvc?rev=669051&view=rev
Log:
added DateRestrictionValidatorTestCase.java
Added:
myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java (with props)
Added: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java?rev=669051&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java Tue Jun 17 19:24:15 2008
@@ -0,0 +1,131 @@
+package org.apache.myfaces.commons.validator;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.commons.validator.model.DateListProvider;
+
+public class DateRestrictionValidatorTestCase extends AbstractValidatorTestCase
+{
+
+ public DateRestrictionValidatorTestCase(String arg0)
+ {
+ super(arg0);
+ }
+
+ DateRestrictionValidator dateRestrictionValidator;
+
+ private static final String[] invalidMonths = { "jan", "feb", "mar" };
+ private static final String[] invalidDaysOfWeek = { "sat", "sun" };
+
+
+
+ public class CustomDateListProvider implements DateListProvider
+ {
+ public List<Date> getDateList(FacesContext context, Calendar base,
+ Date rangeStart, Date rangeEnd)
+ {
+ List<Date> list = new ArrayList<Date>();
+ Calendar cal = new GregorianCalendar();
+ cal.set(2008, 0, 2, 0, 1, 0);
+ list.add(cal.getTime());
+ return list;
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ dateRestrictionValidator = new DateRestrictionValidator();
+ dateRestrictionValidator.setInvalidMonths(invalidMonths);
+ dateRestrictionValidator.setInvalidDaysOfWeek(invalidDaysOfWeek);
+ dateRestrictionValidator.setInvalidDays(new CustomDateListProvider());
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(DateRestrictionValidatorTestCase.class);
+ }
+
+ /**
+ * Test when context is set to null
+ */
+ public void testNullContext()
+ {
+ doTestNullContext(component, dateRestrictionValidator);
+ }
+
+ public void testGoodDateRestriction()
+ {
+ Calendar cal = new GregorianCalendar();
+ cal.set(2008, 6, 16, 0, 1, 0);//MONDAY
+ dateRestrictionValidator.validate(facesContext, component, cal
+ .getTime());
+ }
+
+ public void testBadDayOfWeekRestriction()
+ {
+ try
+ {
+ Calendar cal = new GregorianCalendar();
+ cal.set(2008, 5, 15, 0, 1, 0);//SUNDAY JUNE 15 2008
+ //System.out.println(cal.get(Calendar.DAY_OF_WEEK)+" "+cal.getTime().toString());
+ dateRestrictionValidator.validate(facesContext, component, cal
+ .getTime());
+ fail("Expected ValidatorException");
+ }
+ catch (ValidatorException ve)
+ {
+ // if exception then fine.
+ }
+ }
+
+ public void testBadMonthRestriction()
+ {
+ try
+ {
+ Calendar cal = new GregorianCalendar();
+ cal.set(2008, 0, 15, 0, 1, 0);//JANUARY 15 2008
+ //System.out.println(cal.get(Calendar.DAY_OF_WEEK)+" "+cal.getTime().toString());
+ dateRestrictionValidator.validate(facesContext, component, cal
+ .getTime());
+ fail("Expected ValidatorException");
+ }
+ catch (ValidatorException ve)
+ {
+ // if exception then fine.
+ }
+ }
+
+ public void testBadDayRestriction()
+ {
+ try
+ {
+ Calendar cal = new GregorianCalendar();
+ cal.set(2008, 0, 2, 0, 1, 0);
+ //System.out.println(cal.get(Calendar.DAY_OF_WEEK)+" "+cal.getTime().toString());
+ dateRestrictionValidator.validate(facesContext, component, cal
+ .getTime());
+ fail("Expected ValidatorException");
+ }
+ catch (ValidatorException ve)
+ {
+ // if exception then fine.
+ }
+ }
+
+}
\ No newline at end of file
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/commons/trunk/myfaces-commons-validators/src/test/java/org/apache/myfaces/commons/validator/DateRestrictionValidatorTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL