geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r763927 [4/4] - in /geronimo/sandbox/gnodet/blueprint: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/blueprint/ src/main/java/org/apache/felix/bl...
Date Fri, 10 Apr 2009 13:23:44 GMT
Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/ParserTest.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,113 @@
+package org.apache.felix.blueprint;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.LocalComponentMetadata;
+import org.osgi.service.blueprint.reflect.ConstructorInjectionMetadata;
+import org.osgi.service.blueprint.reflect.ParameterSpecification;
+import org.osgi.service.blueprint.reflect.TypedStringValue;
+import org.osgi.service.blueprint.reflect.NullValue;
+import org.osgi.service.blueprint.reflect.ReferenceValue;
+import org.osgi.service.blueprint.reflect.ArrayValue;
+import org.osgi.service.blueprint.reflect.ComponentValue;
+import org.osgi.service.blueprint.namespace.ComponentDefinitionRegistry;
+import org.apache.felix.blueprint.parser.Parser;
+import org.apache.felix.blueprint.reflect.LocalComponentMetadataImpl;
+
+/**
+ * TODO: constructor injection
+ * TODO: Dependency#setMethod 
+ */
+public class ParserTest extends TestCase {
+
+    public void testParseComponent() throws Exception {
+        Parser parser = parse("/test-simple-component.xml");
+        ComponentDefinitionRegistry registry = parser.getRegistry();
+        assertNotNull(registry);
+        ComponentMetadata component = registry.getComponentDefinition("pojoA");
+        assertNotNull(component);
+        assertEquals("pojoA", component.getName());
+        Set<String> deps = component.getExplicitDependencies();
+        assertNotNull(deps);
+        assertEquals(2, deps.size());
+        assertTrue(deps.contains("pojoB"));
+        assertTrue(deps.contains("pojoC"));
+        assertTrue(component instanceof LocalComponentMetadata);
+        LocalComponentMetadata local = (LocalComponentMetadata) component;
+        assertEquals("org.apache.felix.blueprint.pojos.PojoA", local.getClassName());
+        ConstructorInjectionMetadata cns = local.getConstructorInjectionMetadata();
+        assertNotNull(cns);
+        List<ParameterSpecification> params = cns.getParameterSpecifications();
+        assertNotNull(params);
+        assertEquals(6, params.size());
+        ParameterSpecification param = params.get(0);
+        assertNotNull(param);
+        assertEquals(0, param.getIndex());
+        assertNull(param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof TypedStringValue);
+        assertEquals("val0", ((TypedStringValue) param.getValue()).getStringValue());
+        assertNull(((TypedStringValue) param.getValue()).getTypeName());
+        param = params.get(1);
+        assertNotNull(param);
+        assertEquals(2, param.getIndex());
+        assertNull(param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof ReferenceValue);
+        assertEquals("val1", ((ReferenceValue) param.getValue()).getComponentName());
+        param = params.get(2);
+        assertNotNull(param);
+        assertEquals(1, param.getIndex());
+        assertNull(param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof NullValue);
+        param = params.get(3);
+        assertNotNull(param);
+        assertEquals(3, param.getIndex());
+        assertEquals("java.lang.String", param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof TypedStringValue);
+        assertEquals("val3", ((TypedStringValue) param.getValue()).getStringValue());
+        assertNull(((TypedStringValue) param.getValue()).getTypeName());
+        param = params.get(4);
+        assertNotNull(param);
+        assertEquals(4, param.getIndex());
+        assertNull(param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof ArrayValue);
+        ArrayValue array = (ArrayValue) param.getValue();
+        assertNull(array.getValueType());
+        assertNotNull(array.getArray());
+        assertEquals(3, array.getArray().length);
+        assertTrue(array.getArray()[0] instanceof TypedStringValue);
+        assertTrue(array.getArray()[1] instanceof ComponentValue);
+        assertTrue(array.getArray()[2] instanceof NullValue);
+        param = params.get(5);
+        assertNotNull(param);
+        assertEquals(5, param.getIndex());
+        assertNull(param.getTypeName());
+        assertNotNull(param.getValue());
+        assertTrue(param.getValue() instanceof ReferenceValue);
+        assertEquals("pojoB", ((ReferenceValue) param.getValue()).getComponentName());
+    }
+
+    public void testParse() throws Exception {
+        Parser parser = new Parser();
+        parser.parse(new URL[] { getClass().getResource("/test.xml") });
+        ComponentDefinitionRegistry registry = parser.getRegistry();
+        assertNotNull(registry);
+
+    }
+
+
+    protected Parser parse(String name) throws Exception {
+        Parser parser = new Parser();
+        parser.parse(new URL[] { getClass().getResource(name) });
+        return parser;
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/convert/ConversionServiceImplTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/convert/ConversionServiceImplTest.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/convert/ConversionServiceImplTest.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/convert/ConversionServiceImplTest.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,95 @@
+package org.apache.felix.blueprint.convert;
+
+import java.net.URI;
+import java.net.URL;
+import java.math.BigInteger;
+import java.util.Properties;
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.TestCase;
+import org.osgi.service.blueprint.convert.ConversionService;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Apr 8, 2009
+ * Time: 10:26:20 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ConversionServiceImplTest extends TestCase {
+
+    private ConversionService service;
+
+    protected void setUp() {
+        service = new ConversionServiceImpl();
+    }
+
+    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));
+        // TODO: check the following tests
+//        assertEquals('\n', service.convert("\\n", char.class));
+//        assertEquals('\n', service.convert("\\n", 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));
+    }
+
+    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 {
+        // TODO
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterA.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterA.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterA.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,19 @@
+package org.apache.felix.blueprint.pojos;
+
+import java.io.File;
+
+import org.osgi.service.blueprint.convert.Converter;
+
+public class ConverterA implements Converter {
+
+    public Object convert(Object source) 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());
+    }
+
+    public Class getTargetClass() {
+        return File.class;
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterB.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterB.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterB.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ConverterB.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,20 @@
+package org.apache.felix.blueprint.pojos;
+
+import java.io.File;
+import java.net.URI;
+
+import org.osgi.service.blueprint.convert.Converter;
+
+public class ConverterB implements Converter {
+
+    public Object convert(Object source) 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());
+    }
+
+    public Class getTargetClass() {
+        return URI.class;
+    }
+}
\ No newline at end of file

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/InterfaceA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/InterfaceA.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/InterfaceA.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/InterfaceA.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,11 @@
+package org.apache.felix.blueprint.pojos;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Apr 7, 2009
+ * Time: 9:41:27 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface InterfaceA {
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ListenerA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ListenerA.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ListenerA.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/ListenerA.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,21 @@
+package org.apache.felix.blueprint.pojos;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Apr 3, 2009
+ * Time: 11:42:58 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ListenerA {
+
+    public void bind(ServiceReference ref) {
+
+    }
+
+    public void unbind(ServiceReference ref) {
+        
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoA.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoA.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoA.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,28 @@
+package org.apache.felix.blueprint.pojos;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Mar 26, 2009
+ * Time: 6:16:31 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PojoA implements InterfaceA {
+
+    private PojoB pojob;
+
+    public PojoA() {
+    }
+
+    public PojoA(PojoB pojob) {
+        this.pojob = pojob;
+    }
+
+    public PojoB getPojob() {
+        return pojob;
+    }
+
+    public void setPojob(PojoB pojob) {
+        this.pojob = pojob;
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoB.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoB.java?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoB.java
(added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/java/org/apache/felix/blueprint/pojos/PojoB.java
Fri Apr 10 13:23:41 2009
@@ -0,0 +1,30 @@
+package org.apache.felix.blueprint.pojos;
+
+import java.net.URI;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Mar 26, 2009
+ * Time: 6:16:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PojoB {
+
+    private URI uri;
+
+    public PojoB() {
+    }
+
+    public PojoB(URI uri) {
+        this.uri = uri;
+    }
+
+    public URI getUri() {
+        return uri;
+    }
+
+    public void setUri(URI uri) {
+        this.uri = uri;
+    }
+}

Added: geronimo/sandbox/gnodet/blueprint/src/test/resources/test-simple-component.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/resources/test-simple-component.xml?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/resources/test-simple-component.xml (added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/resources/test-simple-component.xml Fri Apr
10 13:23:41 2009
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 ../../main/resources/org/apache/felix/blueprint/blueprint.xsd">
+
+    <component id="pojoA" class="org.apache.felix.blueprint.pojos.PojoA" depends-on="
pojoB , pojoC ,">
+        <constructor-arg value="val0"/>
+        <constructor-arg ref="val1" index="2"/>
+        <constructor-arg index="1">
+            <description>null value</description>
+            <null/>
+        </constructor-arg>
+        <constructor-arg type="java.lang.String">
+            <value>val3</value>
+        </constructor-arg>
+        <constructor-arg>
+            <array>
+                <value>val0</value>
+                <component class="java.lang.String"/>
+                <null/>
+            </array>
+        </constructor-arg>
+        <constructor-arg>
+            <ref component="pojoB"/>
+        </constructor-arg>
+        <property name="prop1" ref="pojoB"/>
+        <property name="prop2" value="value" />
+        <property name="prop3">
+            <description>property</description>
+            <value>val</value>
+        </property>
+    </component>
+
+</components>
\ No newline at end of file

Added: geronimo/sandbox/gnodet/blueprint/src/test/resources/test.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gnodet/blueprint/src/test/resources/test.xml?rev=763927&view=auto
==============================================================================
--- geronimo/sandbox/gnodet/blueprint/src/test/resources/test.xml (added)
+++ geronimo/sandbox/gnodet/blueprint/src/test/resources/test.xml Fri Apr 10 13:23:41 2009
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 ../../main/resources/org/apache/felix/blueprint/blueprint.xsd"
+            default-availability="mandatory">
+
+    <description>
+        This is a parsing test application
+    </description>
+
+    <type-converters>
+        <component class="org.apache.felix.blueprint.pojos.ConverterA"/>
+        <ref component="converterB"/>
+    </type-converters>
+
+    <component id="pojoA" class="org.apache.felix.blueprint.pojos.PojoA">
+        <property name="pojob" ref="pojoB"/>
+    </component>
+
+    <component id="pojoAcns" class="org.apache.felix.blueprint.pojos.PojoA">
+        <constructor-arg ref="pojoB"/>
+    </component>
+
+    <component id="pojoB" class="org.apache.felix.blueprint.pojos.PojoB">
+        <property name="uri" value="urn:myuri"/>
+    </component>
+
+    <component id="pojoBcns" class="org.apache.felix.blueprint.pojos.PojoB">
+        <constructor-arg value="urn:myuri"/>
+    </component>
+
+    <component id="converterB" class="org.apache.felix.blueprint.pojos.ConverterB"/>
+
+    <reference id="refA" filter="(key=prop)" interface="org.apache.felix.blueprint.pojos.InterfaceA"/>
+
+    <reference id="refB" availability="optional">
+        <interfaces>
+            <value>org.apache.felix.blueprint.pojos.InterfaceA</value>
+        </interfaces>
+        <listener ref="listenerA" bind-method="bind" unbind-method="unbind"/>
+    </reference>
+
+    <service interface="org.apache.felix.blueprint.pojos.InterfaceA" ref="pojoA"/>
+
+    <component id="listenerA" class="org.apache.felix.blueprint.pojos.ListenerA"/>
+
+    <ref-list availability="optional" member-type="service-instance"/>
+
+</components>
\ No newline at end of file



Mime
View raw message