use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testAnnotationOrderedResourceInjection.
@Test
public void testAnnotationOrderedResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
IndexedTestBean itb = new IndexedTestBean();
bf.registerSingleton("indexedTestBean", itb);
FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
bf.registerSingleton("nestedTestBean1", ntb1);
FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
bf.registerSingleton("nestedTestBean2", ntb2);
OptionalResourceInjectionBean bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(itb, bean.getIndexedTestBean());
assertEquals(2, bean.getNestedTestBeans().length);
assertSame(ntb2, bean.getNestedTestBeans()[0]);
assertSame(ntb1, bean.getNestedTestBeans()[1]);
assertEquals(2, bean.nestedTestBeansField.length);
assertSame(ntb2, bean.nestedTestBeansField[0]);
assertSame(ntb1, bean.nestedTestBeansField[1]);
bf.destroySingletons();
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testOrderedResourceInjection.
@Test
public void testOrderedResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
IndexedTestBean itb = new IndexedTestBean();
bf.registerSingleton("indexedTestBean", itb);
OrderedNestedTestBean ntb1 = new OrderedNestedTestBean();
ntb1.setOrder(2);
bf.registerSingleton("nestedTestBean1", ntb1);
OrderedNestedTestBean ntb2 = new OrderedNestedTestBean();
ntb2.setOrder(1);
bf.registerSingleton("nestedTestBean2", ntb2);
OptionalResourceInjectionBean bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(itb, bean.getIndexedTestBean());
assertEquals(2, bean.getNestedTestBeans().length);
assertSame(ntb2, bean.getNestedTestBeans()[0]);
assertSame(ntb1, bean.getNestedTestBeans()[1]);
assertEquals(2, bean.nestedTestBeansField.length);
assertSame(ntb2, bean.nestedTestBeansField[0]);
assertSame(ntb1, bean.nestedTestBeansField[1]);
bf.destroySingletons();
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testOptionalResourceInjection.
@Test
public void testOptionalResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
IndexedTestBean itb = new IndexedTestBean();
bf.registerSingleton("indexedTestBean", itb);
NestedTestBean ntb1 = new NestedTestBean();
bf.registerSingleton("nestedTestBean1", ntb1);
NestedTestBean ntb2 = new NestedTestBean();
bf.registerSingleton("nestedTestBean2", ntb2);
OptionalResourceInjectionBean bean = (OptionalResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(itb, bean.getIndexedTestBean());
assertEquals(2, bean.getNestedTestBeans().length);
assertSame(ntb1, bean.getNestedTestBeans()[0]);
assertSame(ntb2, bean.getNestedTestBeans()[1]);
assertEquals(2, bean.nestedTestBeansField.length);
assertSame(ntb1, bean.nestedTestBeansField[0]);
assertSame(ntb2, bean.nestedTestBeansField[1]);
bf.destroySingletons();
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setRawMapPropertyWithNoEditorRegistered.
// must work with raw map in this test
@SuppressWarnings("unchecked")
@Test
public void setRawMapPropertyWithNoEditorRegistered() {
IndexedTestBean target = new IndexedTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
Map inputMap = new HashMap();
inputMap.put(1, "rod");
inputMap.put(2, "rob");
ReadOnlyMap readOnlyMap = new ReadOnlyMap(inputMap);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("map", readOnlyMap);
accessor.setPropertyValues(pvs);
assertSame(readOnlyMap, target.getMap());
assertFalse(readOnlyMap.isAccessed());
}
use of org.springframework.tests.sample.beans.IndexedTestBean in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setCollectionPropertyWithStringValue.
// list cannot be properly parameterized as it breaks other tests
@SuppressWarnings("unchecked")
@Test
public void setCollectionPropertyWithStringValue() {
IndexedTestBean target = new IndexedTestBean();
AbstractPropertyAccessor accessor = createAccessor(target);
List<String> set = new LinkedList<>();
set.add("set1");
accessor.setPropertyValue("set", "set1");
List<String> sortedSet = new ArrayList<>();
sortedSet.add("sortedSet1");
accessor.setPropertyValue("sortedSet", "sortedSet1");
Set<String> list = new HashSet<>();
list.add("list1");
accessor.setPropertyValue("list", "list1");
assertEquals(1, target.getSet().size());
assertTrue(target.getSet().containsAll(set));
assertEquals(1, target.getSortedSet().size());
assertTrue(target.getSortedSet().containsAll(sortedSet));
assertEquals(1, target.getList().size());
assertTrue(target.getList().containsAll(list));
}
Aggregations