use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.
the class CommonAnnotationBeanPostProcessorTests method testExtendedResourceInjection.
@Test
public void testExtendedResourceInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerResolvableDependency(BeanFactory.class, bf);
@SuppressWarnings("deprecation") org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.setProperty("tb", "testBean3");
ppc.setProperties(props);
ppc.postProcessBeanFactory(bf);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ExtendedResourceInjectionBean.class));
bf.registerBeanDefinition("annotatedBean2", new RootBeanDefinition(NamedResourceInjectionBean.class));
bf.registerBeanDefinition("annotatedBean3", new RootBeanDefinition(ConvertedResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
TestBean tb3 = new TestBean();
bf.registerSingleton("testBean3", tb3);
TestBean tb4 = new TestBean();
bf.registerSingleton("testBean4", tb4);
NestedTestBean tb6 = new NestedTestBean();
bf.registerSingleton("value", "5");
bf.registerSingleton("xy", tb6);
bf.registerAlias("xy", "testBean9");
ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
NamedResourceInjectionBean bean2 = (NamedResourceInjectionBean) bf.getBean("annotatedBean2");
assertThat(bean2.testBean).isSameAs(tb6);
ConvertedResourceInjectionBean bean3 = (ConvertedResourceInjectionBean) bf.getBean("annotatedBean3");
assertThat(bean3.value).isSameAs(5);
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.
the class CommonAnnotationBeanPostProcessorTests method testExtendedResourceInjectionWithOverriding.
@Test
public void testExtendedResourceInjectionWithOverriding() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerResolvableDependency(BeanFactory.class, bf);
@SuppressWarnings("deprecation") org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
Properties props = new Properties();
props.setProperty("tb", "testBean3");
ppc.setProperties(props);
ppc.postProcessBeanFactory(bf);
RootBeanDefinition annotatedBd = new RootBeanDefinition(ExtendedResourceInjectionBean.class);
TestBean tb5 = new TestBean();
annotatedBd.getPropertyValues().add("testBean2", tb5);
bf.registerBeanDefinition("annotatedBean", annotatedBd);
bf.registerBeanDefinition("annotatedBean2", new RootBeanDefinition(NamedResourceInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
TestBean tb3 = new TestBean();
bf.registerSingleton("testBean3", tb3);
TestBean tb4 = new TestBean();
bf.registerSingleton("testBean4", tb4);
NestedTestBean tb6 = new NestedTestBean();
bf.registerSingleton("xy", tb6);
ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb5);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
try {
bf.getBean("annotatedBean2");
} catch (BeanCreationException ex) {
boolean condition = ex.getRootCause() instanceof NoSuchBeanDefinitionException;
assertThat(condition).isTrue();
NoSuchBeanDefinitionException innerEx = (NoSuchBeanDefinitionException) ex.getRootCause();
assertThat(innerEx.getBeanName()).isEqualTo("testBean9");
}
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.
the class CommonAnnotationBeanPostProcessorTests method testExtendedEjbInjection.
@Test
public void testExtendedEjbInjection() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerResolvableDependency(BeanFactory.class, bf);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ExtendedEjbInjectionBean.class));
TestBean tb = new TestBean();
bf.registerSingleton("testBean", tb);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
TestBean tb3 = new TestBean();
bf.registerSingleton("testBean3", tb3);
TestBean tb4 = new TestBean();
bf.registerSingleton("testBean4", tb4);
NestedTestBean tb6 = new NestedTestBean();
bf.registerSingleton("xy", tb6);
bf.registerAlias("xy", "testBean9");
ExtendedEjbInjectionBean bean = (ExtendedEjbInjectionBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
use of org.springframework.beans.testfixture.beans.NestedTestBean in project spring-framework by spring-projects.
the class BindTagTests method bindTagWithToStringAndHtmlEscaping.
@Test
void bindTagWithToStringAndHtmlEscaping() throws JspException {
PageContext pc = createPageContext();
BindTag tag = new BindTag();
tag.setPageContext(pc);
tag.setPath("tb.doctor");
tag.setHtmlEscape(true);
TestBean tb = new TestBean("somebody", 99);
NestedTestBean ntb = new NestedTestBean("juergen&eva");
tb.setDoctor(ntb);
pc.getRequest().setAttribute("tb", tb);
tag.doStartTag();
BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
assertThat(status.getExpression()).isEqualTo("doctor");
boolean condition = status.getValue() instanceof NestedTestBean;
assertThat(condition).isTrue();
assertThat(status.getDisplayValue().contains("juergen&eva")).isTrue();
}
Aggregations