Author: andrei_exadel
Date: 2008-12-02 12:09:06 -0500 (Tue, 02 Dec 2008)
New Revision: 11494
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarDataModel.java
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml
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:
RF-5148,RF-5149
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarDataModel.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarDataModel.java
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarDataModel.java 2008-12-02
17:09:06 UTC (rev 11494)
@@ -0,0 +1,76 @@
+/**
+ *
+ */
+package org.ajax4jsf.bean;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.richfaces.model.CalendarDataModelItem;
+
+/**
+ * @author Andrey Markavtsov
+ *
+ */
+public class CalendarDataModel implements org.richfaces.model.CalendarDataModel {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.CalendarDataModel#getData(java.util.Date[])
+ */
+ public CalendarDataModelItem[] getData(Date[] dateArray) {
+ CalendarDataModelItem[] items = new CalendarDataModelItemImpl[dateArray.length];
+ for (int i = 0;i < items.length; i++) {
+ items[i] = new CalendarDataModelItemImpl(dateArray[i]);
+ }
+ return items;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.CalendarDataModel#getToolTip(java.util.Date)
+ */
+ public Object getToolTip(Date date) {
+ return null;
+ }
+
+}
+
+class CalendarDataModelItemImpl implements CalendarDataModelItem {
+
+ int day;
+ Object data;
+
+ public CalendarDataModelItemImpl(Date date) {
+ Map<String, String> data = new HashMap<String, String>();
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+ day = c.get(Calendar.DAY_OF_MONTH);
+ this.data = data;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public int getDay() {
+ return day;
+ }
+
+ public String getStyleClass() {
+ return null;
+ }
+
+ public Object getToolTip() {
+ return null;
+ }
+
+ public boolean hasToolTip() {
+ return false;
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+}
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-02
16:29:39 UTC (rev 11493)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/CalendarTestBean.java 2008-12-02
17:09:06 UTC (rev 11494)
@@ -29,8 +29,16 @@
import java.util.TimeZone;
import javax.faces.convert.DateTimeConverter;
+import javax.faces.event.ValueChangeEvent;
+import org.richfaces.component.UICalendar;
+import org.richfaces.event.CurrentDateChangeEvent;
+
public class CalendarTestBean {
+
+ public static final String valueChangeListener = "valueChangeListener";
+
+ public static final String currentDateChangeListener =
"currentDateChangeListener";
public static final String DATE_PATTERN = "MM/dd/yyyy HH:mm";
@@ -60,6 +68,12 @@
private String selectedDateString;
+ private CalendarDataModel model;
+
+ private String mode = UICalendar.AJAX_MODE;
+
+ private String status;
+
public CalendarTestBean() {
selectedDate = DEFAULT_DATE;
resetSelectedDateString();
@@ -167,4 +181,52 @@
// skip exception
}
}
+
+ public void valueChangeListener(ValueChangeEvent event) {
+ status = getStatus() + valueChangeListener;
+ }
+
+ public void currectDateChangeListener(CurrentDateChangeEvent event) {
+ status = getStatus() + currentDateChangeListener;
+ }
+
+ public String testClientMode() {
+ mode = UICalendar.CLIENT_MODE;
+ return null;
+ }
+
+ public void reset() {
+ mode = UICalendar.AJAX_MODE;
+ status = "";
+ selectedDate = new Date();
+ }
+
+ public String resetAction() {
+ reset();
+ return null;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getMode() {
+ return mode;
+ }
+
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
+
+ public CalendarDataModel getModel() {
+ return model;
+ }
+
+ public void setModel(CalendarDataModel model) {
+ this.model = model;
+ }
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml 2008-12-02
16:29:39 UTC (rev 11493)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/WEB-INF/faces-config.xml 2008-12-02
17:09:06 UTC (rev 11494)
@@ -186,8 +186,18 @@
<managed-bean-name>calendarBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.CalendarTestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
+ <managed-property>
+ <property-name>model</property-name>
+ <property-class>org.ajax4jsf.bean.CalendarDataModel</property-class>
+ <value>#{calendarDataModel}</value>
+ </managed-property>
</managed-bean>
<managed-bean>
+ <managed-bean-name>calendarDataModel</managed-bean-name>
+ <managed-bean-class>org.ajax4jsf.bean.CalendarDataModel</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
<managed-bean-name>formBean</managed-bean-name>
<managed-bean-class>org.ajax4jsf.bean.A4JFormTestBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
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-02
16:29:39 UTC (rev 11493)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/CalendarTest.java 2008-12-02
17:09:06 UTC (rev 11494)
@@ -32,81 +32,203 @@
public class CalendarTest extends SeleniumTestBase {
- @Test
- public void testCalendarComponent(Template template) {
- renderPage(template);
+ static final String RESET_METHOD = "#{calendarBean.reset}";
- String containerId = getParentId() + "_form:";
- String calendarOpenedId = containerId + "calendar";
- String calendarCollapsedId = calendarOpenedId + "Popup";
- String calendarInputDate = calendarOpenedId + "InputDate";
- String calendarPopupButton = calendarCollapsedId + "Button";
- String outputPanel = containerId + "outputPanel";
+ 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;
+ String ajaxSubmitId;
+ String serverSubmitId;
+ String statusId;
+ String resetActionId;
+ String testClientModeId;
- Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
+ void initIds(String parentId) {
+ calendarId = parentId + FORM_ID + "calendar";
+ calendarHeaderId = calendarId + "Header";
+ 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";
+ }
- writeStatus("Mouse click on calendar InputDate field");
- clickById(calendarInputDate);
+ String getStatus() {
+ return getTextById(statusId);
+ }
+
+ void assertListeners(String... listener) {
+ String status = getStatus();
+ String s = status;
+ String sum = "";
+ for (String l : listener) {
+ if (status.indexOf(l) == -1) {
+ Assert.fail(l + " has been skipped");
+ } else {
+ s = s.replace(l, "");
+ }
+ sum += l;
+ }
+ if (s.length() > 0) {
+ Assert.fail("The following listener were called but shouldn't: "
+ + s);
+ }
+ if (!status.equals(sum)) {
+ Assert.fail("Order of listeners call is incorrect. Should be: "
+ + sum + ". But was : " + status);
+ }
+ }
- Assert.assertTrue(isVisibleById(calendarOpenedId), "Calendar window should be
visible on the component!");
+ void changeDate() {
+ String weekNumId = calendarId + "WeekNum2";
+ selenium.click("//tr[@id='"+weekNumId+"']/td[@class='"+availableDayCellClass+"']");
+ }
+
+ void changeCurrentDate(boolean wait4ajax) {
+ selenium.click("//td[@id='"+calendarHeaderId+"']/table/tbody/tr/td/div");
+ if (wait4ajax) {
+ waitForAjaxCompletion();
+ }
+ }
+
+ void reset() {
+ clickCommandAndWait(resetActionId);
+ }
+
+ void switchToClientMode() {
+ clickCommandAndWait(testClientModeId);
+ }
+
+ @Test
+ public void testListenersInAjaxMode(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId());
- writeStatus("Mouse click outside calendar");
- clickById(outputPanel);
+ changeDate();
+
+ clickAjaxCommandAndWait(ajaxSubmitId);
+ assertListeners(CalendarTestBean.valueChangeListener);
+
+ reset();
+
+ changeCurrentDate(true);
+ changeDate();
+ clickAjaxCommandAndWait(ajaxSubmitId);
+ assertListeners(CalendarTestBean.valueChangeListener,
CalendarTestBean.currentDateChangeListener);
+
+ }
+
+
+ @Test
+ public void testListenersInClientMode(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId());
+ switchToClientMode();
+
+ changeDate();
+
+ clickCommandAndWait(serverSubmitId);
+ assertListeners(CalendarTestBean.valueChangeListener);
+
+ reset();
+ switchToClientMode();
+
+ changeCurrentDate(false);
+ changeDate();
+ clickCommandAndWait(serverSubmitId);
+ assertListeners(CalendarTestBean.valueChangeListener,
CalendarTestBean.currentDateChangeListener);
+
+ }
- Assert.assertFalse(isVisibleById(calendarOpenedId), "Calendar window should NOT be
visible on the component!");
- writeStatus("Mouse click on calendar popup button");
- clickById(calendarPopupButton);
+ // @Test
+ public void testCalendarComponent(Template template) {
+ renderPage(template);
- Assert.assertTrue(isVisibleById(calendarOpenedId), "Calendar window should be
visible on the component!");
- }
+ String containerId = getParentId() + "_form:";
+ String calendarOpenedId = containerId + "calendar";
+ String calendarCollapsedId = calendarOpenedId + "Popup";
+ String calendarInputDate = calendarOpenedId + "InputDate";
+ String calendarPopupButton = calendarCollapsedId + "Button";
+ String outputPanel = containerId + "outputPanel";
- @Test
- public void testSelectDateComponent(Template template) {
- renderPage(template);
+ Assert.assertFalse(isVisibleById(calendarOpenedId),
+ "Calendar window should NOT be visible on the component!");
- Date newSelectedDate = CalendarTestBean.getDayInMay(15);
+ writeStatus("Mouse click on calendar InputDate field");
+ clickById(calendarInputDate);
- 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.assertTrue(isVisibleById(calendarOpenedId),
+ "Calendar window should be visible on the component!");
- 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!");
+ writeStatus("Mouse click outside calendar");
+ clickById(outputPanel);
- String inputDateString = getValueById(calendarInputDate);
- Date readDate = null;
- try {
- readDate = CalendarTestBean.DATE_FORMAT.parse(inputDateString);
- } catch(ParseException parseException) {
- // skip exception
+ 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!");
}
- Assert.assertEquals(readDate, CalendarTestBean.DEFAULT_DATE, "Default date
representation is wrong!");
- // click on 15th of May
- String newSelectedDateId = calendarOpenedId + "DayCell18";
- clickById(newSelectedDateId);
+ // @Test
+ public void testSelectDateComponent(Template template) {
+ renderPage(template);
- writeStatus("Mouse click outside calendar");
- clickById(outputPanel);
+ Date newSelectedDate = CalendarTestBean.getDayInMay(15);
- inputDateString = getValueById(calendarInputDate);
- try {
- readDate = CalendarTestBean.DATE_FORMAT.parse(inputDateString);
- } catch(ParseException parseException) {
- // skip exception
+ 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!");
}
- 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 "pages/calendar/calendarTest.xhtml";
- }
+ public String getTestUrl() {
+ return "pages/calendar/calendarTest.xhtml";
+ }
}
Show replies by date