@Test public void testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() { StaticApplicationContext sac = new StaticApplicationContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("proxyObject", "false"); sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs); pvs = new MutablePropertyValues(); pvs.add("singleton", "false"); sac.registerSingleton("prototypeFactoryToBeProxied", DummyFactory.class, pvs); sac.refresh(); TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator"); tapc.testInterceptor.nrOfInvocations = 0; FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied"); assertTrue(AopUtils.isCglibProxy(prototypeFactory)); TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied"); assertFalse(AopUtils.isCglibProxy(tb)); assertEquals(2, tapc.testInterceptor.nrOfInvocations); tb.getAge(); assertEquals(2, tapc.testInterceptor.nrOfInvocations); }
@Test public void testBindWithAlias() throws Exception { VanillaTarget target = new VanillaTarget(); MutablePropertyValues properties = new MutablePropertyValues(); properties.add("flub", "a"); properties.add("foo", "b"); new RelaxedDataBinder(target).withAlias("flub", "fooBaz").bind(properties); assertThat(target.getFooBaz(), equalTo("a")); assertThat(target.getFoo(), equalTo("b")); }
/** * Parse the named reference attribute and make it a property reference value. * * @param element The {@link Element} being parsed. * @param referenceName The name of the reference attribute. * @param propertyName The name of the property to set the references object to * @param properties The properties of the bean definition * @param autowiredType An optional class defining the type to autowire. Use <code>null</code> to * indicate that no autowiring is required. */ private void parseReferenceAttribute( Element element, String referenceName, String propertyName, MutablePropertyValues properties, Class<?> autowiredType) { if (element.hasAttribute(referenceName)) { properties.add(propertyName, new RuntimeBeanReference(element.getAttribute(referenceName))); } else if (autowiredType != null) { properties.add(propertyName, createAutowiredBean(autowiredType)); } }
@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 testBindLocalDateArray() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDate", new String[] {"10/31/09"}); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); }
@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 testBindLocalDateAnnotatedWithError() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateAnnotated", "Oct -31, 2009"); binder.bind(propertyValues); assertEquals(1, binder.getBindingResult().getFieldErrorCount("localDateAnnotated")); assertEquals("Oct -31, 2009", binder.getBindingResult().getFieldValue("localDateAnnotated")); }
@Test public void testBindLocalTimeFromJavaUtilCalendar() throws Exception { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localTime", new GregorianCalendar(1970, 0, 0, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("12:00 PM", binder.getBindingResult().getFieldValue("localTime")); }
@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 testBindPeriod() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("period", "P6Y3M1D"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue(binder.getBindingResult().getFieldValue("period").toString().equals("P6Y3M1D")); }
@Test public void testBindMonthDay() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("monthDay", "--12-03"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue(binder.getBindingResult().getFieldValue("monthDay").toString().equals("--12-03")); }
@Test public void testBindISOTime() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("isoTime", "12:00:00"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("12:00:00", binder.getBindingResult().getFieldValue("isoTime")); }
@Test public void testBindLocalDate() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDate", "10/31/09"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("10/31/09", binder.getBindingResult().getFieldValue("localDate")); }
@Test public void testBindYearMonth() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("yearMonth", "2007-12"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue(binder.getBindingResult().getFieldValue("yearMonth").toString().equals("2007-12")); }
@Test public void testBindInstantFromJavaUtilDate() throws Exception { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("instant", new Date(109, 9, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue( binder.getBindingResult().getFieldValue("instant").toString().startsWith("2009-10-31")); }
@Test public void testBindLocalDateAnnotatedWithDirectFieldAccess() { binder.initDirectFieldAccess(); 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 testBindDateTimeAnnotatedPattern() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("dateTimeAnnotatedPattern", "10/31/09 12:00 PM"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals( "10/31/09 12:00 PM", binder.getBindingResult().getFieldValue("dateTimeAnnotatedPattern")); }
@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 testBindDuration() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("duration", "PT8H6M12.345S"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue( binder.getBindingResult().getFieldValue("duration").toString().equals("PT8H6M12.345S")); }
@Test public void testBindLocalDateTimeFromJavaUtilCalendar() throws Exception { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", new GregorianCalendar(2009, 9, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("10/31/09")); assertTrue(value.endsWith("12:00 PM")); }
@Test public void testBindLocalDateTimeAnnotated() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTimeAnnotated", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString(); assertTrue(value.startsWith("Oct 31, 2009")); assertTrue(value.endsWith("12:00:00 PM")); }
@Test public void testMixed() throws Exception { // gh-3385 VanillaTarget target = new VanillaTarget(); RelaxedDataBinder binder = getBinder(target, "test"); MutablePropertyValues values = new MutablePropertyValues(); values.add("test.FOO_BAZ", "boo"); values.add("test.foo-baz", "bar"); binder.bind(values); assertEquals("boo", target.getFooBaz()); }
@Test public void testBindLocalTimeWithSpecificFormatter() throws Exception { DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); registrar.setTimeFormatter(DateTimeFormatter.ofPattern("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 testBindLocalDateWithSpecificStyle() throws Exception { DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); registrar.setDateStyle(FormatStyle.LONG); setUp(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDate", "October 31, 2009"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("October 31, 2009", binder.getBindingResult().getFieldValue("localDate")); }
@Test public void testBindLocalTimeWithSpecificStyle() throws Exception { DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); registrar.setTimeStyle(FormatStyle.MEDIUM); setUp(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localTime", "12:00:00 PM"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals("12:00:00 PM", binder.getBindingResult().getFieldValue("localTime")); }
@SuppressWarnings("unchecked") public void afterPropertiesSet() { if (this.name == null) { this.name = this.beanName; } if (this.group == null) { this.group = Scheduler.DEFAULT_GROUP; } if (this.applicationContextJobDataKey != null) { if (this.applicationContext == null) { throw new IllegalStateException( "JobDetailBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextJobDataKey'"); } getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext); } /* JobDetailImpl jdi = new JobDetailImpl(); jdi.setName(this.name); jdi.setGroup(this.group); jdi.setJobClass(this.jobClass); jdi.setJobDataMap(this.jobDataMap); this.jobDetail = jdi; */ Class jobDetailClass; try { jobDetailClass = getClass().getClassLoader().loadClass("org.quartz.impl.JobDetailImpl"); } catch (ClassNotFoundException ex) { jobDetailClass = JobDetail.class; } BeanWrapper bw = new BeanWrapperImpl(jobDetailClass); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", this.name); pvs.add("group", this.group); pvs.add("jobClass", this.jobClass); pvs.add("jobDataMap", this.jobDataMap); bw.setPropertyValues(pvs); this.jobDetail = (JobDetail) bw.getWrappedInstance(); }
@Test public void testBindDateTimeWithSpecificStyle() throws Exception { DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); registrar.setDateTimeStyle(FormatStyle.MEDIUM); setUp(registrar); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0)); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); String value = binder.getBindingResult().getFieldValue("localDateTime").toString(); assertTrue(value.startsWith("Oct 31, 2009")); assertTrue(value.endsWith("12:00:00 PM")); }
@Test public void testBindInstant() { MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.add("instant", "2009-10-31T12:00:00.000Z"); binder.bind(propertyValues); assertEquals(0, binder.getBindingResult().getErrorCount()); assertTrue( binder .getBindingResult() .getFieldValue("instant") .toString() .startsWith("2009-10-31T12:00")); }
private void processRepositoryInterface( BeanDefinitionRegistry registry, Class repositoryInterface) { LOG.debug( String.format( "Registering bean definition for repository interface %s", repositoryInterface.getCanonicalName())); String beanName = Introspector.decapitalize(repositoryInterface.getSimpleName()); GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(JpaRepositoryFactoryBean.class); MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); mutablePropertyValues.add("repositoryInterface", repositoryInterface); beanDefinition.setPropertyValues(mutablePropertyValues); registry.registerBeanDefinition(beanName, beanDefinition); }
/** * This overrides the method from WebDataBinder to allow for nested checkbox handling, so property * paths such as a._b will result in the boolean b on object a getting set to false. */ @Override protected void checkFieldMarkers(MutablePropertyValues mpvs) { if (getFieldMarkerPrefix() == null) { return; } String fieldMarkerPrefix = getFieldMarkerPrefix(); PropertyValue[] pvArray = mpvs.getPropertyValues(); for (PropertyValue pv : pvArray) { // start of variation from superclass method if (propertyStartsWithFieldMarkerPrefix(pv, fieldMarkerPrefix)) { String field = stripFieldMarkerPrefix(pv.getName(), fieldMarkerPrefix); // end of variation from superclass method if (getPropertyAccessor().isWritableProperty(field) && !mpvs.contains(field)) { Class<?> fieldType = getPropertyAccessor().getPropertyType(field); mpvs.add(field, getEmptyValue(field, fieldType)); } mpvs.removePropertyValue(pv); } } }