use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class GenericFilterBean method getFilterConfigPropertyValues.
/**
* @param config the FilterConfig we'll use to take PropertyValues from
* @param requiredProperties set of property names we need, where
* we can't accept default values
* @return PropertyValues
* @throws ServletException if any required properties are missing
*/
private PropertyValues getFilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) throws ServletException {
PropertyValues propertyValues = new PropertyValues();
Set<String> missingProps = CollectionUtils.isNotEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null;
Enumeration<String> paramNames = config.getInitParameterNames();
while (paramNames.hasMoreElements()) {
String property = paramNames.nextElement();
Object value = config.getInitParameter(property);
propertyValues.add(new PropertyValue(property, value));
if (missingProps != null) {
missingProps.remove(property);
}
}
// Fail if we are still missing properties.
if (CollectionUtils.isNotEmpty(missingProps)) {
throw new ServletException("Initialization from FilterConfig for filter '" + config.getFilterName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", "));
}
return propertyValues;
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class MixinProxyTargetClassTrueConfig method testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory.
@Test
public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
GenericApplicationContext childAc = new GenericApplicationContext(ac);
// Create a child factory with a bean that should be woven
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.getPropertyValues().add(new PropertyValue("name", "Adrian")).add(new PropertyValue("age", 34));
childAc.registerBeanDefinition("adrian2", bd);
// Register the advisor auto proxy creator with subclass
childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class));
childAc.refresh();
ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2");
// testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian"));
doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class CustomEditorTests method testComplexObjectWithOldValueAccess.
@Test
void testComplexObjectWithOldValueAccess() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.setExtractOldValueForEditor(true);
bw.registerCustomEditor(ITestBean.class, new OldValueAccessingTestBeanEditor());
PropertyValues pvs = new PropertyValues();
pvs.add(new PropertyValue("age", 55));
pvs.add(new PropertyValue("name", newName));
pvs.add(new PropertyValue("touchy", "valid"));
pvs.add(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
ITestBean spouse = tb.getSpouse();
bw.setPropertyValues(pvs);
assertThat(tb.getSpouse()).as("Should have remained same object").isSameAs(spouse);
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class CustomEditorTests method testComplexObject.
@Test
void testComplexObject() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
PropertyValues pvs = new PropertyValues();
pvs.add(new PropertyValue("age", 55));
pvs.add(new PropertyValue("name", newName));
pvs.add(new PropertyValue("touchy", "valid"));
pvs.add(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
}
use of cn.taketoday.beans.PropertyValue in project today-framework by TAKETODAY.
the class JdbcNamespaceIntegrationTests method assertBeanPropertyValueOf.
private void assertBeanPropertyValueOf(String propertyName, String expected, StandardBeanFactory factory) {
BeanDefinition bean = factory.getBeanDefinition(expected);
PropertyValue value = bean.getPropertyValues().get(propertyName);
assertThat(value).isNotNull();
assertThat(value.getValue().toString()).isEqualTo(expected);
}
Aggregations