Search in sources :

Example 6 with BeanMetadataImpl

use of org.apache.aries.blueprint.reflect.BeanMetadataImpl in project geronimo-xbean by apache.

the class RestaurantUsingBlueprintTest method testPizza.

public void testPizza() throws Exception {
    BeanMetadataImpl restaurant = (BeanMetadataImpl) reg.getComponentDefinition("restaurant");
    BeanProperty prop = propertyByName("serviceName", restaurant);
    BeanMetadataImpl qname = (BeanMetadataImpl) prop.getValue();
    assertEquals(3, qname.getArguments().size());
    assertEquals("http://acme.com", ((ValueMetadataImpl) qname.getArguments().get(0).getValue()).getStringValue());
    assertEquals("xyz", ((ValueMetadataImpl) qname.getArguments().get(1).getValue()).getStringValue());
    assertEquals("foo", ((ValueMetadataImpl) qname.getArguments().get(2).getValue()).getStringValue());
    // dinners (1-many using list)
    BeanProperty dinnerProp = propertyByName("dinnerMenu", restaurant);
    List<Metadata> dinners = ((CollectionMetadata) dinnerProp.getValue()).getValues();
    assertNotNull("dinners is null!", dinners);
    assertEquals("dinners size: " + dinners, 2, dinners.size());
    BeanMetadataImpl pizza = (BeanMetadataImpl) dinners.get(0);
    checkPropertyValue("topping", "Ham", pizza);
    checkPropertyValue("cheese", "Mozzarella", pizza);
    // TODO blueprint int value
    checkPropertyValue("size", "15", pizza);
    pizza = (BeanMetadataImpl) dinners.get(1);
    checkPropertyValue("topping", "Eggs", pizza);
    checkPropertyValue("cheese", "Mozzarella", pizza);
    // TODO blueprint int value
    checkPropertyValue("size", "16", pizza);
    // dinners (1-many using Set)
    BeanProperty snackProp = propertyByName("snackMenu", restaurant);
    List<Metadata> snacks = ((CollectionMetadata) snackProp.getValue()).getValues();
    assertNotNull("dinners is null!", snacks);
    assertEquals("dinners size: " + snacks, 2, snacks.size());
    for (Metadata snackMeta : snacks) {
        BeanMetadataImpl snack = (BeanMetadataImpl) snackMeta;
        BeanProperty toppingProp = propertyByName("topping", snack);
        String topping = ((ValueMetadataImpl) toppingProp.getValue()).getStringValue();
        if ("Tofu".equals(topping)) {
            checkPropertyValue("cheese", "Parmesan", snack);
            checkPropertyValue("size", "6", snack);
        } else if ("Prosciutto".equals(topping)) {
            checkPropertyValue("cheese", "Blue", snack);
            checkPropertyValue("size", "8", snack);
        } else {
            fail("wrong topping: " + snackMeta);
        }
    }
    // lunches (1-many using array)
    CollectionMetadataImpl lunches = (CollectionMetadataImpl) propertyByName("lunchMenu", restaurant).getValue();
    assertNotNull("lunches is null!", lunches);
    assertEquals("lunches size: " + lunches, 1, lunches.getValues().size());
    pizza = (BeanMetadataImpl) lunches.getValues().get(0);
    checkPropertyValue("topping", "Chicken", pizza);
    checkPropertyValue("cheese", "Brie", pizza);
    checkPropertyValue("size", "17", pizza);
    // favourite (1-1)
    BeanProperty favourite = propertyByName("favourite", restaurant);
    pizza = (BeanMetadataImpl) favourite.getValue();
    assertNotNull("Pizza is null!", pizza);
    // pizza.makePizza();
    // 
    checkPropertyValue("topping", "Salami", pizza);
    checkPropertyValue("cheese", "Edam", pizza);
    checkPropertyValue("size", "17", pizza);
}
Also used : BeanMetadataImpl(org.apache.aries.blueprint.reflect.BeanMetadataImpl) ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadataImpl(org.apache.aries.blueprint.reflect.CollectionMetadataImpl) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 7 with BeanMetadataImpl

use of org.apache.aries.blueprint.reflect.BeanMetadataImpl in project geronimo-xbean by apache.

the class QNameUsingBlueprintTest method testQName.

public void testQName() throws Exception {
    BeanMetadataImpl svc = (BeanMetadataImpl) reg.getComponentDefinition("qnameService");
    List<Metadata> services = ((CollectionMetadataImpl) propertyByName("services", svc).getValue()).getValues();
    assertNotNull(services);
    assertEquals(2, services.size());
    checkQName("urn:foo", "test", services.get(0));
    checkQName("urn:foo", "bar", services.get(1));
    List<Metadata> list = ((CollectionMetadataImpl) propertyByName("list", svc).getValue()).getValues();
    assertNotNull(list);
    assertEquals(1, list.size());
    checkQName("urn:foo", "list", list.get(0));
}
Also used : BeanMetadataImpl(org.apache.aries.blueprint.reflect.BeanMetadataImpl) Metadata(org.osgi.service.blueprint.reflect.Metadata) CollectionMetadataImpl(org.apache.aries.blueprint.reflect.CollectionMetadataImpl)

Example 8 with BeanMetadataImpl

use of org.apache.aries.blueprint.reflect.BeanMetadataImpl in project geronimo-xbean by apache.

the class BeerNullTest method testBeer.

public void testBeer() throws Exception {
    BeanMetadataImpl meta = (BeanMetadataImpl) reg.getComponentDefinition("beerService");
    checkPropertyValue("name", "Stella", meta);
    checkPropertyValue("id", "123", meta);
    // no property set since this is the default
    // checkPropertyValue("source", "tap", meta);
    BeanMetadataImpl meta2 = (BeanMetadataImpl) reg.getComponentDefinition("beerService2");
    checkPropertyValue("name", "Blue Moon", meta2);
    checkPropertyValue("id", "123", meta2);
    assertTrue(propertyByName("source", meta2).getValue() instanceof NullMetadata);
}
Also used : BeanMetadataImpl(org.apache.aries.blueprint.reflect.BeanMetadataImpl) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata)

Example 9 with BeanMetadataImpl

use of org.apache.aries.blueprint.reflect.BeanMetadataImpl in project geronimo-xbean by apache.

the class WineUsingBlueprintTest method testWine.

public void testWine() throws Exception {
    BeanMetadataImpl meta = (BeanMetadataImpl) reg.getComponentDefinition("wineService");
    checkArgumentValue(1, "Amarone", meta, false);
    checkArgumentValue(0, "wineService", meta, false);
}
Also used : BeanMetadataImpl(org.apache.aries.blueprint.reflect.BeanMetadataImpl)

Example 10 with BeanMetadataImpl

use of org.apache.aries.blueprint.reflect.BeanMetadataImpl in project geronimo-xbean by apache.

the class SocketAddressBlueprintTest method testSocketService.

public void testSocketService() throws Exception {
    BeanMetadataImpl socketService = (BeanMetadataImpl) reg.getComponentDefinition("socketService");
    // System.out.println();
    // System.out.println("===========================");
    // System.out.println(socketService.getAddresses());
    // System.out.println("===========================");
    // System.out.println();
    // List<InetSocketAddress> expected = Arrays.asList(new InetSocketAddress("localhost", 42), new InetSocketAddress("localhost", 42));
    assertEquals(1, socketService.getProperties().size());
    CollectionMetadata collection = (CollectionMetadata) socketService.getProperties().get(0).getValue();
    assertEquals(2, collection.getValues().size());
}
Also used : BeanMetadataImpl(org.apache.aries.blueprint.reflect.BeanMetadataImpl) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata)

Aggregations

BeanMetadataImpl (org.apache.aries.blueprint.reflect.BeanMetadataImpl)18 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)4 CollectionMetadataImpl (org.apache.aries.blueprint.reflect.CollectionMetadataImpl)3 RefMetadataImpl (org.apache.aries.blueprint.reflect.RefMetadataImpl)3 BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)3 Metadata (org.osgi.service.blueprint.reflect.Metadata)3 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)2 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)1 NamespaceHandlerSet (org.apache.aries.blueprint.parser.NamespaceHandlerSet)1 IdRefMetadataImpl (org.apache.aries.blueprint.reflect.IdRefMetadataImpl)1