Search in sources :

Example 1 with JodaDateTimeFormatAnnotationFormatterFactory

use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.

the class FormattingConversionServiceTests method formatFieldForAnnotationWithDirectFieldAccess.

@Test
public void formatFieldForAnnotationWithDirectFieldAccess() throws Exception {
    formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
    doTestFormatFieldForAnnotation(Model.class, true);
}
Also used : JodaDateTimeFormatAnnotationFormatterFactory(org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory) Test(org.junit.Test)

Example 2 with JodaDateTimeFormatAnnotationFormatterFactory

use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.

the class FormattingConversionServiceTests method formatFieldForAnnotationWithSubclassAsFieldType.

@Test
public void formatFieldForAnnotationWithSubclassAsFieldType() throws Exception {
    formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory() {

        @Override
        public Printer<?> getPrinter(org.springframework.format.annotation.DateTimeFormat annotation, Class<?> fieldType) {
            assertEquals(MyDate.class, fieldType);
            return super.getPrinter(annotation, fieldType);
        }
    });
    formattingService.addConverter(new Converter<MyDate, Long>() {

        @Override
        public Long convert(MyDate source) {
            return source.getTime();
        }
    });
    formattingService.addConverter(new Converter<MyDate, Date>() {

        @Override
        public Date convert(MyDate source) {
            return source;
        }
    });
    formattingService.convert(new MyDate(), new TypeDescriptor(ModelWithSubclassField.class.getField("date")), TypeDescriptor.valueOf(String.class));
}
Also used : Printer(org.springframework.format.Printer) ReadablePartialPrinter(org.springframework.format.datetime.joda.ReadablePartialPrinter) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) JodaDateTimeFormatAnnotationFormatterFactory(org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory) Test(org.junit.Test)

Example 3 with JodaDateTimeFormatAnnotationFormatterFactory

use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.

the class FormattingConversionServiceTests method formatFieldForAnnotationWithPlaceholders.

@Test
@SuppressWarnings("resource")
public void formatFieldForAnnotationWithPlaceholders() throws Exception {
    GenericApplicationContext context = new GenericApplicationContext();
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Properties props = new Properties();
    props.setProperty("dateStyle", "S-");
    props.setProperty("datePattern", "M-d-yy");
    ppc.setProperties(props);
    context.getBeanFactory().registerSingleton("ppc", ppc);
    context.refresh();
    context.getBeanFactory().initializeBean(formattingService, "formattingService");
    formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
    doTestFormatFieldForAnnotation(ModelWithPlaceholders.class, false);
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) JodaDateTimeFormatAnnotationFormatterFactory(org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with JodaDateTimeFormatAnnotationFormatterFactory

use of org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory in project spring-framework by spring-projects.

the class FormattingConversionServiceTests method formatFieldForAnnotation.

@Test
public void formatFieldForAnnotation() throws Exception {
    formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
    doTestFormatFieldForAnnotation(Model.class, false);
}
Also used : JodaDateTimeFormatAnnotationFormatterFactory(org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 JodaDateTimeFormatAnnotationFormatterFactory (org.springframework.format.datetime.joda.JodaDateTimeFormatAnnotationFormatterFactory)4 Date (java.util.Date)1 Properties (java.util.Properties)1 LocalDate (org.joda.time.LocalDate)1 PropertyPlaceholderConfigurer (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)1 Printer (org.springframework.format.Printer)1 ReadablePartialPrinter (org.springframework.format.datetime.joda.ReadablePartialPrinter)1