Search in sources :

Example 1 with FITestBean

use of org.apache.aries.blueprint.pojos.FITestBean in project aries by apache.

the class WiringTest method testFieldInjection.

public void testFieldInjection() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object fiTestBean = repository.create("FITestBean");
    assertNotNull(fiTestBean);
    assertTrue(fiTestBean instanceof FITestBean);
    FITestBean bean = (FITestBean) fiTestBean;
    // single field injection
    assertEquals("value", bean.getAttr());
    // prefer setter injection to field injection
    assertEquals("IS_LOWER", bean.getUpperCaseAttr());
    // support cascaded injection 'bean.name' via fields
    assertEquals("aName", bean.getBeanName());
    // fail if field-injection is not specified
    try {
        repository.create("FIFailureTestBean");
        Assert.fail("Expected exception");
    } catch (ComponentDefinitionException cde) {
    }
    // fail if field-injection is false
    try {
        repository.create("FIFailureTest2Bean");
        Assert.fail("Expected exception");
    } catch (ComponentDefinitionException cde) {
    }
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) BlueprintRepository(org.apache.aries.blueprint.container.BlueprintRepository) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) FITestBean(org.apache.aries.blueprint.pojos.FITestBean) MyObject(org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Aggregations

BlueprintRepository (org.apache.aries.blueprint.container.BlueprintRepository)1 Repository (org.apache.aries.blueprint.di.Repository)1 ComponentDefinitionRegistryImpl (org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)1 FITestBean (org.apache.aries.blueprint.pojos.FITestBean)1 MyObject (org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1