[richfaces-svn-commits] JBoss Rich Faces SVN: r11534 - in trunk/test-applications/seleniumTest/richfaces/src: main/java/org/ajax4jsf/util and 2 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Dec 3 13:59:50 EST 2008


Author: dsvyatobatsko
Date: 2008-12-03 13:59:50 -0500 (Wed, 03 Dec 2008)
New Revision: 11534

Added:
   trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/DateUtils.java
Modified:
   trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java
   trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/calendar/calendarTest.xhtml
   trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java
Log:
https://jira.jboss.org/jira/browse/RF-5153
https://jira.jboss.org/jira/browse/RF-5154

Modified: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java	2008-12-03 18:38:11 UTC (rev 11533)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java	2008-12-03 18:59:50 UTC (rev 11534)
@@ -93,7 +93,11 @@
     }
 
     public void resetSelectedDateString() {
-        setSelectedDateString(DATE_FORMAT.format(getSelectedDate()));
+        if (getSelectedDate() != null) {
+            setSelectedDateString(DATE_FORMAT.format(getSelectedDate()));
+        } else {
+            setSelectedDateString("");
+        }
     }
 
     public String getSelectedDateString() {
@@ -251,4 +255,22 @@
         this.currentDate = currentDate;
     }
 
+    private boolean isPopup;
+
+    /**
+     * Gets value of isPopup field.
+     * @return value of isPopup field
+     */
+    public boolean isPopup() {
+        return isPopup;
+    }
+
+    /**
+     * Set a new value for isPopup field.
+     * @param isPopup a new value for isPopup field
+     */
+    public void setPopup(boolean isPopup) {
+        this.isPopup = isPopup;
+    }
+
 }

Added: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/DateUtils.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/DateUtils.java	                        (rev 0)
+++ trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/DateUtils.java	2008-12-03 18:59:50 UTC (rev 11534)
@@ -0,0 +1,44 @@
+package org.ajax4jsf.util;
+
+import java.text.DateFormatSymbols;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+public abstract class DateUtils {
+
+    /**
+     * Returns <code>Date</code> object according to given <code>dateString</code>
+     * @param dateString
+     * @param pattern
+     * @param locale
+     * @return
+     */
+    public static Date date(String dateString, String pattern, Locale locale) {
+        Date retVal = null;
+        try {
+            retVal = new SimpleDateFormat(pattern, locale).parse(dateString);
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return retVal;
+    }
+
+    public static String month(Date date, Locale locale) {
+        Calendar c = Calendar.getInstance(locale);
+        c.setTime(date);
+        DateFormatSymbols symbols = new DateFormatSymbols(locale);
+        return symbols.getMonths()[c.get(Calendar.MONTH)];
+    }
+
+    public static int year(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        return c.get(Calendar.YEAR);
+    }
+
+}


Property changes on: trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/util/DateUtils.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Author Id Revision Date
Name: svn:eol-style
   + native

Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/calendar/calendarTest.xhtml
===================================================================
(Binary files differ)

Modified: trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java
===================================================================
--- trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java	2008-12-03 18:38:11 UTC (rev 11533)
+++ trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java	2008-12-03 18:59:50 UTC (rev 11534)
@@ -22,10 +22,13 @@
 package org.richfaces.testng;
 
 import java.text.ParseException;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.Locale;
 
 import org.ajax4jsf.bean.CalendarTestBean;
 import org.ajax4jsf.template.Template;
+import org.ajax4jsf.util.DateUtils;
 import org.richfaces.SeleniumTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -33,13 +36,12 @@
 public class CalendarTest extends SeleniumTestBase {
 
     static final String RESET_METHOD = "#{calendarBean.reset}";
-
     static final String FORM_ID = "_form:";
 
     static final String CONTROLS_FORM_ID = "_controls:";
 
     static final String availableDayCellClass = "rich-calendar-cell-size rich-calendar-cell rich-calendar-btn";
-    
+
     String calendarId;
 
     String calendarHeaderId;
@@ -55,9 +57,15 @@
     String resetActionId;
 
     String testClientModeId;
-    
+
+    String setupActionId;
+
+    String dateSelectionXpath;
+
     String timeSelectionXpath;
-    
+
+    String timeSelectionXpathMinusDiv;
+
     String timeHoursSelectionId;
     
     String timeMinutesSelectionId;
@@ -66,20 +74,44 @@
     
     String timeSelectionCancelButtonId;
 
+    String selectedDateId;
+
+    String currentDateId;
+
+    String isPopupId;
+
+    String datePatternId;
+
+    String timeZoneId;
+
+    String localId;
+
+    String currentDateHeaderXpath;
+
     void initIds(String parentId) {
         calendarId = parentId + FORM_ID + "calendar";
         calendarHeaderId = calendarId + "Header";
         calendarFooterId = calendarId + "Footer";
+        dateSelectionXpath = "//td[@id='"+calendarFooterId+"']/table/tbody/tr/td[1]";
+        timeSelectionXpathMinusDiv = "//td[@id='"+calendarFooterId+"']/table/tbody/tr/td[3]";
         timeSelectionXpath = "//td[@id='"+calendarFooterId+"']/table/tbody/tr/td[3]/div";
         ajaxSubmitId = parentId + FORM_ID + "ajaxSubmit";
         serverSubmitId = parentId + FORM_ID + "serverSubmit";
         statusId = parentId + FORM_ID + "status";
         resetActionId = parentId + CONTROLS_FORM_ID + "resetAction";
         testClientModeId = parentId + CONTROLS_FORM_ID + "testClientMode";
+        setupActionId = parentId + CONTROLS_FORM_ID + "setup";
         timeHoursSelectionId = calendarId + "TimeHours";
         timeMinutesSelectionId = calendarId + "TimeMinutes";
         timeSelectionOkButtonId = calendarId + "TimeEditorButtonOk";
         timeSelectionCancelButtonId = calendarId + "TimeEditorButtonCancel";
+        selectedDateId = parentId + CONTROLS_FORM_ID + "selectedDate";
+        currentDateId = parentId + CONTROLS_FORM_ID + "currentDate";
+        isPopupId  = parentId + CONTROLS_FORM_ID + "isPopup";
+        datePatternId = parentId + CONTROLS_FORM_ID + "datePattern";
+        timeZoneId = parentId + CONTROLS_FORM_ID + "timeZone";
+        localId = parentId + CONTROLS_FORM_ID + "local";
+        currentDateHeaderXpath = "//td[@id='"+calendarHeaderId+"']/table/tbody/tr/td[3]/div";
     }
 
     String getStatus() {
@@ -292,6 +324,76 @@
         Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be visible on the component!");
     }
 
+//    @Test
+//    public void testValueAndCurrentDateOfCalendarInCaseOfPopupTrue(Template template) {
+//        renderPage(template);
+//        //1. value != null + curr_date != null
+//        //2. value != null + curr_date == null
+//        //3. value == null + curr_date == null
+//    }
+
+    @Test
+    public void testValueAndCurrentDateOfCalendarWithPopupFalse(Template template) {
+        renderPage(template, RESET_METHOD);
+        initIds(getParentId());
+        String expectedSelectedDate = "03/03/2007 11:00";
+        String expectedCurrentDate = "04/04/2008 13:00";
+
+        //1. value != null + curr_date != null
+        writeStatus("Check whether the component is present and up to the mark if value and currentDate are defined");
+        setValueById(selectedDateId, expectedSelectedDate);
+        setValueById(currentDateId, expectedCurrentDate);
+        clickCommandAndWait(setupActionId);
+
+        writeStatus("Check selected date");
+        String date = selenium.getText(dateSelectionXpath);
+        String time = selenium.getText(timeSelectionXpath);
+        String date_time = date + " " + time;
+        Assert.assertEquals(date_time, expectedSelectedDate, "Calendar shows wrong date");
+
+        writeStatus("Check current month and year");
+        String currentDate = selenium.getText(currentDateHeaderXpath);
+        Assert.assertEquals(currentDate, "April, 2008", "Calendar shows wrong current date");
+
+        //2. value != null + curr_date == null
+        writeStatus("Check whether the component is present and up to the mark if value is given but currentDate is not");
+
+        setValueById(selectedDateId, expectedSelectedDate);
+        setValueById(currentDateId, "");
+        clickCommandAndWait(setupActionId);
+
+        writeStatus("Check selected date");
+        date = selenium.getText(dateSelectionXpath);
+        time = selenium.getText(timeSelectionXpath);
+        date_time = date + " " + time;
+        Assert.assertEquals(date_time, expectedSelectedDate, "Calendar shows wrong date");
+
+        writeStatus("Check current month and year. Current date is not specified. Value date will be used instead");
+        currentDate = selenium.getText(currentDateHeaderXpath);
+        Assert.assertEquals(currentDate, "March, 2007", "Calendar shows wrong current date");
+
+        //3. value == null + curr_date == null
+        writeStatus("Check whether the component is present and up to the mark if value and currentDate are not defined");
+        setValueById(selectedDateId, "");
+        setValueById(currentDateId, "");
+        clickCommandAndWait(setupActionId);
+
+        writeStatus("Selected date is null. Selected value panel is not visible");
+        Assert.assertFalse(isVisible(dateSelectionXpath), "Footer with selected date has to be invisible");
+        Assert.assertFalse(isVisible(timeSelectionXpathMinusDiv), "Footer with selected date has to be invisible");
+
+        writeStatus("Check current month and year. Current date and value are not defined. Present (do not mix with current time 8))");
+        currentDate = selenium.getText(currentDateHeaderXpath);
+
+        Locale locale = new Locale(selenium.getText(localId));
+        Date presentTime = Calendar.getInstance(locale).getTime();
+        String month = DateUtils.month(presentTime, locale);
+        int year = DateUtils.year(presentTime);
+        String month_year = month + ", " + year;
+
+        Assert.assertEquals(currentDate, month_year, "Calendar shows wrong current date");        
+    }
+
     public String getTestUrl() {
         return "pages/calendar/calendarTest.xhtml";
     }




More information about the richfaces-svn-commits mailing list