@ -12,9 +12,11 @@ import org.joda.time.LocalDateTime;
@@ -12,9 +12,11 @@ import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime ;
import org.junit.After ;
import org.junit.Before ;
import org.junit.Ignore ;
import org.junit.Test ;
import org.springframework.beans.MutablePropertyValues ;
import org.springframework.context.i18n.LocaleContextHolder ;
import org.springframework.ui.format.jodatime.DateTimeFormat.Style ;
import org.springframework.ui.format.support.FormattingConversionService ;
import org.springframework.validation.DataBinder ;
@ -28,10 +30,10 @@ public class JodaTimeFormattingTests {
@@ -28,10 +30,10 @@ public class JodaTimeFormattingTests {
public void setUp ( ) {
JodaTimeFormattingConfigurer configurer = new JodaTimeFormattingConfigurer ( ) ;
configurer . installJodaTimeFormatting ( conversionService ) ;
binder = new DataBinder ( new JodaTimeBean ( ) ) ;
binder . setConversionService ( conversionService ) ;
LocaleContextHolder . setLocale ( Locale . US ) ;
}
@ -46,6 +48,7 @@ public class JodaTimeFormattingTests {
@@ -46,6 +48,7 @@ public class JodaTimeFormattingTests {
propertyValues . addPropertyValue ( "localDate" , "10/31/09" ) ;
binder . bind ( propertyValues ) ;
assertEquals ( 0 , binder . getBindingResult ( ) . getErrorCount ( ) ) ;
assertEquals ( "10/31/09" , binder . getBindingResult ( ) . getFieldValue ( "localDate" ) ) ;
}
@Test
@ -56,22 +59,53 @@ public class JodaTimeFormattingTests {
@@ -56,22 +59,53 @@ public class JodaTimeFormattingTests {
assertEquals ( 0 , binder . getBindingResult ( ) . getErrorCount ( ) ) ;
}
private static class JodaTimeBean {
@Test
@Ignore
public void testBindLocalDateAnnotated ( ) {
MutablePropertyValues propertyValues = new MutablePropertyValues ( ) ;
propertyValues . addPropertyValue ( "localDateAnnotated" , "Oct 31, 2009" ) ;
binder . bind ( propertyValues ) ;
assertEquals ( 0 , binder . getBindingResult ( ) . getErrorCount ( ) ) ;
assertEquals ( "Oct 31, 2009" , binder . getBindingResult ( ) . getFieldValue ( "localDateAnnotated" ) ) ;
}
public static class JodaTimeBean {
private LocalDate localDate ;
@DateTimeFormat ( dateStyle = Style . MEDIUM )
private LocalDate localDateAnnotated ;
private LocalTime localTime ;
@DateTimeFormat ( timeStyle = Style . LONG )
private LocalDate localTimeAnnotated ;
private LocalDateTime localDateTime ;
@DateTimeFormat ( dateStyle = Style . FULL , timeStyle = Style . FULL )
private LocalDateTime localDateTimeAnnotated ;
private DateTime dateTime ;
@DateTimeFormat ( dateStyle = Style . MEDIUM , timeStyle = Style . SHORT )
private LocalDateTime dateTimeAnnotated ;
private Date date ;
@DateTimeFormat ( dateStyle = Style . SHORT )
private Date dateAnnotated ;
private Calendar calendar ;
@DateTimeFormat ( dateStyle = Style . SHORT )
private Calendar calendarAnnotated ;
private Long millis ;
@DateTimeFormat ( dateStyle = Style . SHORT )
private Long millisAnnotated ;
public LocalDate getLocalDate ( ) {
return localDate ;
}
@ -80,6 +114,14 @@ public class JodaTimeFormattingTests {
@@ -80,6 +114,14 @@ public class JodaTimeFormattingTests {
this . localDate = localDate ;
}
public LocalDate getLocalDateAnnotated ( ) {
return localDateAnnotated ;
}
public void setLocalDateAnnotated ( LocalDate localDateAnnotated ) {
this . localDateAnnotated = localDateAnnotated ;
}
public LocalTime getLocalTime ( ) {
return localTime ;
}
@ -88,6 +130,14 @@ public class JodaTimeFormattingTests {
@@ -88,6 +130,14 @@ public class JodaTimeFormattingTests {
this . localTime = localTime ;
}
public LocalDate getLocalTimeAnnotated ( ) {
return localTimeAnnotated ;
}
public void setLocalTimeAnnotated ( LocalDate localTimeAnnotated ) {
this . localTimeAnnotated = localTimeAnnotated ;
}
public LocalDateTime getLocalDateTime ( ) {
return localDateTime ;
}
@ -96,6 +146,14 @@ public class JodaTimeFormattingTests {
@@ -96,6 +146,14 @@ public class JodaTimeFormattingTests {
this . localDateTime = localDateTime ;
}
public LocalDateTime getLocalDateTimeAnnotated ( ) {
return localDateTimeAnnotated ;
}
public void setLocalDateTimeAnnotated ( LocalDateTime localDateTimeAnnotated ) {
this . localDateTimeAnnotated = localDateTimeAnnotated ;
}
public DateTime getDateTime ( ) {
return dateTime ;
}
@ -104,6 +162,14 @@ public class JodaTimeFormattingTests {
@@ -104,6 +162,14 @@ public class JodaTimeFormattingTests {
this . dateTime = dateTime ;
}
public LocalDateTime getDateTimeAnnotated ( ) {
return dateTimeAnnotated ;
}
public void setDateTimeAnnotated ( LocalDateTime dateTimeAnnotated ) {
this . dateTimeAnnotated = dateTimeAnnotated ;
}
public Date getDate ( ) {
return date ;
}
@ -112,6 +178,14 @@ public class JodaTimeFormattingTests {
@@ -112,6 +178,14 @@ public class JodaTimeFormattingTests {
this . date = date ;
}
public Date getDateAnnotated ( ) {
return dateAnnotated ;
}
public void setDateAnnotated ( Date dateAnnotated ) {
this . dateAnnotated = dateAnnotated ;
}
public Calendar getCalendar ( ) {
return calendar ;
}
@ -120,6 +194,14 @@ public class JodaTimeFormattingTests {
@@ -120,6 +194,14 @@ public class JodaTimeFormattingTests {
this . calendar = calendar ;
}
public Calendar getCalendarAnnotated ( ) {
return calendarAnnotated ;
}
public void setCalendarAnnotated ( Calendar calendarAnnotated ) {
this . calendarAnnotated = calendarAnnotated ;
}
public Long getMillis ( ) {
return millis ;
}
@ -128,5 +210,13 @@ public class JodaTimeFormattingTests {
@@ -128,5 +210,13 @@ public class JodaTimeFormattingTests {
this . millis = millis ;
}
public Long getMillisAnnotated ( ) {
return millisAnnotated ;
}
public void setMillisAnnotated ( Long millisAnnotated ) {
this . millisAnnotated = millisAnnotated ;
}
}
}