You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/07/02 13:26:41 UTC
svn commit: r552470 [3/3] - in
/incubator/tuscany/java/sca/modules/implementation-osgi/src:
main/java/org/apache/tuscany/implementation/osgi/context/
main/java/org/apache/tuscany/implementation/osgi/invocation/
main/java/org/apache/tuscany/implementati...
Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java Mon Jul 2 04:26:39 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.tuscany.sca.implementation.osgi.test;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ *
+ * Test class - Implementation of an OSGi service
+ *
+ */
+public class OSGiTestWithPropertyImpl implements OSGiTestInterface, BundleActivator {
+
+ public double exchangeRate;
+
+ private String currency;
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+
+ public String testService() throws Exception {
+
+ if (exchangeRate != 2.0)
+ throw new Exception("Property exchangeRate not set correctly, expected 2.0, got " + exchangeRate);
+ if (!"USD".equals(currency))
+ throw new Exception("Property currency not set correctly, expected USD, got " + currency);
+ return OSGiTestWithPropertyImpl.class.getName();
+
+ }
+
+ public void start(BundleContext bc) throws Exception {
+
+ bc.registerService(OSGiTestInterface.class.getName(), this, new Hashtable<String, Object>());
+
+ }
+
+ public void stop(BundleContext bc) throws Exception {
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java Mon Jul 2 04:26:39 2007
@@ -0,0 +1,156 @@
+/*
+ * 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.tuscany.sca.implementation.osgi.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.CompositeProcessor;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestImpl;
+import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface;
+import org.apache.tuscany.sca.implementation.osgi.xml.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.xml.OSGiImplementationProcessor;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.scope.Scope;
+
+/**
+ * Test reading OSGi implementations.
+ *
+ */
+public class OSGiReadImplTestCase extends TestCase {
+
+ XMLInputFactory inputFactory;
+ DefaultStAXArtifactProcessorExtensionPoint staxProcessors;
+ ExtensibleStAXArtifactProcessor staxProcessor;
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private PolicyFactory policyFactory;
+ private InterfaceContractMapper mapper;
+ private OSGiImplementationProcessor osgiProcessor;
+
+ public void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ scaBindingFactory = new DefaultSCABindingFactory();
+ policyFactory = new DefaultPolicyFactory();
+ mapper = new InterfaceContractMapperImpl();
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+ JavaInterfaceFactory javaInterfaceFactory = new DefaultJavaInterfaceFactory();
+
+ JavaInterfaceIntrospectorExtensionPoint interfaceVisitors = new DefaultJavaInterfaceIntrospectorExtensionPoint();
+ JavaInterfaceIntrospector interfaceIntrospector =
+ new ExtensibleJavaInterfaceIntrospector(javaInterfaceFactory, interfaceVisitors);
+
+ osgiProcessor = new OSGiImplementationProcessor(
+ interfaceIntrospector,
+ javaInterfaceFactory,
+ assemblyFactory,
+ policyFactory);
+ staxProcessors.addArtifactProcessor(osgiProcessor);
+
+ OSGiTestBundles.createBundle("target/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class);
+
+ }
+
+ public void tearDown() throws Exception {
+ inputFactory = null;
+ staxProcessors = null;
+ policyFactory = null;
+ assemblyFactory = null;
+ mapper = null;
+ }
+
+ public void testReadComposite() throws Exception {
+ CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor);
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeProcessor.read(reader);
+ assertNotNull(composite);
+
+ CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null);
+ compositeUtil.build(composite);
+
+ }
+
+ public void testReadAndResolveComposite() throws Exception {
+ CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor);
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeProcessor.read(reader);
+ assertNotNull(composite);
+
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+ staxProcessor.resolve(composite, resolver);
+
+ CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null);
+ compositeUtil.build(composite);
+ }
+
+ public void testReadOSGiImplementation() throws Exception {
+
+ String str = "<implementation.osgi xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" " +
+ "bundle=\"OSGiTestService\" " +
+ "bundleLocation=\"file:target/OSGiTestService.jar\" " +
+ "scope=\"COMPOSITE\" " +
+ "imports=\"import1.jar import2.jar\"" +
+ "/>";
+ ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes());
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ reader.next();
+
+
+ OSGiImplementation osgiImpl = osgiProcessor.read(reader);
+
+ assertEquals(osgiImpl.getBundleName(), "OSGiTestService");
+ assertEquals(osgiImpl.getBundleLocation(), "file:target/OSGiTestService.jar");
+ assertTrue(osgiImpl.getImports().length == 2);
+ assertEquals(osgiImpl.getImports()[0], "import1.jar");
+ assertEquals(osgiImpl.getImports()[1], "import2.jar");
+ assertEquals(osgiImpl.getScope(), Scope.COMPOSITE);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java?view=auto&rev=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java Mon Jul 2 04:26:39 2007
@@ -0,0 +1,87 @@
+/*
+ * 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.tuscany.sca.implementation.osgi.xml;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ private WeakReference<ClassLoader> classLoader;
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrappering the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType?view=diff&rev=552470&r1=552469&r2=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType Mon Jul 2 04:26:39 2007
@@ -17,9 +17,12 @@
* specific language governing permissions and limitations
* under the License.
-->
-<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<service name="OSGiTestService">
- <interface.java interface="org.apache.tuscany.implementation.osgi.test.OSGiTestInterface"/>
+ <interface.java interface="org.apache.tuscany.sca.implementation.osgi.test.OSGiTestInterface"/>
</service>
+
+ <property name="currency" type="xsd:string" >GBP</property>
+ <property name="exchangeRate" type="xsd:double" >1.0</property>
</componentType>
Modified: incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite?view=diff&rev=552470&r1=552469&r2=552470
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite (original)
+++ incubator/tuscany/java/sca/modules/implementation-osgi/src/test/resources/osgitest.composite Mon Jul 2 04:26:39 2007
@@ -17,14 +17,20 @@
* specific language governing permissions and limitations
* under the License.
-->
-<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="OSGiTestComposite">
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ name="OSGiTestComposite">
<component name="OSGiTestServiceComponent">
<implementation.osgi
bundle="OSGiTestService"
bundleLocation="file:target/OSGiTestService.jar"
scope="COMPOSITE"
+ injectProperties="true"
/>
+
+ <property name="currency" type="xsd:string" >USD</property>
+ <property name="exchangeRate" type="xsd:double" >2.0</property>
</component>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org