aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r1075094 [14/17] - in /aries/tags/blueprint-0.1-incubating: ./ blueprint-api/ blueprint-api/src/ blueprint-api/src/main/ blueprint-api/src/main/appended-resources/ blueprint-api/src/main/appended-resources/META-INF/ blueprint-api/src/main/j...
Date Sun, 27 Feb 2011 17:47:18 GMT
Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd Sun Feb 27 17:47:08 2011
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<xsd:schema xmlns="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+            xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            targetNamespace="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+            elementFormDefault="qualified"
+            attributeFormDefault="unqualified"
+            version="1.0.0">
+
+    <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0"/>
+
+    <!-- property placeholder -->
+
+    <xsd:element name="property-placeholder" type="TpropertyPlaceholder"/>
+
+    <xsd:complexType name="TpropertyPlaceholder">
+        <xsd:complexContent>
+            <xsd:extension base="bp:Tcomponent">
+                <xsd:sequence>
+                    <!-- nested properties declaration -->
+                    <xsd:element name="default-properties" type="TdefaultProperties" minOccurs="0" maxOccurs="1"/>
+                    <xsd:element name="location" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/>
+                </xsd:sequence>
+                <xsd:attribute name="placeholder-prefix" type="xsd:string" use="optional" default="${"/>
+                <xsd:attribute name="placeholder-suffix" type="xsd:string" use="optional" default="}"/>
+                <xsd:attribute name="defaults-ref" type="bp:Tidref" use="optional"/>
+                <xsd:attribute name="ignore-missing-locations" type="xsd:boolean" use="optional" default="false"/>
+                <xsd:attribute name="system-properties" use="optional" default="fallback">
+                    <xsd:simpleType>
+                        <xsd:restriction base="xsd:NMTOKEN">
+                            <xsd:enumeration value="never"/>
+                            <xsd:enumeration value="fallback"/>
+                            <xsd:enumeration value="override"/>
+                        </xsd:restriction>
+                    </xsd:simpleType>
+                </xsd:attribute>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+
+    <xsd:complexType name="TdefaultProperties">
+        <xsd:sequence minOccurs="0" maxOccurs="unbounded">
+            <xsd:element name="property" type="bp:Tproperty"/>
+        </xsd:sequence>
+    </xsd:complexType>
+
+    <!-- proxy method -->
+
+    <xsd:attribute name="proxy-method" default="default">
+        <xsd:simpleType>
+            <xsd:restriction>
+                <xsd:simpleType>
+                    <xsd:list>
+                        <xsd:simpleType>
+                            <xsd:restriction base="xsd:NMTOKEN">
+                                <xsd:enumeration value="default"/>
+                                <xsd:enumeration value="classes"/>
+                                <xsd:enumeration value="greedy"/>
+                            </xsd:restriction>
+                        </xsd:simpleType>
+                    </xsd:list>
+                </xsd:simpleType>
+                <xsd:minLength value="1"/>
+            </xsd:restriction>
+        </xsd:simpleType>
+    </xsd:attribute>
+
+    <!-- role -->
+
+    <xsd:attribute name="role">
+        <xsd:simpleType>
+            <xsd:restriction>
+                <xsd:simpleType>
+                    <xsd:list>
+                        <xsd:simpleType>
+                            <xsd:restriction base="xsd:NMTOKEN">
+                                <xsd:enumeration value="processor"/>
+                            </xsd:restriction>
+                        </xsd:simpleType>
+                    </xsd:list>
+                </xsd:simpleType>
+            </xsd:restriction>
+        </xsd:simpleType>
+    </xsd:attribute>
+
+    <!-- CM property placeholder extenstion -->
+
+    <xsd:element name="location" type="xsd:string"/>
+    <xsd:attribute name="ignore-missing-locations" type="xsd:boolean" default="false"/>
+    <xsd:attribute name="system-properties" default="fallback">
+        <xsd:simpleType>
+            <xsd:restriction base="xsd:NMTOKEN">
+                <xsd:enumeration value="never"/>
+                <xsd:enumeration value="fallback"/>
+                <xsd:enumeration value="override"/>
+            </xsd:restriction>
+        </xsd:simpleType>
+    </xsd:attribute>
+    
+    <xsd:attribute name="field-injection" type="xsd:boolean" default="false" />
+
+</xsd:schema>

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/AbstractBlueprintTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.xml.validation.Schema;
+
+import junit.framework.TestCase;
+
+import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
+import org.apache.aries.blueprint.container.Parser;
+import org.apache.aries.blueprint.ext.ExtNamespaceHandler;
+import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.xml.sax.SAXException;
+
+public abstract class AbstractBlueprintTest extends TestCase {
+
+    protected ComponentDefinitionRegistryImpl parse(String name) throws Exception {
+      final URI extensionHandler = new URI("http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0");
+      NamespaceHandlerRegistry.NamespaceHandlerSet handlers = new NamespaceHandlerRegistry.NamespaceHandlerSet() {
+            public Set<URI> getNamespaces() {
+                return null;
+            }
+            public NamespaceHandler getNamespaceHandler(URI namespace) {
+                if (namespace.equals(extensionHandler)) {
+                  return new ExtNamespaceHandler();
+                } else {
+                  return null;
+                }
+            }
+            public void removeListener(NamespaceHandlerRegistry.Listener listener) {
+            }
+            public Schema getSchema() throws SAXException, IOException {
+                return null;
+            }
+            public boolean isComplete() {
+                return false;
+            }
+            public void addListener(NamespaceHandlerRegistry.Listener listener) {
+            }
+            public void destroy() {
+            }
+        };
+        return parse(name, handlers);
+    }
+
+    protected ComponentDefinitionRegistryImpl parse(String name, NamespaceHandlerRegistry.NamespaceHandlerSet handlers) throws Exception {
+        ComponentDefinitionRegistryImpl registry = new ComponentDefinitionRegistryImpl();
+        Parser parser = new Parser();
+        parser.parse(Collections.singletonList(getClass().getResource(name)));
+        parser.populate(handlers, registry);
+        return registry;
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/CallbackTracker.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/CallbackTracker.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/CallbackTracker.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/CallbackTracker.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CallbackTracker {
+
+    private static List<Callback> callbacks = new ArrayList<Callback>();
+    
+    public static void add(Callback callback) {
+        callbacks.add(callback);
+    }
+    
+    public static List<Callback> getCallbacks() {
+        return callbacks;
+    }
+    
+    public static void clear() {
+        callbacks.clear();
+    }
+    
+    public static class Callback {
+        
+        public static int INIT = 1;
+        public static int DESTROY = 2;
+        
+        private Object object;
+        private int type;
+        
+        public Callback(int type, Object object) {
+            this.type = type;
+            this.object = object;
+        }        
+        
+        public int getType() {
+            return type;
+        }
+        
+        public Object getObject() {
+            return object;
+        }
+        
+        public String toString() {
+            return type + " " + object;
+        }
+        
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ParserTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.io.IOException;
+
+import javax.xml.validation.Schema;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.aries.blueprint.container.NamespaceHandlerRegistry;
+import org.apache.aries.blueprint.reflect.BeanMetadataImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.service.blueprint.reflect.BeanArgument;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.CollectionMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+import org.osgi.service.blueprint.reflect.NullMetadata;
+import org.osgi.service.blueprint.reflect.RefMetadata;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+import org.xml.sax.SAXException;
+
+/**
+ * TODO: constructor injection
+ * TODO: Dependency#setMethod 
+ */
+public class ParserTest extends AbstractBlueprintTest {
+
+    public void test() {
+        Integer[] oo = new Integer[1];
+        Object[] ii = oo;
+    }
+
+    public void testParseComponent() throws Exception {
+        ComponentDefinitionRegistry registry = parse("/test-simple-component.xml");
+        assertNotNull(registry);
+        ComponentMetadata component = registry.getComponentDefinition("pojoA");
+        assertNotNull(component);
+        assertEquals("pojoA", component.getId());
+        assertTrue(component instanceof BeanMetadata);
+        BeanMetadata local = (BeanMetadata) component;
+        List<String> deps = local.getDependsOn();
+        assertNotNull(deps);
+        assertEquals(2, deps.size());
+        assertTrue(deps.contains("pojoB"));
+        assertTrue(deps.contains("pojoC"));
+        assertEquals("org.apache.aries.blueprint.pojos.PojoA", local.getClassName());
+        List<BeanArgument> params = local.getArguments();
+        assertNotNull(params);
+        assertEquals(6, params.size());
+        BeanArgument param = params.get(0);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertNull(param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof ValueMetadata);
+        assertEquals("val0", ((ValueMetadata) param.getValue()).getStringValue());
+        assertNull(((ValueMetadata) param.getValue()).getType());
+        param = params.get(1);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertNull(param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof RefMetadata);
+        assertEquals("val1", ((RefMetadata) param.getValue()).getComponentId());
+        param = params.get(2);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertNull(param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof NullMetadata);
+        param = params.get(3);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertEquals("java.lang.String", param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof ValueMetadata);
+        assertEquals("val3", ((ValueMetadata) param.getValue()).getStringValue());
+        assertNull(((ValueMetadata) param.getValue()).getType());
+        param = params.get(4);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertNull(param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof CollectionMetadata);
+        CollectionMetadata array = (CollectionMetadata) param.getValue();
+        assertNull(array.getValueType());
+        assertNotNull(array.getValues());
+        assertEquals(3, array.getValues().size());
+        assertTrue(array.getValues().get(0) instanceof ValueMetadata);
+        assertTrue(array.getValues().get(1) instanceof ComponentMetadata);
+        assertTrue(array.getValues().get(2) instanceof NullMetadata);
+        param = params.get(5);
+        assertNotNull(param);
+        assertEquals(-1, param.getIndex());
+        assertNull(param.getValueType());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof RefMetadata);
+        assertEquals("pojoB", ((RefMetadata) param.getValue()).getComponentId());
+        
+        assertEquals(null, local.getInitMethod());
+        assertEquals(null, local.getDestroyMethod());
+                
+        // test pojoB
+        ComponentMetadata pojoB = registry.getComponentDefinition("pojoB");
+        assertNotNull(pojoB);
+        assertEquals("pojoB", pojoB.getId());
+        assertTrue(pojoB instanceof BeanMetadata);
+        BeanMetadata pojoBLocal = (BeanMetadata) pojoB;
+        assertEquals("initPojo", pojoBLocal.getInitMethod());
+//        assertEquals("", pojoBLocal.getDestroyMethod());
+        
+        params = pojoBLocal.getArguments();
+        assertNotNull(params);
+        assertEquals(2, params.size());
+        param = params.get(0);
+        assertNotNull(param);
+        assertEquals(1, param.getIndex());
+        param = params.get(1);
+        assertNotNull(param);
+        assertEquals(0, param.getIndex());
+    }
+
+    public void testParse() throws Exception {
+        parse("/test.xml");
+    }
+
+
+    public void testCustomNodes() throws Exception {
+        ComponentDefinitionRegistry registry = parse("/test-custom-nodes.xml", new TestNamespaceHandlerSet());
+        
+        ComponentMetadata metadata;
+        
+        metadata = registry.getComponentDefinition("fooService");
+        assertNotNull(metadata);
+        assertTrue(metadata instanceof MyLocalComponentMetadata);
+        MyLocalComponentMetadata comp1 = (MyLocalComponentMetadata) metadata;
+        assertEquals(true, comp1.getCacheReturnValues());
+        assertEquals("getVolatile", comp1.getOperation());
+        
+        metadata = registry.getComponentDefinition("barService");
+        assertNotNull(metadata);
+        assertTrue(metadata instanceof BeanMetadata);
+        BeanMetadata comp2 = (BeanMetadata) metadata;
+        assertEquals(1, comp2.getProperties().size());
+        BeanProperty propertyMetadata = comp2.getProperties().get(0);
+        assertEquals("localCache", propertyMetadata.getName());
+        Metadata propertyValue = propertyMetadata.getValue();
+        assertTrue(propertyValue instanceof BeanMetadata);
+        BeanMetadata innerComp = (BeanMetadata) propertyValue;
+        assertEquals("org.apache.aries.CacheProperty", innerComp.getClassName()); 
+        
+        metadata = registry.getComponentDefinition("myCache");
+        assertNotNull(metadata);
+        assertTrue(metadata instanceof BeanMetadata);
+        BeanMetadata comp3 = (BeanMetadata) metadata;
+        assertEquals("org.apache.aries.Cache", comp3.getClassName());         
+    }
+
+    private static class TestNamespaceHandlerSet implements NamespaceHandlerRegistry.NamespaceHandlerSet {
+
+        private TestNamespaceHandlerSet() {
+        }
+
+        public Set<URI> getNamespaces() {
+            return Collections.singleton(URI.create("http://cache.org"));
+        }
+
+        public boolean isComplete() {
+            return true;
+        }
+
+        public NamespaceHandler getNamespaceHandler(URI namespace) {
+            URI u = URI.create("http://cache.org");
+            if (u.equals(namespace)) {
+                return new TestNamespaceHandler();
+            } else {
+                return null;
+            }
+        }
+
+        public Schema getSchema() throws SAXException, IOException {
+            return null;
+        }
+
+        public void addListener(NamespaceHandlerRegistry.Listener listener) {
+        }
+
+        public void removeListener(NamespaceHandlerRegistry.Listener listener) {
+        }
+
+        public void destroy() {
+        }
+    }
+
+    private static class TestNamespaceHandler implements NamespaceHandler {
+
+        public URL getSchemaLocation(String namespace) {
+            return getClass().getResource("/cache.xsd");
+        }
+
+        public Set<Class> getManagedClasses() {
+            return new HashSet<Class>();
+        }
+
+        public ComponentMetadata decorate(Node node,
+                                          ComponentMetadata component,
+                                          ParserContext context) {
+            //System.out.println("decorate: " + node + " " + component + " " + container.getEnclosingComponent().getId());
+            
+            if (node instanceof Attr) {
+                Attr attr = (Attr) node;
+                MyLocalComponentMetadata decoratedComp = new MyLocalComponentMetadata((BeanMetadata)component);
+                decoratedComp.setCacheReturnValues(Boolean.parseBoolean(attr.getValue()));
+                return decoratedComp;
+            } else if (node instanceof Element) {
+                Element element = (Element) node;                
+                MyLocalComponentMetadata decoratedComp = (MyLocalComponentMetadata) component;
+                decoratedComp.setOperation(element.getAttribute("name"));
+                return decoratedComp;
+            } else {
+                throw new RuntimeException("Unhandled node: " + node);
+            }
+        }
+
+        public Metadata parse(Element element, ParserContext context) {
+            String comp = (context.getEnclosingComponent() == null) ? null : context.getEnclosingComponent().getId();
+            //System.out.println("parse: " + element.getLocalName() + " " + comp);
+            
+            String className;
+            if (context.getEnclosingComponent() == null) {
+                className = "org.apache.aries.Cache";
+            } else {
+                className = "org.apache.aries.CacheProperty";
+            }
+                        
+            BeanMetadataImpl p = new BeanMetadataImpl();
+            p.setId(element.getAttribute("id"));
+            p.setClassName(className);
+            
+            return p;
+        }
+        
+    }
+    
+    private static class MyLocalComponentMetadata extends BeanMetadataImpl {
+        
+        private boolean cacheReturnValues;
+        private String operation;
+        
+        public MyLocalComponentMetadata(BeanMetadata impl) {
+            super(impl);
+        }
+        
+        public boolean getCacheReturnValues() {
+            return cacheReturnValues;
+        }
+        
+        public void setCacheReturnValues(boolean value) {
+            cacheReturnValues = value;
+        }
+        
+        public void setOperation(String operation) {
+            this.operation = operation;
+        }
+        
+        public String getOperation() {
+            return this.operation;
+        }
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBlueprintContainer.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import org.apache.aries.blueprint.container.BlueprintContainerImpl;
+import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.aries.blueprint.reflect.PassThroughMetadataImpl;
+
+public class TestBlueprintContainer extends BlueprintContainerImpl {
+
+    private ComponentDefinitionRegistryImpl registry;
+    
+    public TestBlueprintContainer(ComponentDefinitionRegistryImpl registry) {
+        super(new TestBundleContext(), null, null, null, null, null);
+        this.registry = registry;
+        if (registry != null) {
+            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintContainer", this));
+            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundle", getBundleContext().getBundle()));
+            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintBundleContext", getBundleContext()));
+            registry.registerComponentDefinition(new PassThroughMetadataImpl("blueprintConverter", getConverter()));
+        }
+    }
+
+    @Override
+    public Class loadClass(String name) throws ClassNotFoundException {
+        return Thread.currentThread().getContextClassLoader().loadClass(name);
+    }
+
+    @Override
+    public ComponentDefinitionRegistryImpl getComponentDefinitionRegistry() {
+        return registry;
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBundleContext.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBundleContext.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBundleContext.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/TestBundleContext.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class TestBundleContext implements BundleContext {
+
+    public void addBundleListener(BundleListener arg0) {
+    }
+
+    public void addFrameworkListener(FrameworkListener arg0) {
+    }
+
+    public void addServiceListener(ServiceListener arg0) {
+    }
+
+    public void addServiceListener(ServiceListener arg0, String arg1)
+        throws InvalidSyntaxException {
+    }
+
+    public Filter createFilter(String arg0) throws InvalidSyntaxException {
+        return null;
+    }
+
+    public ServiceReference[] getAllServiceReferences(String arg0, String arg1)
+        throws InvalidSyntaxException {
+        return null;
+    }
+
+    public Bundle getBundle() {
+        return null;
+    }
+
+    public Bundle getBundle(long arg0) {
+        return null;
+    }
+
+    public Bundle[] getBundles() {
+        return null;
+    }
+
+    public File getDataFile(String arg0) {
+        return null;
+    }
+
+    public String getProperty(String arg0) {
+        return null;
+    }
+
+    public Object getService(ServiceReference arg0) {
+        return null;
+    }
+
+    public ServiceReference getServiceReference(String arg0) {
+        return null;
+    }
+
+    public ServiceReference[] getServiceReferences(String arg0, String arg1)
+    throws InvalidSyntaxException {
+        return null;
+    }
+
+    public Bundle installBundle(String arg0) throws BundleException {
+        return null;
+    }
+
+    public Bundle installBundle(String arg0, InputStream arg1) throws BundleException {
+        return null;
+    }
+
+    public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
+        return null;
+    }
+
+    public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
+        return null;
+    }
+
+    public void removeBundleListener(BundleListener arg0) {
+    }
+
+    public void removeFrameworkListener(FrameworkListener arg0) {
+    }
+
+    public void removeServiceListener(ServiceListener arg0) {
+    }
+
+    public boolean ungetService(ServiceReference arg0) {
+        return false;
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/WiringTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,457 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint;
+
+import java.math.BigInteger;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.aries.blueprint.CallbackTracker.Callback;
+import org.apache.aries.blueprint.container.BlueprintRepository;
+import org.apache.aries.blueprint.di.CircularDependencyException;
+import org.apache.aries.blueprint.di.Repository;
+import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
+import org.apache.aries.blueprint.pojos.BeanD;
+import org.apache.aries.blueprint.pojos.BeanF;
+import org.apache.aries.blueprint.pojos.FITestBean;
+import org.apache.aries.blueprint.pojos.Multiple;
+import org.apache.aries.blueprint.pojos.PojoA;
+import org.apache.aries.blueprint.pojos.PojoB;
+import org.apache.aries.blueprint.pojos.PojoGenerics;
+import org.apache.aries.blueprint.pojos.PojoListener;
+import org.apache.aries.blueprint.pojos.PojoRecursive;
+import org.apache.aries.blueprint.pojos.Primavera;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+public class WiringTest extends AbstractBlueprintTest {
+
+    public void testWiring() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
+        Repository repository = new TestBlueprintContainer(registry).getRepository();
+        
+        Object obj1 = repository.create("pojoA");
+        assertNotNull(obj1);
+        assertTrue(obj1 instanceof PojoA);
+        PojoA pojoa = (PojoA) obj1;
+        // test singleton scope
+        assertTrue(obj1 == repository.create("pojoA"));
+        
+        Object obj2 = repository.create("pojoB");
+        assertNotNull(obj2);
+        assertTrue(obj2 instanceof PojoB);
+        PojoB pojob = (PojoB) obj2;
+        
+        assertNotNull(pojoa.getPojob());
+        assertNotNull(pojoa.getPojob().getUri());
+        
+        assertNotNull(pojoa.getList());
+        assertEquals("list value", pojoa.getList().get(0));
+        assertEquals(new Integer(55), pojoa.getList().get(2));
+        assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getList().get(3));
+        Object c0 = pojoa.getList().get(1);
+        Object c1 = pojoa.getList().get(4);
+        assertNotNull(c0);
+        assertNotNull(c1);
+        assertEquals(PojoB.class, c0.getClass());
+        assertEquals(PojoB.class, c1.getClass());
+        assertNotSame(c0, c1);
+
+        assertNotNull(pojoa.getArray());
+        assertEquals("list value", pojoa.getArray()[0]);
+        assertEquals(pojob, pojoa.getArray()[1]);
+        assertEquals(new Integer(55), pojoa.getArray()[2]);
+        assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getArray()[3]);
+        
+        assertNotNull(pojoa.getSet());
+        assertTrue(pojoa.getSet().contains("set value"));
+        assertTrue(pojoa.getSet().contains(pojob));
+        assertTrue(pojoa.getSet().contains(URI.create("http://geronimo.apache.org")));
+        
+        assertNotNull(pojoa.getMap());
+        assertEquals("val", pojoa.getMap().get("key"));
+        assertEquals(pojob, pojoa.getMap().get(pojob));      
+        assertEquals(URI.create("http://geronimo.apache.org"), pojoa.getMap().get(new Integer(5)));
+        
+        assertNotNull(pojoa.getProps());
+        assertEquals("value1", pojoa.getProps().get("key1"));
+        assertEquals("value2", pojoa.getProps().get("2"));
+        assertEquals("bar", pojoa.getProps().get("foo"));
+        
+        assertNotNull(pojoa.getNumber());
+        assertEquals(new BigInteger("10"), pojoa.getNumber());
+        
+        assertNotNull(pojoa.getIntArray());
+        assertEquals(3, pojoa.getIntArray().length);
+        assertEquals(1, pojoa.getIntArray()[0]);
+        assertEquals(50, pojoa.getIntArray()[1]);
+        assertEquals(100, pojoa.getIntArray()[2]);
+        
+        assertNotNull(pojoa.getNumberArray());
+        assertEquals(4, pojoa.getNumberArray().length);
+        assertEquals(new Integer(1), pojoa.getNumberArray()[0]);
+        assertEquals(new BigInteger("50"), pojoa.getNumberArray()[1]);
+        assertEquals(new Long(100), pojoa.getNumberArray()[2]);
+        assertEquals(new Integer(200), pojoa.getNumberArray()[3]);
+        
+        // test init-method
+        assertEquals(true, pojob.getInitCalled());
+        
+        // test service
+        Object obj3 = repository.create("service1");
+        assertNotNull(obj3);
+        assertTrue(obj3 instanceof ServiceRegistration);    
+        
+        // tests 'prototype' scope
+        Object obj4 = repository.create("pojoC");
+        assertNotNull(obj4);
+        
+        assertTrue(obj4 != repository.create("pojoC"));
+        
+        repository.destroy();
+        
+        // test destroy-method
+        assertEquals(true, pojob.getDestroyCalled());
+    }
+    
+    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) {}
+    }
+    
+    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());
+    }
+
+    public void testIdRefs() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-bad-id-ref.xml");
+
+        try {
+            new TestBlueprintContainer(registry).getRepository();
+            fail("Did not throw exception");
+        } catch (RuntimeException e) {
+            // we expect exception
+            // TODO: check error string?
+        }
+    }
+    
+    public void testDependencies() throws Exception {
+        CallbackTracker.clear();
+
+        ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml");
+        Repository repository = new TestBlueprintContainer(registry).getRepository();
+        Map instances = repository.createAll(Arrays.asList("c", "d", "e"));
+        
+        List<Callback> callback = CallbackTracker.getCallbacks();
+        assertEquals(3, callback.size());
+        checkInitCallback(instances.get("d"), callback.get(0));
+        checkInitCallback(instances.get("c"), callback.get(1));
+        checkInitCallback(instances.get("e"), callback.get(2));
+                
+        repository.destroy();
+        
+        assertEquals(6, callback.size());
+        checkDestroyCallback(instances.get("e"), callback.get(3));
+        checkDestroyCallback(instances.get("c"), callback.get(4));
+        checkDestroyCallback(instances.get("d"), callback.get(5));
+    }
+
+    private void checkInitCallback(Object obj, Callback callback) { 
+        assertEquals(Callback.INIT, callback.getType());
+        assertEquals(obj, callback.getObject());
+    }
+    
+    private void checkDestroyCallback(Object obj, Callback callback) { 
+        assertEquals(Callback.DESTROY, callback.getType());
+        assertEquals(obj, callback.getObject());
+    }
+    
+    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);
+
+        // TODO: check the below tests when the incoherence between TCK / spec is solved
+//        Object obj13 = graph.create("mapConstruction");
+//        Object obj14 = graph.create("propsConstruction");
+
+        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());
+    }
+    
+    private void testPojoB(Object obj, URI uri, int intValue) {
+        assertNotNull(obj);
+        assertTrue(obj instanceof PojoB);
+        PojoB pojob = (PojoB) obj;
+        assertEquals(uri, pojob.getUri());
+        assertEquals(intValue, pojob.getNumber());
+    }
+    
+    private void testMultiple(Object obj, String stringValue, int intValue, Integer integerValue) {
+        assertNotNull(obj);
+        assertTrue(obj instanceof Multiple);
+        assertEquals(intValue, ((Multiple)obj).getInt());
+        assertEquals(stringValue, ((Multiple)obj).getString());
+        assertEquals(integerValue, ((Multiple)obj).getInteger());        
+    }
+
+    public void testGenerics() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-generics.xml");
+        Repository repository = new TestBlueprintContainer(registry).getRepository();
+
+        List<Integer> expectedList = new ArrayList<Integer>();
+        expectedList.add(new Integer(10));
+        expectedList.add(new Integer(20));
+        expectedList.add(new Integer(50));
+        
+        Set<Long> expectedSet = new HashSet<Long>();
+        expectedSet.add(new Long(1000));
+        expectedSet.add(new Long(2000));
+        expectedSet.add(new Long(5000));
+        
+        Map<Short, Boolean> expectedMap = new HashMap<Short, Boolean>();
+        expectedMap.put(new Short((short)1), Boolean.TRUE);
+        expectedMap.put(new Short((short)2), Boolean.FALSE);
+        expectedMap.put(new Short((short)5), Boolean.TRUE);
+        
+        Object obj;
+        PojoGenerics pojo;
+        
+        obj = repository.create("method");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedList, pojo.getList());
+        assertEquals(expectedSet, pojo.getSet());
+        assertEquals(expectedMap, pojo.getMap());
+        
+        obj = repository.create("constructorList");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedList, pojo.getList());
+        
+        obj = repository.create("constructorSet");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedSet, pojo.getSet());
+        
+        obj = repository.create("constructorMap");
+        assertTrue(obj instanceof PojoGenerics);
+        pojo = (PojoGenerics) obj;
+        
+        assertEquals(expectedMap, pojo.getMap());
+        
+        obj = repository.create("genericPojo");
+        assertTrue(obj instanceof Primavera);
+        assertEquals("string", ((Primavera) obj).prop);
+        
+        obj = repository.create("doubleGenericPojo");
+        assertTrue(obj instanceof Primavera);
+        assertEquals("stringToo", ((Primavera) obj).prop);
+    }
+    
+    public void testCircular() throws Exception {
+        BlueprintRepository repository = createBlueprintContainer().getRepository();
+
+        // this should pass (we allow circular dependencies for components without init method)
+        Object obj1 = repository.create("a");
+                
+        // test service and listener circular dependencies
+        Object obj2 = repository.create("service");
+        assertNotNull(obj2);
+        assertTrue(obj2 instanceof ServiceRegistration);
+        
+        Object obj3 = repository.create("listener");
+        assertNotNull(obj3);
+        assertTrue(obj3 instanceof PojoListener);
+        
+        assertEquals(obj2, ((PojoListener) obj3).getService() );        
+    }
+     
+    public void testCircularPrototype() throws Exception {
+        BlueprintRepository repository = createBlueprintContainer().getRepository();
+        
+        try {
+            repository.create("circularPrototypeDriver");
+            fail("Did not throw exception");  
+        } catch (CircularDependencyException e) {
+            // that's what we expect
+        }
+
+        try {
+            repository.create("circularPrototype");
+            fail("Did not throw exception");  
+        } catch (CircularDependencyException e) {
+            // that's what we expect
+        }
+    }
+    
+    public void testRecursive() throws Exception {
+        BlueprintRepository repository = createBlueprintContainer().getRepository();
+        
+        try {
+            repository.create("recursiveConstructor");
+            fail("Did not throw exception");           
+        } catch (ComponentDefinitionException e) {
+            if (e.getCause() instanceof CircularDependencyException) {                          
+                // that's what we expect
+            } else {
+                fail("Did not throw expected exception");
+                throw e;
+            }
+        }
+        
+        PojoRecursive pojo;
+        
+        pojo = (PojoRecursive) repository.create("recursiveSetter");
+        assertNotNull(pojo);
+                           
+        pojo = (PojoRecursive) repository.create("recursiveInitMethod");
+        assertNotNull(pojo);
+    }
+    
+    public void testCircularBreaking() throws Exception {
+        BlueprintRepository repository;
+        
+        repository = createBlueprintContainer().getRepository();        
+        assertNotNull(repository.create("c1"));
+        
+        repository = createBlueprintContainer().getRepository();        
+        assertNotNull(repository.create("c2"));
+        
+        repository = createBlueprintContainer().getRepository();        
+        assertNotNull(repository.create("c3"));
+    }
+    
+    private TestBlueprintContainer createBlueprintContainer() throws Exception {
+        ComponentDefinitionRegistryImpl registry = parse("/test-circular.xml");
+        return new TestBlueprintContainer(registry);
+    }
+    
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AbstractServiceReferenceTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AbstractServiceReferenceTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AbstractServiceReferenceTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AbstractServiceReferenceTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.container;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+import static org.junit.Assert.*;
+
+import org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe.CgLibProxyFactory;
+import org.junit.Test;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+
+public class AbstractServiceReferenceTest {
+    @Test
+    public void testCglibProxySingleTargetClass() {
+        CgLibProxyFactory sut = new CgLibProxyFactory();
+        Class<?> result = sut.getTargetClass(new Class<?>[] {ArrayList.class});
+        assertEquals(ArrayList.class, result);
+    }
+    
+    @Test
+    public void testCglibProxyMultipleTargetClasses() {
+        CgLibProxyFactory sut = new CgLibProxyFactory();
+        Class<?> result = sut.getTargetClass(new Class<?>[] {AbstractList.class, ArrayList.class});
+        assertEquals(ArrayList.class, result);
+        
+        result = sut.getTargetClass(new Class<?>[] {ArrayList.class, AbstractList.class});
+        assertEquals(ArrayList.class, result);
+    }
+    
+    @Test(expected=ComponentDefinitionException.class)
+    public void testCglibProxyIncompatibleTargetClasses() {
+        CgLibProxyFactory sut = new CgLibProxyFactory();
+        sut.getTargetClass(new Class<?>[] {LinkedList.class, ArrayList.class});        
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AggregateConverterTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AggregateConverterTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AggregateConverterTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/AggregateConverterTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.container;
+
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+import org.apache.aries.blueprint.TestBlueprintContainer;
+import org.osgi.service.blueprint.container.ReifiedType;
+import org.osgi.service.blueprint.container.Converter;
+
+public class AggregateConverterTest extends TestCase {
+
+    private AggregateConverter service;
+
+    protected void setUp() {
+        service = new AggregateConverter(new TestBlueprintContainer(null));
+    }
+
+    public void testConvertNumbers() throws Exception {
+        assertEquals(1, service.convert(1.46f, int.class));
+        assertEquals(1.0d, service.convert(1, double.class));
+    }
+
+    public void testConvertSimpleTypes() throws Exception {
+        assertEquals(123, service.convert("123", int.class));
+        assertEquals(123, service.convert("123", Integer.class));
+        assertEquals(123l, service.convert("123", long.class));
+        assertEquals(123l, service.convert("123", Long.class));
+        assertEquals((short) 123, service.convert("123", short.class));
+        assertEquals((short) 123, service.convert("123", Short.class));
+        assertEquals(1.5f, service.convert("1.5", float.class));
+        assertEquals(1.5f, service.convert("1.5", Float.class));
+        assertEquals(1.5, service.convert("1.5", double.class));
+        assertEquals(1.5, service.convert("1.5", Double.class));
+    }
+
+    public void testConvertCharacter() throws Exception {
+        assertEquals('c', service.convert("c", char.class));
+        assertEquals('c', service.convert("c", Character.class));
+        assertEquals('\u00F6', service.convert("\\u00F6", char.class));
+        assertEquals('\u00F6', service.convert("\\u00F6", Character.class));
+    }
+
+    public void testConvertBoolean() throws Exception {
+        assertEquals(Boolean.TRUE, service.convert("true", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("yes", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("on", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("TRUE", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("YES", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("ON", Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("true", boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("yes", boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("on", boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("TRUE", boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("YES", boolean.class));
+        assertEquals(Boolean.TRUE, service.convert("ON", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("false", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("no", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("off", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("FALSE", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("NO", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("OFF", Boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("false", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("no", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("off", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("FALSE", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("NO", boolean.class));
+        assertEquals(Boolean.FALSE, service.convert("OFF", boolean.class));
+        
+        assertEquals(Boolean.FALSE, service.convert(false, boolean.class));
+        assertEquals(Boolean.TRUE, service.convert(true, boolean.class));        
+        assertEquals(Boolean.FALSE, service.convert(false, Boolean.class));
+        assertEquals(Boolean.TRUE, service.convert(true, Boolean.class));
+    }
+
+    public void testConvertOther() throws Exception {
+        assertEquals(URI.create("urn:test"), service.convert("urn:test", URI.class));
+        assertEquals(new URL("file:/test"), service.convert("file:/test", URL.class));
+        assertEquals(new BigInteger("12345"), service.convert("12345", BigInteger.class));
+    }
+
+    public void testConvertProperties() throws Exception {
+        Properties props = new Properties();
+        props.setProperty("key", "value");
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        props.store(baos, null);
+        props = (Properties) service.convert(baos.toString(), Properties.class);
+        assertEquals(1, props.size());
+        assertEquals("value", props.getProperty("key"));
+    }
+
+    public void testConvertLocale() throws Exception {
+        Object result;
+        result = service.convert("en", Locale.class);
+        assertTrue(result instanceof Locale);
+        assertEquals(new Locale("en"), result);
+        
+        result = service.convert("de_DE", Locale.class);
+        assertTrue(result instanceof Locale);
+        assertEquals(new Locale("de", "DE"), result);
+        
+        result = service.convert("_GB", Locale.class);
+        assertTrue(result instanceof Locale);
+        assertEquals(new Locale("", "GB"), result);
+        
+        result = service.convert("en_US_WIN", Locale.class);
+        assertTrue(result instanceof Locale);
+        assertEquals(new Locale("en", "US", "WIN"), result);
+        
+        result = service.convert("de__POSIX", Locale.class);
+        assertTrue(result instanceof Locale);
+        assertEquals(new Locale("de", "", "POSIX"), result);
+    }
+    
+    public void testConvertClass() throws Exception {
+        assertEquals(this, service.convert(this, AggregateConverterTest.class));
+        assertEquals(AggregateConverterTest.class, service.convert(this.getClass().getName(), Class.class));
+        assertEquals(int[].class, service.convert("int[]", Class.class));
+    }
+
+    public void testConvertArray() throws Exception {
+        Object obj = service.convert(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4)),
+                                     GenericType.parse("java.util.List<java.lang.Integer>[]", getClass().getClassLoader()));
+        assertNotNull(obj);
+        assertTrue(obj.getClass().isArray());
+        Object[] o = (Object[]) obj;
+        assertEquals(2, o.length);
+        assertNotNull(o[0]);
+        assertTrue(o[0] instanceof List);
+        assertEquals(2, ((List) o[0]).size());
+        assertEquals(1, ((List) o[0]).get(0));
+        assertEquals(2, ((List) o[0]).get(1));
+        assertNotNull(o[0]);
+        assertTrue(o[1] instanceof List);
+        assertEquals(2, ((List) o[1]).size());
+        assertEquals(3, ((List) o[1]).get(0));
+        assertEquals(4, ((List) o[1]).get(1));
+        //assertEquals((Object) new int[] { 1, 2 }, (Object) service.convert(Arrays.asList(1, 2), int[].class));
+    }
+    
+    public void testCustom() throws Exception {
+        AggregateConverter s = new AggregateConverter(new TestBlueprintContainer(null));
+        s.registerConverter(new RegionConverter());
+        s.registerConverter(new EuRegionConverter());
+        
+        // lookup on a specific registered converter type
+        Object result;
+        result = s.convert(new Object(), Region.class);
+        assertTrue(result instanceof Region);
+        assertFalse(result instanceof EuRegion);
+                
+        result = s.convert(new Object(), EuRegion.class);
+        assertTrue(result instanceof EuRegion);
+        
+        // find first converter that matches the type
+        s = new AggregateConverter(new TestBlueprintContainer(null));
+        s.registerConverter(new AsianRegionConverter());
+        s.registerConverter(new EuRegionConverter());
+        
+        result = s.convert(new Object(), Region.class);
+        // TODO: check with the spec about the result
+        //assertTrue(result instanceof AsianRegion || result instanceof EuRegion);
+    }
+    
+    private interface Region {} 
+    
+    private interface EuRegion extends Region {}
+    
+    private interface AsianRegion extends Region {}
+    
+    private static class RegionConverter implements Converter {
+        public boolean canConvert(Object fromValue, ReifiedType toType) {
+            return Region.class == toType.getRawClass();
+        }
+        public Object convert(Object source, ReifiedType toType) throws Exception {
+            return new Region() {} ;
+        }
+    }
+    
+    private static class EuRegionConverter implements Converter {
+        public boolean canConvert(Object fromValue, ReifiedType toType) {
+            return toType.getRawClass().isAssignableFrom(EuRegion.class);
+        }
+        public Object convert(Object source, ReifiedType toType) throws Exception {
+            return new EuRegion() {} ;
+        }
+    }
+    
+    private static class AsianRegionConverter implements Converter {
+        public boolean canConvert(Object fromValue, ReifiedType toType) {
+            return toType.getRawClass().isAssignableFrom(AsianRegion.class);
+        }
+        public Object convert(Object source, ReifiedType toType) throws Exception {
+            return new AsianRegion() {} ;
+        }
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/GenericTypeTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/GenericTypeTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/GenericTypeTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/container/GenericTypeTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.container;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+public class GenericTypeTest extends TestCase {
+
+    private GenericType parse(String expression) throws Exception {
+        GenericType type = GenericType.parse(expression, getClass().getClassLoader());
+        assertEquals(expression, type.toString());
+        return type;
+    }
+    
+    public void testArrays() {
+        assertTrue(AggregateConverter.isAssignable(new Object[0], new GenericType(Object[].class)));
+        assertFalse(AggregateConverter.isAssignable(new Object[0], new GenericType(String[].class)));
+        assertTrue(AggregateConverter.isAssignable(new String[0], new GenericType(String[].class)));
+        assertFalse(AggregateConverter.isAssignable(new String[0], new GenericType(URI[].class)));
+        assertTrue(AggregateConverter.isAssignable(new String[0], new GenericType(Object[].class)));
+    }
+
+    public void testParseTypes() throws Exception {
+        
+        GenericType type = parse("java.util.List<java.lang.String[]>");
+        assertEquals(List.class, type.getRawClass());
+        assertEquals(1, type.size());
+        assertEquals(String[].class, type.getActualTypeArgument(0).getRawClass());
+        assertEquals(1, type.getActualTypeArgument(0).size());
+        assertEquals(String.class, type.getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
+
+        type = parse("java.util.Map<int,java.util.List<java.lang.Integer>[]>");
+        assertEquals(Map.class, type.getRawClass());
+        assertEquals(2, type.size());
+        assertEquals(int.class, type.getActualTypeArgument(0).getRawClass());
+        assertEquals(List[].class, type.getActualTypeArgument(1).getRawClass());
+        assertEquals(1, type.getActualTypeArgument(1).size());
+        assertEquals(Integer.class, type.getActualTypeArgument(1).getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
+
+        type = parse("java.util.List<java.lang.Integer>[]");
+        assertEquals(List[].class, type.getRawClass());
+        assertEquals(1, type.size());
+        assertEquals(Integer.class, type.getActualTypeArgument(0).getActualTypeArgument(0).getRawClass());
+    }
+
+    public void testBasic() throws Exception {        
+        GenericType type = new GenericType(int[].class);
+        assertEquals("int[]", type.toString());
+        assertEquals(int[].class, type.getRawClass());
+        assertEquals(0, type.getActualTypeArgument(0).size());
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholderTest.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholderTest.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholderTest.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/ext/AbstractPropertyPlaceholderTest.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.ext;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.blueprint.reflect.ValueMetadata;
+
+public class AbstractPropertyPlaceholderTest extends AbstractPropertyPlaceholder {
+    private final Map<String,String> values = new HashMap<String,String>();
+    private LateBindingValueMetadata sut;
+    
+    @Before
+    public void setup() {
+        values.clear();
+        bind("prop","value");
+        bind("prop2","other");
+    }
+    
+    @Test
+    public void singleProp() {
+        sut = makeProperty("${prop}");
+        assertEquals("value", sut.getStringValue());
+    }
+    
+    @Test
+    public void multipleProps() {
+        sut = makeProperty("the ${prop2} ${prop}");
+        assertEquals("the other value", sut.getStringValue());
+    }
+    
+    /*
+     * Test helper methods
+     */
+    
+    // Override to simulate actual property retrieval
+    protected String getProperty(String prop) {
+        return values.get(prop);
+    }
+    
+    private void bind(String prop, String val) {
+        values.put(prop, val);
+    }
+    
+    private LateBindingValueMetadata makeProperty(final String prop) {
+        return new LateBindingValueMetadata(new ValueMetadata() {
+            public String getType() {
+                return null;
+            }
+            
+            public String getStringValue() {
+                return prop;
+            }
+        });
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanC.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanC.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanC.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanC.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+import org.apache.aries.blueprint.CallbackTracker;
+import org.apache.aries.blueprint.CallbackTracker.Callback;
+
+public class BeanC {
+
+    public void init() {
+        CallbackTracker.add(new Callback(Callback.INIT, this));
+    }
+    
+    public void destroy() {
+        CallbackTracker.add(new Callback(Callback.DESTROY, this));
+    }
+    
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanD.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanD.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanD.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanD.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+import org.apache.aries.blueprint.CallbackTracker;
+import org.apache.aries.blueprint.CallbackTracker.Callback;
+
+public class BeanD {
+
+    private String name;
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public void init() {
+        CallbackTracker.add(new Callback(Callback.INIT, this));
+    }
+    
+    public void destroy() {
+        CallbackTracker.add(new Callback(Callback.DESTROY, this));
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanE.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanE.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanE.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanE.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+import org.apache.aries.blueprint.CallbackTracker;
+import org.apache.aries.blueprint.CallbackTracker.Callback;
+
+public class BeanE {
+
+    public BeanE(BeanC c) {        
+    }
+    
+    public void init() {
+        CallbackTracker.add(new Callback(Callback.INIT, this));
+    }
+    
+    public void destroy() {
+        CallbackTracker.add(new Callback(Callback.DESTROY, this));
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanF.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanF.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanF.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/BeanF.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+public class BeanF {
+
+    private Boolean wrapped;
+    private Boolean prim;
+
+    public BeanF(Boolean wrapped) {
+        this.wrapped = wrapped;
+    }
+
+    public BeanF(boolean prim) {
+        this.prim = prim;
+    }
+
+    public Boolean getWrapped() {
+        return wrapped;
+    }
+
+    public Boolean getPrim() {
+        return prim;
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterA.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterA.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterA.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterA.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+import java.io.File;
+
+import org.osgi.service.blueprint.container.ReifiedType;
+import org.osgi.service.blueprint.container.Converter;
+
+public class ConverterA implements Converter {
+
+    public boolean canConvert(Object fromValue, ReifiedType toType) {
+        return fromValue instanceof String && toType.getRawClass() == File.class;
+    }
+
+    public Object convert(Object source, ReifiedType toType) throws Exception {
+        if (source instanceof String) {
+            return new File((String) source);
+        }
+        throw new Exception("Unable to convert from " + (source != null ? source.getClass().getName() : "<null>") + " to " + File.class.getName());
+    }
+
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterB.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterB.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterB.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/ConverterB.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+import java.net.URI;
+
+import org.osgi.service.blueprint.container.ReifiedType;
+import org.osgi.service.blueprint.container.Converter;
+
+public class ConverterB implements Converter {
+
+    public boolean canConvert(Object fromValue, ReifiedType toType) {
+        return fromValue instanceof String && toType.getRawClass() == URI.class;
+    }
+
+    public Object convert(Object source, ReifiedType toType) throws Exception {
+        if (source instanceof String) {
+            return new URI((String) source);
+        }
+        throw new Exception("Unable to convert from " + (source != null ? source.getClass().getName() : "<null>") + " to " + URI.class.getName());
+    }
+
+}
\ No newline at end of file

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestBean.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestBean.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestBean.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestBean.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+public class FITestBean {
+  private String attr;
+  private String upperCaseAttr;
+  private FITestSubBean bean = new FITestSubBean();
+  
+  public String getAttr() { return attr; }
+  
+  public String getUpperCaseAttr() { return upperCaseAttr; }
+  public void setUpperCaseAttr(String val) { upperCaseAttr = val.toUpperCase(); }
+  public String getBeanName() { return bean.getName(); }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestSubBean.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestSubBean.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestSubBean.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/FITestSubBean.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+public class FITestSubBean {
+    private String name;
+    
+    public String getName() {
+        return name;
+    }
+}

Added: aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/InterfaceA.java
URL: http://svn.apache.org/viewvc/aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/InterfaceA.java?rev=1075094&view=auto
==============================================================================
--- aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/InterfaceA.java (added)
+++ aries/tags/blueprint-0.1-incubating/blueprint-core/src/test/java/org/apache/aries/blueprint/pojos/InterfaceA.java Sun Feb 27 17:47:08 2011
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.pojos;
+
+public interface InterfaceA {
+}



Mime
View raw message