Search in sources :

Example 1 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class ExtPlaceholderTest method testStaticValues.

@Test
public void testStaticValues() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-staticvalues.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object obj1 = repository.create("beanD");
    assertNotNull(obj1);
    assertTrue(obj1 instanceof BeanD);
    BeanD beanD = (BeanD) obj1;
    assertEquals(ExtNamespaceHandler.BLUEPRINT_EXT_NAMESPACE_V1_5, beanD.getName());
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) BeanD(org.apache.aries.blueprint.pojos.BeanD) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl) Test(org.junit.Test)

Example 2 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class ReferencesTest method testWiring.

public void testWiring() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-references.xml");
    ProxyManager proxyManager = new AbstractProxyManager() {

        @Override
        protected Object createNewProxy(Bundle bundle, Collection<Class<?>> classes, Callable<Object> objectCallable, InvocationListener invocationListener) throws UnableToProxyException {
            return new Object();
        }

        @Override
        protected InvocationHandler getInvocationHandler(Object o) {
            return null;
        }

        @Override
        protected boolean isProxyClass(Class<?> aClass) {
            return false;
        }
    };
    Repository repository = new TestBlueprintContainer(registry, proxyManager).getRepository();
    repository.create("refItf");
    try {
        repository.create("refClsErr");
        fail("Should have failed");
    } catch (ComponentDefinitionException e) {
    }
    repository.create("refClsOk");
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) AbstractProxyManager(org.apache.aries.proxy.impl.AbstractProxyManager) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) Bundle(org.osgi.framework.Bundle) InvocationListener(org.apache.aries.proxy.InvocationListener) AbstractProxyManager(org.apache.aries.proxy.impl.AbstractProxyManager) ProxyManager(org.apache.aries.proxy.ProxyManager) Collection(java.util.Collection) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl) Callable(java.util.concurrent.Callable)

Example 3 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class WiringTest method testConstructor.

public void testConstructor() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-constructor.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object obj1 = repository.create("pojoA");
    assertNotNull(obj1);
    assertTrue(obj1 instanceof PojoA);
    PojoA pojoa = (PojoA) obj1;
    Object obj2 = repository.create("pojoB");
    testPojoB(obj2, URI.create("urn:myuri"), 10);
    assertEquals(obj2, pojoa.getPojob());
    assertEquals(new BigInteger("10"), pojoa.getNumber());
    Object obj3 = repository.create("pojoC");
    testPojoB(obj3, URI.create("urn:myuri-static"), 15);
    Object obj4 = repository.create("pojoD");
    testPojoB(obj4, URI.create("urn:myuri-static"), 15);
    Object obj5 = repository.create("pojoE");
    testPojoB(obj5, URI.create("urn:myuri-dynamic"), 20);
    Object obj6 = repository.create("multipleInt");
    testMultiple(obj6, null, 123, null);
    Object obj7 = repository.create("multipleInteger");
    testMultiple(obj7, null, -1, new Integer(123));
    Object obj8 = repository.create("multipleString");
    testMultiple(obj8, "123", -1, null);
    // TODO: check the below tests when the incoherence between TCK / spec is solved
    //        try {
    //            graph.create("multipleStringConvertable");
    //            fail("Did not throw exception");
    //        } catch (RuntimeException e) {
    //            // we expect exception
    //        }
    Object obj10 = repository.create("multipleFactory1");
    testMultiple(obj10, null, 1234, null);
    Object obj11 = repository.create("multipleFactory2");
    testMultiple(obj11, "helloCreate-boolean", -1, null);
    try {
        repository.create("multipleFactoryNull");
        fail("Did not throw exception");
    } catch (RuntimeException e) {
    // we expect exception 
    // TODO: check the exception string?
    }
    Object obj12 = repository.create("multipleFactoryTypedNull");
    testMultiple(obj12, "hello-boolean", -1, null);
    Object obj13 = repository.create("mapConstruction");
    Map<String, String> constructionMap = new HashMap<String, String>();
    constructionMap.put("a", "b");
    testMultiple(obj13, constructionMap);
    Object obj14 = repository.create("propsConstruction");
    Properties constructionProperties = new Properties();
    constructionProperties.put("a", "b");
    testMultiple(obj14, constructionProperties);
    Object obja = repository.create("mapConstructionWithDefaultType");
    Map<String, Date> mapa = new HashMap<String, Date>();
    // Months are 0-indexed
    Calendar calendar = new GregorianCalendar(2012, 0, 6);
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
    mapa.put("date", new Date(calendar.getTimeInMillis()));
    testMultiple(obja, mapa);
    Object objc = repository.create("mapConstructionWithTypedEntries");
    Map mapc = new HashMap();
    mapc.put("boolean", Boolean.TRUE);
    mapc.put("double", 1.23);
    mapc.put("date", new Date(calendar.getTimeInMillis()));
    testMultiple(objc, mapc);
    Object objb = repository.create("mapConstructionWithNonDefaultTypedEntries");
    Map mapb = new HashMap();
    mapb.put("boolean", Boolean.TRUE);
    mapb.put("double", 3.45);
    mapb.put("otherdouble", 10.2);
    testMultiple(objb, mapb);
    Object objd = repository.create("mapConstructionWithNonDefaultTypedKeys");
    Map mapd = new HashMap();
    mapd.put(Boolean.TRUE, "boolean");
    mapd.put(42.42, "double");
    testMultiple(objd, mapd);
    BeanF obj15 = (BeanF) repository.create("booleanWrapped");
    assertNotNull(obj15.getWrapped());
    assertEquals(false, (boolean) obj15.getWrapped());
    assertNull(obj15.getPrim());
// TODO: check the below tests when the incoherence between TCK / spec is solved
//        BeanF obj16 = (BeanF) graph.create("booleanPrim");
//        assertNotNull(obj16.getPrim());
//        assertEquals(false, (boolean) obj16.getPrim());
//        assertNull(obj16.getWrapped());
}
Also used : HashMap(java.util.HashMap) PojoA(org.apache.aries.blueprint.pojos.PojoA) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) BeanF(org.apache.aries.blueprint.pojos.BeanF) GregorianCalendar(java.util.GregorianCalendar) Properties(java.util.Properties) Date(java.util.Date) BigInteger(java.math.BigInteger) Repository(org.apache.aries.blueprint.di.Repository) BlueprintRepository(org.apache.aries.blueprint.container.BlueprintRepository) BigInteger(java.math.BigInteger) MyObject(org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class WiringTest method testCompoundProperties.

public void testCompoundProperties() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object obj5 = repository.create("compound");
    assertNotNull(obj5);
    assertTrue(obj5 instanceof PojoB);
    PojoB pojob = (PojoB) obj5;
    assertEquals("hello bean property", pojob.getBean().getName());
    Object obj = repository.create("goodIdRef");
    assertNotNull(obj);
    assertTrue(obj instanceof BeanD);
    BeanD bean = (BeanD) obj;
    assertEquals("pojoA", bean.getName());
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) BlueprintRepository(org.apache.aries.blueprint.container.BlueprintRepository) PojoB(org.apache.aries.blueprint.pojos.PojoB) BeanD(org.apache.aries.blueprint.pojos.BeanD) MyObject(org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Example 5 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class WiringTest method testSetterDisambiguation.

public void testSetterDisambiguation() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    AmbiguousPojo pojo = (AmbiguousPojo) repository.create("ambiguousViaInt");
    assertEquals(5, pojo.getSum());
    pojo = (AmbiguousPojo) repository.create("ambiguousViaList");
    assertEquals(7, pojo.getSum());
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) BlueprintRepository(org.apache.aries.blueprint.container.BlueprintRepository) AmbiguousPojo(org.apache.aries.blueprint.pojos.AmbiguousPojo) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Aggregations

Repository (org.apache.aries.blueprint.di.Repository)14 ComponentDefinitionRegistryImpl (org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)12 BlueprintRepository (org.apache.aries.blueprint.container.BlueprintRepository)8 MyObject (org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject)6 HashMap (java.util.HashMap)4 BigInteger (java.math.BigInteger)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Recipe (org.apache.aries.blueprint.di.Recipe)2 BeanD (org.apache.aries.blueprint.pojos.BeanD)2 PojoA (org.apache.aries.blueprint.pojos.PojoA)2 PojoB (org.apache.aries.blueprint.pojos.PojoB)2 SimpleBean (org.apache.aries.blueprint.pojos.SimpleBean)2 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)2 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 List (java.util.List)1