summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 11:07:13 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 11:07:13 +0000
commit1618160f4f2dbb67727df2d341c505f105aa1e2c (patch)
tree047c412e33690e8cc17ca0bab60702a6419e6a54 /sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test
parent4a25bb51cbb7253286662fbd20aabf71e245bf6a (diff)
Delete and redo release branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027464 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test')
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java39
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java31
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java89
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java89
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java173
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java110
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java105
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml36
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType63
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite35
13 files changed, 863 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java
new file mode 100644
index 0000000000..656b78b717
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/CalculatorService.java
@@ -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 calculator.dosgi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The Calculator service interface.
+ */
+@Remotable
+public interface CalculatorService extends Remote {
+
+ double add(double n1, double n2) throws RemoteException;
+
+ double subtract(double n1, double n2) throws RemoteException;
+
+ double multiply(double n1, double n2) throws RemoteException;
+
+ double divide(double n1, double n2) throws RemoteException;
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java
new file mode 100644
index 0000000000..971500782f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/AddService.java
@@ -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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the add service
+ */
+@Remotable
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java
new file mode 100644
index 0000000000..49b8a1c0bf
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/DivideService.java
@@ -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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the divide service
+ */
+@Remotable
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java
new file mode 100644
index 0000000000..f4e59d12ea
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/MultiplyService.java
@@ -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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the multiply service
+ */
+@Remotable
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java
new file mode 100644
index 0000000000..bfb9b820f7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/calculator/dosgi/operations/SubtractService.java
@@ -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 calculator.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the subtract service
+ */
+@Remotable
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
new file mode 100644
index 0000000000..224467181b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BluePrintComponentsProcessorTestCase {
+ private static final String xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<components xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\">"
+ + "<component id=\"CalculatorComponent\" class=\"calculator.dosgi.impl.CalculatorServiceImpl\">"
+ + "<property name=\"addService\" ref=\"AddService\" />"
+ + "<property name=\"subtractService\" ref=\"SubtractService\" />"
+ + "<property name=\"multiplyService\" ref=\"MultiplyService\" />"
+ + "<property name=\"divideService\" ref=\"DivideService\" />"
+ + "</component>"
+ + "<service id=\"CalculatorService\" ref=\"CalculatorComponent\" interface=\"calculator.dosgi.CalculatorService\">"
+ + "</service>"
+ + "<reference id=\"AddService\" interface=\"calculator.dosgi.operations.AddService\">"
+ + "</reference>"
+ + "<reference id=\"SubtractService\" interface=\"calculator.dosgi.operations.SubtractService\">"
+ + "</reference>"
+ + "<reference id=\"MultiplyService\" interface=\"calculator.dosgi.operations.MultiplyService\">"
+ + "</reference>"
+ + "<reference id=\"DivideService\" interface=\"calculator.dosgi.operations.DivideService\">"
+ + "</reference>"
+ + "</components>";
+ private static XMLStreamReader reader;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ BluePrintComponentsProcessor processor =
+ new BluePrintComponentsProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()));
+ ComponentType ct = processor.read(reader, new ProcessorContext());
+ Assert.assertEquals(1, ct.getServices().size());
+ Assert.assertEquals(4, ct.getReferences().size());
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
new file mode 100644
index 0000000000..ef49121c2c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * 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.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class OSGiComponentProcessorTestCase {
+ private static final String xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<scr:component name=\"CalculatorComponent\""
+ + " xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.0.0\">"
+ + "<implementation class=\"calculator.dosgi.CalculatorServiceDSImpl\" />"
+ + "<service>"
+ + "<provide interface=\"calculator.dosgi.CalculatorService\" />"
+ + "</service>"
+ + "<reference name=\"addService\" interface=\"calculator.dosgi.operations.AddService\""
+ + " bind=\"setAddService\" unbind=\"unsetAddService\" policy=\"dynamic\" />"
+ + "<reference name=\"subtractService\" interface=\"calculator.dosgi.operations.SubtractService\""
+ + " bind=\"setSubtractService\" unbind=\"unsetSubtractService\" policy=\"dynamic\" />"
+ + "<reference name=\"multiplyService\" interface=\"calculator.dosgi.operations.MultiplyService\""
+ + " bind=\"setMultiplyService\" unbind=\"unsetMultiplyService\" policy=\"dynamic\" />"
+ + "<reference name=\"divideService\" interface=\"calculator.dosgi.operations.DivideService\""
+ + " bind=\"setDivideService\" unbind=\"unsetDivideService\" policy=\"dynamic\" />"
+ + "</scr:component>";
+
+ private static XMLStreamReader reader;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ OSGiComponentProcessor processor =
+ new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(registry));
+ ComponentType ct = processor.read(reader, new ProcessorContext(registry));
+ Assert.assertEquals(1, ct.getServices().size());
+ Assert.assertEquals(4, ct.getReferences().size());
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
new file mode 100644
index 0000000000..614f243eb3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
@@ -0,0 +1,173 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.OSGiImplementation;
+import org.apache.tuscany.sca.implementation.osgi.OSGiProperty;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test reading OSGi implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OSGiReadImplTestCase {
+
+ private static XMLInputFactory inputFactory;
+ private static XMLOutputFactory outputFactory;
+ private static StAXArtifactProcessor<Object> staxProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ }
+
+ @Test
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+ }
+
+ @Test
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
+ assertNotNull(componentType);
+
+ assertEquals(2, componentType.getServices().get(0).getExtensions().size());
+
+ //write composite back
+ StringWriter stringWriter = new StringWriter();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
+ staxProcessor.write(componentType, writer, context);
+ stringWriter.close();
+
+ //read from the output from write
+ reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString()));
+ componentType = (ComponentType)staxProcessor.read(reader, context);
+ assertNotNull(componentType);
+
+ assertEquals(2, componentType.getServices().get(0).getExtensions().size());
+
+ reader.close();
+ }
+
+ @Test
+ public void testReadAndResolveComposite() throws Exception {
+ InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+
+ is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType");
+ reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
+
+ assertEquals(1, componentType.getServices().size());
+ Object prop1 = componentType.getServices().get(0).getExtensions().get(0);
+ assertTrue(prop1 instanceof OSGiProperty);
+ OSGiProperty osgiProp1 = (OSGiProperty)prop1;
+ assertEquals("1", osgiProp1.getValue());
+ assertEquals("prop1", osgiProp1.getName());
+
+ assertEquals(4, componentType.getReferences().size());
+ Object prop2 = componentType.getReferences().get(0).getExtensions().get(1);
+ assertTrue(prop2 instanceof OSGiProperty);
+ OSGiProperty osgiProp2 = (OSGiProperty)prop2;
+ assertEquals("ABC", osgiProp2.getValue());
+ assertEquals("prop2", osgiProp2.getName());
+
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+ staxProcessor.resolve(componentType, resolver, context);
+ resolver.addModel(componentType, context);
+
+ staxProcessor.resolve(composite, resolver, context);
+
+ reader.close();
+ }
+
+ @Test
+ public void testReadOSGiImplementation() throws Exception {
+
+ String str =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<implementation.osgi xmlns=\"http://tuscany.apache.org/xmlns/sca/1.1\" targetNamespace=\"http://test\" "
+ + "bundleSymbolicName=\"osgi.test\" "
+ + "bundleVersion=\"1.0.0\" "
+ + "/>";
+ ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes());
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ reader.nextTag();
+
+ OSGiImplementation osgiImpl = (OSGiImplementation)staxProcessor.read(reader, context);
+
+ assertEquals(osgiImpl.getBundleSymbolicName(), "osgi.test");
+ assertEquals(osgiImpl.getBundleVersion(), "1.0.0");
+
+ StringWriter sw = new StringWriter();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
+ staxProcessor.write(osgiImpl, writer, context);
+ writer.flush();
+ writer.close();
+ Assert.assertTrue(sw.toString().contains("bundleSymbolicName=\"osgi.test\" bundleVersion=\"1.0.0\""));
+
+ reader.close();
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
new file mode 100644
index 0000000000..0e7acc354a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.StringReader;
+import java.util.List;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.osgi.ServiceDescription;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ServiceDescriptionsTestCase {
+ private static final String xml =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<endpoint-descriptions xmlns=\"http://www.osgi.org/xmlns/rsa/v1.0.0\" "
+ + "xmlns:sca=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\">"
+ + "<endpoint-description>"
+ + "<property name=\"objectClass\" value=\"calculator.operations.AddService\"/>"
+ + "<property name=\"service.intents\" value=\"sca:SOAP sca:HTTP\"/>"
+ + "<property name=\"service.imported.configs\" value=\"org.osgi.sca\"/>"
+ + "</endpoint-description>"
+ + "<endpoint-description>"
+ + "<property name=\"service.intents\">"
+ + " <list>"
+ + " <value>SOAP</value>"
+ + " <value>HTTP</value>"
+ + " </list>"
+ + "</property>"
+ + "<property name=\"endpoint.id\" value=\"http://ws.acme.com:9000/hello\"/>"
+ + "<property name=\"objectClass\" value=\"com.acme.Foo\"/>"
+ + "<property name=\"endpoint.package.version.com.acme\" value=\"4.2\"/>"
+ + "<property name=\"service.imported.configs\" value=\"com.acme\"/>"
+ + "<property name=\"com.acme.ws.xml\">"
+ + "<xml>"
+ + " <config xmlns=\"http://acme.com/defs\">"
+ + " <port>1029</port>"
+ + " <host>www.acme.com</host>"
+ + " </config>"
+ + " </xml>"
+ + " </property>"
+ + "</endpoint-description>"
+ + "</endpoint-descriptions>";
+
+ private static ServiceDescriptionsProcessor processor;
+ private static XMLStreamReader reader;
+
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ StAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, factory, null);
+
+ processor = new ServiceDescriptionsProcessor(extensionPoints, staxProcessor);
+
+ reader = factory.createXMLStreamReader(new StringReader(xml));
+ }
+
+ @Test
+ public void testLoad() throws Exception {
+ List<ServiceDescription> descriptions = processor.read(reader, context);
+ Assert.assertEquals(2, descriptions.size());
+ System.out.println(descriptions);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
new file mode 100644
index 0000000000..17fef8a05c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java
@@ -0,0 +1,105 @@
+/*
+ * 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.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl;
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+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, ProcessorContext context) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ if (unresolved instanceof OSGiImplementationImpl && !(resolved instanceof OSGiImplementationImpl)) {
+
+ OSGiImplementationImpl impl = ((OSGiImplementationImpl)unresolved);
+ ComponentType componentType = (ComponentType)resolved;
+
+ List<Property> properties = componentType.getProperties();
+ for (Property property : properties) {
+ impl.getProperties().add(property);
+ }
+ impl.setUnresolved(false);
+ return unresolved;
+ }
+
+ // 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 wrapping 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, ProcessorContext context) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
new file mode 100644
index 0000000000..3e537df732
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/calculator-component.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<scr:component name="CalculatorComponent"
+ xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <implementation class="calculator.dosgi.CalculatorServiceDSImpl" />
+ <service>
+ <provide interface="calculator.dosgi.CalculatorService" />
+ </service>
+
+ <reference name="addService" interface="calculator.dosgi.operations.AddService" bind="setAddService" unbind="unsetAddService"
+ policy="dynamic" />
+ <reference name="subtractService" interface="calculator.dosgi.operations.SubtractService" bind="setSubtractService"
+ unbind="unsetSubtractService" policy="dynamic" />
+ <reference name="multiplyService" interface="calculator.dosgi.operations.MultiplyService" bind="setMultiplyService"
+ unbind="unsetMultiplyService" policy="dynamic" />
+ <reference name="divideService" interface="calculator.dosgi.operations.DivideService" bind="setDivideService"
+ unbind="unsetDivideService" policy="dynamic" />
+
+</scr:component>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
new file mode 100644
index 0000000000..401809c197
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/OSGI-INF/sca/bundle.componentType
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1">
+ <!-- The service elment defines an SCA view of the OSGi service -->
+ <service name="Calculator">
+ <!-- The interface will be mapped into the OSGi service class -->
+ <interface.java interface="calculator.dosgi.CalculatorService"/>
+ <!-- The list of OSGi properties -->
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </service>
+
+ <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
+ <reference name="addService">
+ <interface.java interface="calculator.dosgi.operations.AddService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="subtractService">
+ <interface.java interface="calculator.dosgi.operations.SubtractService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="multiplyService">
+ <interface.java interface="calculator.dosgi.operations.MultiplyService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+ <reference name="divideService">
+ <interface.java interface="calculator.dosgi.operations.DivideService"/>
+ <extensions>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </extensions>
+ </reference>
+</componentType>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite
new file mode 100644
index 0000000000..7c54e46a54
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/implementation-osgi/src/test/resources/osgitest.composite
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://test"
+ name="OSGiTestComposite">
+
+ <component name="OSGiTestServiceComponent">
+ <tuscany:implementation.osgi bundleVersion="1.0.0"
+ bundleSymbolicName="osgi.test" />
+
+ <property name="currency" type="xsd:string">USD</property>
+ <property name="exchangeRate" type="xsd:double">2.0</property>
+
+ </component>
+
+</composite>