use of cn.taketoday.beans.PropertyValue in project today-infrastructure 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-infrastructure by TAKETODAY.
the class ViewResolverTests method beanNameViewResolver.
@Test
public void beanNameViewResolver() {
PropertyValues pvs1 = new PropertyValues();
pvs1.add(new PropertyValue("url", "/example1.jsp"));
this.wac.registerSingleton("example1", InternalResourceView.class, pvs1);
PropertyValues pvs2 = new PropertyValues();
pvs2.add(new PropertyValue("url", "/example2.jsp"));
this.wac.registerSingleton("example2", JstlView.class, pvs2);
BeanNameViewResolver vr = new BeanNameViewResolver();
vr.setApplicationContext(this.wac);
this.wac.refresh();
View view = vr.resolveViewName("example1", Locale.getDefault());
assertThat(view.getClass()).as("Correct view class").isEqualTo(InternalResourceView.class);
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("/example1.jsp");
view = vr.resolveViewName("example2", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("/example2.jsp");
}
use of cn.taketoday.beans.PropertyValue in project today-infrastructure 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-infrastructure 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-infrastructure by TAKETODAY.
the class AnnotationJmxAttributeSource method getManagedResource.
@Override
@Nullable
public cn.taketoday.jmx.export.metadata.ManagedResource getManagedResource(Class<?> beanClass) throws InvalidMetadataException {
MergedAnnotation<ManagedResource> ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY).get(ManagedResource.class).withNonMergedAttributes();
if (!ann.isPresent()) {
return null;
}
Class<?> declaringClass = (Class<?>) ann.getSource();
Class<?> target = (declaringClass != null && !declaringClass.isInterface() ? declaringClass : beanClass);
if (!Modifier.isPublic(target.getModifiers())) {
throw new InvalidMetadataException("@ManagedResource class '" + target.getName() + "' must be public");
}
cn.taketoday.jmx.export.metadata.ManagedResource bean = new cn.taketoday.jmx.export.metadata.ManagedResource();
Map<String, Object> map = ann.asMap();
List<PropertyValue> list = new ArrayList<>(map.size());
map.forEach((attrName, attrValue) -> {
if (!"value".equals(attrName)) {
Object value = attrValue;
if (this.embeddedValueResolver != null && value instanceof String) {
value = this.embeddedValueResolver.resolveStringValue((String) value);
}
list.add(new PropertyValue(attrName, value));
}
});
BeanWrapper.forBeanPropertyAccess(bean).setPropertyValues(new PropertyValues(list));
return bean;
}
Aggregations