Search in sources :

Example 1 with Bean

use of org.apache.wicket.spring.Bean in project wicket by apache.

the class AnnotatedFieldInBehaviorPage method beanExistsDifferentName.

/**
 * @throws Exception
 */
@Test
public void beanExistsDifferentName() throws Exception {
    // add dependency beans of the same type
    ctx.putBean("mrBean", new Bean());
    ctx.putBean("theBean", new Bean());
    // with no name specified we get IllegalStateException
    try {
        tester.startPage(new AnnotatedBeanRequired());
        fail();
    } catch (IllegalStateException e) {
    }
    // we must inject bean with name "mrBean"
    AnnotatedBeanNotRequiredDifferentName page;
    tester.startPage(page = new AnnotatedBeanNotRequiredDifferentName());
    SpringBeanLocator locator = (SpringBeanLocator) ((ILazyInitProxy) page.getBean()).getObjectLocator();
    assertTrue(locator.getBeanName().equals("mrBean"));
}
Also used : SpringBeanLocator(org.apache.wicket.spring.SpringBeanLocator) Bean(org.apache.wicket.spring.Bean) Test(org.junit.Test)

Example 2 with Bean

use of org.apache.wicket.spring.Bean in project wicket by apache.

the class AnnotatedFieldInBehaviorPage method beanInjectedInBehavior.

/**
 * https://issues.apache.org/jira/browse/WICKET-4149
 */
@Test
public void beanInjectedInBehavior() {
    ctx.putBean("mrBean", new Bean());
    // with no name specified we get IllegalStateException
    Page page = tester.startPage(new AnnotatedFieldInBehaviorPage());
    TestBehavior behavior = page.getBehaviors(TestBehavior.class).get(0);
    assertNotNull(behavior.getBean());
}
Also used : DummyHomePage(org.apache.wicket.util.tester.DummyHomePage) Page(org.apache.wicket.Page) Bean(org.apache.wicket.spring.Bean) Test(org.junit.Test)

Example 3 with Bean

use of org.apache.wicket.spring.Bean in project wicket by apache.

the class AnnotatedFieldInBehaviorPage method beanExists.

/**
 * @throws Exception
 */
@Test
public void beanExists() throws Exception {
    // add dependency bean
    ctx.putBean("bean", new Bean());
    AnnotatedBeanRequired page;
    // first test with standard behavior (required = true)
    tester.startPage(page = new AnnotatedBeanRequired());
    assertNotNull(page.getBean());
    // now test with required = false
    AnnotatedBeanNotRequired notRequiredpage;
    tester.startPage(notRequiredpage = new AnnotatedBeanNotRequired());
    assertNotNull(notRequiredpage.getBean());
    // both page must have the same bean instance
    assertTrue(page.getBean() == notRequiredpage.getBean());
}
Also used : Bean(org.apache.wicket.spring.Bean) Test(org.junit.Test)

Aggregations

Bean (org.apache.wicket.spring.Bean)3 Test (org.junit.Test)3 Page (org.apache.wicket.Page)1 SpringBeanLocator (org.apache.wicket.spring.SpringBeanLocator)1 DummyHomePage (org.apache.wicket.util.tester.DummyHomePage)1