Author: akushunin
Date: 2007-08-02 11:47:18 -0400 (Thu, 02 Aug 2007)
New Revision: 2017
Modified:
trunk/ui/calendar/
trunk/ui/calendar/src/main/config/component/calendar.xml
trunk/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
trunk/ui/calendar/src/test/java/org/richfaces/component/CurrentDateEventTest.java
Log:
added test for updateCurrentDate and broadcast methods.
added tags for auto test generation.
Property changes on: trunk/ui/calendar
___________________________________________________________________
Name: svn:ignore
- .settings
target
.classpath
.project
bin
+ .settings
target
.classpath
.project
bin
.clover
Modified: trunk/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- trunk/ui/calendar/src/main/config/component/calendar.xml 2007-08-02 15:43:11 UTC (rev
2016)
+++ trunk/ui/calendar/src/main/config/component/calendar.xml 2007-08-02 15:47:18 UTC (rev
2017)
@@ -6,6 +6,10 @@
<family>org.richfaces.Calendar</family>
<classname>org.richfaces.component.html.HtmlCalendar</classname>
<superclass>org.richfaces.component.UICalendar</superclass>
+ <test>
+ <classname>org.richfaces.component.html.HtmlCalendarTest</classname>
+ <superclassname>org.ajax4jsf.tests.AbstractAjax4JsfTestCase</superclassname>
+ </test>
<description>
<![CDATA[
]]>
@@ -20,6 +24,11 @@
<superclass>
org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
</superclass>
+
+ <test>
+ <classname>org.richfaces.component.html.HtmlCalendarTest</classname>
+ <superclassname>org.ajax4jsf.tests.AbstractAjax4JsfTestCase</superclassname>
+ </test>
</tag>
<!--
<taghandler>
Modified:
trunk/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java
===================================================================
---
trunk/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-08-02
15:43:11 UTC (rev 2016)
+++
trunk/ui/calendar/src/test/java/org/richfaces/component/CalendarComponentTest.java 2007-08-02
15:47:18 UTC (rev 2017)
@@ -10,6 +10,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
+import java.util.TimeZone;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlForm;
@@ -17,10 +18,12 @@
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
+import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlScript;
+import com.gargoylesoftware.htmlunit.html.HtmlSpan;
/**
* @author Nick Belaevski - mailto:nbelaevski@exadel.com created 08.06.2007
@@ -54,16 +57,22 @@
form = new HtmlForm();
form.setId("form");
facesContext.getViewRoot().getChildren().add(form);
-
- calendar = (UICalendar) application
- .createComponent(UICalendar.COMPONENT_TYPE);
- calendar.setLocale(Locale.CHINESE);
+ calendar = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE);
+ calendar.setLocale(Locale.UK);
calendar.setDatePattern("d/MM/yyyy");
+ calendar.setTimeZone(TimeZone.getTimeZone("Europe/London"));
+ /*String[] strarr = TimeZone.getAvailableIDs();
+ for(int i=0; i < strarr.length; i++){
+ System.out.println(strarr[i]);
+ } */
+ calendar.setButtonLabel("PopUp");
+ calendar.setPopup(true);
Calendar calendarObject = Calendar.getInstance();
- calendarObject.set(2001, Calendar.SEPTEMBER, 11);
+ calendarObject.set(2001, Calendar.SEPTEMBER, 11,1,1,1);
calendar.setId("calendar");
-
+ calendar.setSubmittedValue(calendarObject.getTime());
form.getChildren().add(calendar);
+
}
@@ -140,24 +149,43 @@
public void testCalendarRenderer() throws Exception {
+/* UIViewRoot root = facesContext.getViewRoot();
+ root.processDecodes(facesContext);
+ root.processValidators(facesContext);
+ root.processUpdates(facesContext);
+ root.processApplication(facesContext);
+*/
HtmlPage page = renderView();
assertNotNull(page);
- // System.out.println(page.asXml());
+ //System.out.println(page.asXml());
+
HtmlElement htmlCalendar =
page.getHtmlElementById(calendar.getClientId(facesContext));
assertNotNull(htmlCalendar);
- System.out.println(htmlCalendar.getAttributeValue("datePattern"));
- //System.out.println(htmlCalendar.getAttributeValue("class"));
-
- htmlCalendar.getAttributeValue("class");
- HtmlInput htmlCalendarInput = (HtmlInput)
page.getHtmlElementById(calendar.getClientId(facesContext)+"PopupInput");
- HtmlElement htmlCalendarButton =
page.getHtmlElementById(calendar.getClientId(facesContext)+"PopupButton");
+
+ HtmlInput htmlCalendarInput = (HtmlInput)
page.getHtmlElementById(calendar.getClientId(facesContext)+"InputDate");
+ HtmlButton htmlCalendarButton = (HtmlButton)
page.getHtmlElementById(calendar.getClientId(facesContext)+"PopupButton");
+ HtmlSpan htmlCalendarSpan =(HtmlSpan)
page.getHtmlElementById(calendar.getClientId(facesContext)+"Popup");
assertNotNull(htmlCalendarInput);
assertNotNull(htmlCalendarButton);
- htmlCalendarInput.setValueAttribute("11/09/2001");
- // assertTrue(htmlCalendarInput.getAttributeValue("class").contains("org.richfaces.component.html.HtmlCalendar"));
- // assertTrue(htmlCalendarButton.getAttributeValue("class").contains("org.richfaces.component.html.HtmlCalendar"));
+ assertNotNull(htmlCalendarSpan);
+
+ assertEquals("10/09/2001", htmlCalendarInput.getValueAttribute());
+
}
+
+ public void testCalendarDecode() throws Exception{
+
+ calendar.decode(facesContext);
+ assertEquals("Tue Sep 11 01:01:01 EEST 2001",
calendar.getSubmittedValue().toString());
+ Calendar calendarObject = Calendar.getInstance();
+ calendarObject.set(2002, Calendar.SEPTEMBER, 11,1,1,1);
+ calendar.updateCurrentDate(facesContext, calendarObject.getTime());
+ assertEquals("Wed Sep 11 01:01:01 EEST 2002",
calendar.getCurrentDate().toString());
+ //assertEquals("11/09/2001", htmlCalendarInput.getValueAttribute());
+
+ }
+
public void testCalendarStyles() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
@@ -177,6 +205,18 @@
for (Iterator it = scripts.iterator(); it.hasNext();) {
HtmlScript item = (HtmlScript) it.next();
String srcAttr = item.getSrcAttribute();
+ if(item.getFirstChild()!=null ){
+ String scriptBodyString = item.getFirstChild().toString();
+ if(scriptBodyString.contains("new Calendar")){
+
+ assertTrue(scriptBodyString.contains("datePattern"));
+ assertTrue(scriptBodyString.contains("d/MM/yyyy"));
+ assertTrue(scriptBodyString.contains("selectedDate"));
+ assertTrue(scriptBodyString.contains("Date(2001,8,11)"));
+ assertTrue(scriptBodyString.contains("popup: true"));
+
+ }
+ }
if (StringUtils.isNotBlank(srcAttr)) {
boolean found = false;
Modified:
trunk/ui/calendar/src/test/java/org/richfaces/component/CurrentDateEventTest.java
===================================================================
---
trunk/ui/calendar/src/test/java/org/richfaces/component/CurrentDateEventTest.java 2007-08-02
15:43:11 UTC (rev 2016)
+++
trunk/ui/calendar/src/test/java/org/richfaces/component/CurrentDateEventTest.java 2007-08-02
15:47:18 UTC (rev 2017)
@@ -23,6 +23,7 @@
import java.util.Calendar;
+import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
/**
@@ -32,6 +33,8 @@
private CurrentDateChangeEvent event1;
private CurrentDateChangeEvent event2;
+ private CurrentDateChangeEvent event4;
+ private AjaxEvent event3;
private UICalendar calendar;
private Calendar cal;
@@ -51,11 +54,13 @@
super.setUp();
calendar = (UICalendar) application.createComponent(UICalendar.COMPONENT_TYPE);;
- event1 = new CurrentDateChangeEvent (calendar, "09/11/2001");
+ event1 = new CurrentDateChangeEvent (calendar, "11/2001");
cal = Calendar.getInstance();
- cal.set(2001, 8, 11);
+ cal.set(2001, 10, 9);
event2 = new CurrentDateChangeEvent (calendar, cal.getTime());
- }
+ event4 = new CurrentDateChangeEvent (calendar, "");
+ event3 = new AjaxEvent(calendar);
+ }
/* (non-Javadoc)
* @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
@@ -69,8 +74,15 @@
public void testEvent() throws Exception {
assertEquals(cal.getTime(), event2.getCurrentDate());
- assertEquals("09/11/2001", event1.getCurrentDateString());
+ assertEquals("11/2001", event1.getCurrentDateString());
}
-
+ public void testBrodcastEvent() throws Exception{
+
+ calendar.broadcast(event1);
+ calendar.broadcast(event3);
+ calendar.broadcast(event4);
+ // calendar.broadcast(event2);
+
+ }
}