Author: vbaranov
Date: 2008-05-15 12:29:02 -0400 (Thu, 15 May 2008)
New Revision: 8598
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/CalendarTestBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/calendar/
trunk/test-applications/seleniumTest/src/main/webapp/pages/calendar/calendarTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/CalendarTest.java
Log:
Add selenium test for Calendar control
Added:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/CalendarTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/CalendarTestBean.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/CalendarTestBean.java 2008-05-15
16:29:02 UTC (rev 8598)
@@ -0,0 +1,170 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf;
+
+import java.lang.reflect.Method;
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import javax.faces.convert.DateTimeConverter;
+
+public class CalendarTestBean {
+
+ public static final String DATE_PATTERN = "MM/dd/yyyy HH:mm";
+
+ public static final Locale LOCALE = new Locale("US");
+
+ public static final TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT+2");
+
+ public static Date DEFAULT_DATE;
+
+ private static DateTimeConverter DEFAULT_CONVERTER;
+
+ public static DateFormat DATE_FORMAT;
+
+ // constructor for static fields
+ static {
+ setupDefaultConverter();
+ setupDefaultDate();
+ }
+
+ private String datePattern ;
+
+ private Locale locale;
+
+ private TimeZone timeZone;
+
+ private Date selectedDate;
+
+ private String selectedDateString;
+
+ public CalendarTestBean() {
+ selectedDate = DEFAULT_DATE;
+ resetSelectedDateString();
+
+ datePattern = DATE_PATTERN;
+ locale = LOCALE;
+ timeZone = TIME_ZONE;
+ }
+
+ public Date getSelectedDate() {
+ return selectedDate;
+ }
+
+ public void setSelectedDate(Date selectedDate) {
+ this.selectedDate = selectedDate;
+ resetSelectedDateString();
+ }
+
+ public void resetSelectedDateString() {
+ setSelectedDateString(DATE_FORMAT.format(getSelectedDate()));
+ }
+
+ public String getSelectedDateString() {
+ return selectedDateString;
+ }
+
+ public void setSelectedDateString(String selectedDateString) {
+ this.selectedDateString = selectedDateString;
+ }
+
+ public String getDatePattern() {
+ return datePattern;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public TimeZone getTimeZone() {
+ return timeZone;
+ }
+
+ public void setDatePattern(String datePattern) {
+ this.datePattern = datePattern;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ public void setTimeZone(TimeZone timeZone) {
+ this.timeZone = timeZone;
+ }
+
+ public static Calendar getCalendar() {
+ return Calendar.getInstance(CalendarTestBean.TIME_ZONE, CalendarTestBean.LOCALE);
+ }
+
+ /**
+ * Setup the default date
+ */
+ private static void setupDefaultDate() {
+ DEFAULT_DATE = getDayInMay(10);
+ }
+
+ public static Date getDayInMay(int dayOfMonth) {
+ Calendar calendar = getCalendar();
+ calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+ calendar.set(Calendar.MONTH, Calendar.MAY);
+ calendar.set(Calendar.YEAR, 2008);
+ calendar.set(Calendar.HOUR_OF_DAY, 18);
+ calendar.set(Calendar.MINUTE, 25);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+
+ return calendar.getTime();
+ }
+
+ /**
+ * Setup the default converter
+ */
+ private static void setupDefaultConverter() {
+ DEFAULT_CONVERTER = new DateTimeConverter();
+
+ DEFAULT_CONVERTER.setPattern(DATE_PATTERN);
+ DEFAULT_CONVERTER.setLocale(LOCALE);
+ DEFAULT_CONVERTER.setTimeZone(TIME_ZONE);
+
+ try {
+ Method method = null;
+ Method[] declaredMethods = DateTimeConverter.class.getDeclaredMethods();
+ for (int i = 0; i < declaredMethods.length; i++) {
+ if (declaredMethods[i].getName().equals("getDateFormat")) {
+ method = declaredMethods[i];
+ break;
+ }
+ }
+ if (method != null) {
+
+ method.setAccessible(true);
+ DATE_FORMAT = (DateFormat) method.invoke(DEFAULT_CONVERTER,
DEFAULT_CONVERTER.getLocale());
+ DATE_FORMAT.setTimeZone(DEFAULT_CONVERTER.getTimeZone());
+ }
+ } catch (Exception e) {
+ // skip exception
+ }
+ }
+}
Property changes on:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/CalendarTestBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/test-applications/seleniumTest/src/main/webapp/pages/calendar/calendarTest.xhtml
===================================================================
(Binary files differ)
Property changes on:
trunk/test-applications/seleniumTest/src/main/webapp/pages/calendar/calendarTest.xhtml
___________________________________________________________________
Name: svn:mime-type
+ application/xhtml+xml
Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/CalendarTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/CalendarTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/CalendarTest.java 2008-05-15
16:29:02 UTC (rev 8598)
@@ -0,0 +1,147 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces;
+
+import java.text.ParseException;
+import java.util.Date;
+
+import org.ajax4jsf.CalendarTestBean;
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.Assert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class CalendarTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ /**
+ * Default constructor
+ */
+ public CalendarTest() {
+ super("http", "localhost", "8080");
+ }
+
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testContextMenuComponent() throws Exception {
+ _testSelectDateComponent(Templates.SIMPLE);
+// _testCalendarComponent(Templates.DATATABLE);
+ }
+
+ private void _testCalendarComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+
+ String containerId = getParentId() + "_form:";
+ String calendarOpenedId = containerId + "calendar";
+ String calendarCollapsedId = calendarOpenedId + "Popup";
+ String calendarInputDate = calendarOpenedId + "InputDate";
+ String calendarPopupButton = calendarCollapsedId + "Button";
+ String outputPanel = containerId + "outputPanel";
+
+ Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
+
+ writeStatus("Mouse click on calendar InputDate field");
+ clickById(calendarInputDate);
+
+ Assert.assertTrue(isVisibleById(calendarOpenedId), "Calendar window should be
visible on the component!");
+
+ writeStatus("Mouse click outside calendar");
+ clickById(outputPanel);
+
+ Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
+
+ writeStatus("Mouse click on calendar popup button");
+ clickById(calendarPopupButton);
+
+ Assert.assertTrue(isVisibleById(calendarOpenedId), "Calendar window should be
visible on the component!");
+ }
+
+ private void _testSelectDateComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+
+ Date newSelectedDate = CalendarTestBean.getDayInMay(15);
+
+ String containerId = getParentId() + "_form:";
+ String calendarOpenedId = containerId + "calendar";
+ String calendarCollapsedId = calendarOpenedId + "Popup";
+ String calendarInputDate = calendarOpenedId + "InputDate";
+ String calendarPopupButton = calendarCollapsedId + "Button";
+ String outputPanel = containerId + "outputPanel";
+
+ Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
+ writeStatus("Mouse click on calendar popup button");
+ clickById(calendarPopupButton);
+ Assert.assertTrue(isVisibleById(calendarOpenedId), "Calendar window should be
visible on the component!");
+
+ String inputDateString = getValueById(calendarInputDate);
+ Date readDate = null;
+ try {
+ readDate = CalendarTestBean.DATE_FORMAT.parse(inputDateString);
+ } catch(ParseException parseException) {
+ // skip exception
+ }
+ Assert.assertEquals(readDate, CalendarTestBean.DEFAULT_DATE, "Default date
representation is wrong!");
+
+ // click on 15th of May
+ String newSelectedDateId = calendarOpenedId + "DayCell18";
+ clickById(newSelectedDateId);
+
+ writeStatus("Mouse click outside calendar");
+ clickById(outputPanel);
+
+ inputDateString = getValueById(calendarInputDate);
+ try {
+ readDate = CalendarTestBean.DATE_FORMAT.parse(inputDateString);
+ } catch(ParseException parseException) {
+ // skip exception
+ }
+ Assert.assertEquals(readDate, newSelectedDate, "Date representation after selecting
15.May.2008 is wrong!");
+
+ Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
+
+
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/calendar/calendarTest.xhtml";
+ }
+}
Property changes on:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/CalendarTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native