static BeanDefinition parseKeyGenerator(Element element, BeanDefinition def) { String name = element.getAttribute("key-generator"); if (StringUtils.hasText(name)) { def.getPropertyValues().add("keyGenerator", new RuntimeBeanReference(name.trim())); } return def; }
@Test public void testServiceFactoryBean() { assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext()); DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class); bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName()); bf.registerBeanDefinition("service", bd); assertTrue(bf.getBean("service") instanceof DocumentBuilderFactory); }
@Test public void testSizeConstraintSatisfied() { GenericApplicationContext ac = new GenericApplicationContext(); ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class)); RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class); bd.getPropertyValues().add("testBean", new TestBean()); bd.getPropertyValues().add("stringValue", "ss"); ac.registerBeanDefinition("bean", bd); ac.refresh(); ac.close(); }
@Test public void testNotNullConstraintAfterInitialization() { GenericApplicationContext ac = new GenericApplicationContext(); RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class); bvpp.getPropertyValues().add("afterInitialization", true); ac.registerBeanDefinition("bvpp", bvpp); ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class)); ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class)); ac.refresh(); ac.close(); }
@Test public void testBindDateTime() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dateTime", new DateTime(2009, 10, 31, 12, 0, ISOChronology.getInstanceUTC())); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("dateTime").toString(); assertTrue(value.startsWith("10/31/09")); }
@Test public void testBindDateTimeAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dateTimeAnnotated", new DateTime(2009, 10, 31, 12, 0, ISOChronology.getInstanceUTC())); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("dateTimeAnnotated").toString(); assertTrue(value.startsWith("Oct 31, 2009")); }
@Test public void testBindDateTimeOverflow() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dateTimeAnnotatedPattern", "02/29/09 12:00 PM"); binder.bind(propertyValues); assertEquals(1, binder.getBindingResult().getErrorCount()); }
@Test public void testBindLocalDateWithSpecificFormatter() { JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar(); registrar.setDateFormatter(org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd")); setup(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDate", "20091031"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("20091031", binder.getBindingResult().getFieldValue("localDate")); }
@Test public void testBindLocalTimeWithSpecificFormatter() { JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar(); registrar.setTimeFormatter(org.joda.time.format.DateTimeFormat.forPattern("HHmmss")); setup(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localTime", "130000"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("130000", binder.getBindingResult().getFieldValue("localTime")); }
@Test public void testBindLocalDateAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateAnnotated", "Oct 31, 2009"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("Oct 31, 2009", binder.getBindingResult().getFieldValue("localDateAnnotated")); }
@Test public void testBindISODate() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("isoDate", "2009-10-31"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("2009-10-31", binder.getBindingResult().getFieldValue("isoDate")); }
@Test public void testBindISOTimeWithZone() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("isoTime", "12:00:00.000-05:00"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("12:00:00", binder.getBindingResult().getFieldValue("isoTime")); }
@Test public void testBindISODateTimeWithZone() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000Z"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("2009-10-31T12:00:00", binder.getBindingResult().getFieldValue("isoDateTime")); }
@Test public void testBindNestedLocalDateAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("children[0].localDateAnnotated", "Oct 31, 2009"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("Oct 31, 2009", binder.getBindingResult().getFieldValue("children[0].localDateAnnotated")); }
@Test public void testBindLocalTimeAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localTimeAnnotated", "12:00:00 PM"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("12:00:00 PM", binder.getBindingResult().getFieldValue("localTimeAnnotated")); }
@Test public void testBindInstantAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("instantAnnotated", "2009-10-31T12:00:00.000Z"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("2009-10-31T07:00:00.000-05:00", binder.getBindingResult().getFieldValue("instantAnnotated")); }
@Test public void testBindLongAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("millisAnnotated", "10/31/09"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("10/31/09", binder.getBindingResult().getFieldValue("millisAnnotated")); }
@Test public void testBindDateAnnotatedPattern() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dateAnnotatedPattern", "10/31/09 1:05"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("10/31/09 1:05", binder.getBindingResult().getFieldValue("dateAnnotatedPattern")); }
@Test public void testBindISOTime() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("isoTime", "12:00:00.000-05:00"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("17:00:00.000Z", binder.getBindingResult().getFieldValue("isoTime")); }
@Test public void testMethodValidationPostProcessor() { StaticApplicationContext ac = new StaticApplicationContext(); ac.registerSingleton("mvpp", MethodValidationPostProcessor.class); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("beforeExistingAdvisors", false); ac.registerSingleton("aapp", AsyncAnnotationBeanPostProcessor.class, pvs); ac.registerSingleton("bean", MyValidBean.class); ac.refresh(); doTestProxyValidation(ac.getBean("bean", MyValidInterface.class)); ac.close(); }