Search in sources :

Example 1 with ILazyInitProxy

use of org.apache.wicket.proxy.ILazyInitProxy in project wicket by apache.

the class AnnotProxyFieldValueFactoryTest method testFactory.

/**
 * Test the factory
 *
 * @throws Exception
 */
@Test
public void testFactory() throws Exception {
    SpringBeanLocator locator;
    Object proxy;
    Field field = obj.getClass().getDeclaredField("nobean");
    proxy = factory.getFieldValue(field, obj);
    assertNull(proxy);
    field = obj.getClass().getDeclaredField("beanByClass");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator) ((ILazyInitProxy) proxy).getObjectLocator();
    assertTrue(locator.getBeanType().equals(Bean.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertThat(factory.getFieldValue(field, obj), instanceOf(ILazyInitProxy.class));
    field = obj.getClass().getDeclaredField("beanByName");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator) ((ILazyInitProxy) proxy).getObjectLocator();
    assertTrue(locator.getBeanName().equals("somebean"));
    assertTrue(locator.getBeanType().equals(Bean2.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertThat(factory.getFieldValue(field, obj), instanceOf(ILazyInitProxy.class));
}
Also used : Field(java.lang.reflect.Field) SpringBeanLocator(org.apache.wicket.spring.SpringBeanLocator) Bean2(org.apache.wicket.spring.injection.util.Bean2) ILazyInitProxy(org.apache.wicket.proxy.ILazyInitProxy) Bean(org.apache.wicket.spring.injection.util.Bean) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 ILazyInitProxy (org.apache.wicket.proxy.ILazyInitProxy)1 SpringBeanLocator (org.apache.wicket.spring.SpringBeanLocator)1 Bean (org.apache.wicket.spring.injection.util.Bean)1 Bean2 (org.apache.wicket.spring.injection.util.Bean2)1 Test (org.junit.Test)1