From 5d83de3646c6f1b07d2221f5586088deeca27d0a Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 6 Oct 2009 14:24:43 +0000 Subject: Branch for 1.5.2 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@822292 13f79535-47bb-0310-9956-ffa450edef68 --- .../osgi-contribution/contribution-test/pom.xml | 110 +++++++++ .../sca/contribution/osgi/OSGiTestUtil.java | 73 ++++++ .../osgi/test/MixedContributionTestCase.java | 43 ++++ .../osgi/test/NestedBundleTestCase.java | 182 +++++++++++++++ .../osgi/test/OSGiResolverTestCase.java | 257 +++++++++++++++++++++ .../osgi/test/SCAResolverTestCase.java | 240 +++++++++++++++++++ .../resources/osgi/felix/felix.config.properties | 44 ++++ 7 files changed, 949 insertions(+) create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/pom.xml create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/main/java/org/apache/tuscany/sca/contribution/osgi/OSGiTestUtil.java create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/MixedContributionTestCase.java create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/NestedBundleTestCase.java create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/OSGiResolverTestCase.java create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/SCAResolverTestCase.java create mode 100644 branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/resources/osgi/felix/felix.config.properties (limited to 'branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test') diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/pom.xml b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/pom.xml new file mode 100644 index 0000000000..e01ca1dcd5 --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/pom.xml @@ -0,0 +1,110 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-itest + 1.5.1-SNAPSHOT + ../pom.xml + + itest-osgi-contribution-test + Apache Tuscany SCA iTest OSGi Contribution + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.5.1-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.5.1-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-osgi + 1.5.1-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-contribution-osgi + 1.5.1-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-osgi-runtime + 1.5.1-SNAPSHOT + + + + org.apache.felix + org.apache.felix.main + 1.0.4 + + + org.apache.felix + org.osgi.foundation + + + + + + org.apache.felix + org.apache.felix.configadmin + 1.0.1 + + + org.apache.felix + org.osgi.foundation + + + + + + org.apache.felix + org.apache.felix.scr + 1.0.2 + + + org.apache.felix + org.osgi.foundation + + + + + + + junit + junit + 4.5 + test + + + + diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/main/java/org/apache/tuscany/sca/contribution/osgi/OSGiTestUtil.java b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/main/java/org/apache/tuscany/sca/contribution/osgi/OSGiTestUtil.java new file mode 100644 index 0000000000..108481fcbd --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/main/java/org/apache/tuscany/sca/contribution/osgi/OSGiTestUtil.java @@ -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.tuscany.sca.contribution.osgi; + +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; +import org.osgi.framework.BundleContext; + + +/** + * OSGi Test Utils + */ +public class OSGiTestUtil { + + public static BundleContext setUpOSGiTestRuntime() throws Exception { + + setUpFelixTestRuntime(); + return OSGiRuntime.getRuntime().getBundleContext(); + } + + + public static void setUpFelixTestRuntime() throws Exception { + + String felixConfigFileName = "file:target/test-classes/osgi/felix/felix.config.properties"; + + System.setProperty("felix.config.properties", felixConfigFileName); + + try { + + ClassLoader cl = OSGiTestUtil.class.getClassLoader(); + + Class felixMainClass = cl.loadClass("org.apache.felix.main.Main"); + if (felixMainClass != null) { + String felixDir = felixMainClass.getProtectionDomain().getCodeSource().getLocation().getPath(); + int index = 0; + if ((index = felixDir.indexOf("/org.apache.felix.main")) >= 0) { + felixDir = felixDir.substring(0, index); + System.setProperty("FELIX_DIR", felixDir); + } + } + + } catch (Exception e) { + // Ignore + } + + + } + + public static void shutdownOSGiRuntime() { + try { + OSGiRuntime.stop(); + + } catch (Exception e) { + // Ignore + } + } + +} diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/MixedContributionTestCase.java b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/MixedContributionTestCase.java new file mode 100644 index 0000000000..28fe368663 --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/MixedContributionTestCase.java @@ -0,0 +1,43 @@ +/* + * 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.contribution.osgi.test; + + +/* + * + * Supplychain using OSGi and non-OSGi contributions + * + * + */ + +public class MixedContributionTestCase extends SCAResolverTestCase { + + @Override + protected void setUp() throws Exception { + + + customerJarName = "Customer2"; + retailerJarName = "RetailerJar"; + + setUpOSGi(); + setUpSCA(); + + } + +} diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/NestedBundleTestCase.java b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/NestedBundleTestCase.java new file mode 100644 index 0000000000..be3b7365e5 --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/NestedBundleTestCase.java @@ -0,0 +1,182 @@ +/* + * 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.contribution.osgi.test; + + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.osgi.OSGiTestUtil; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain; +/* + * + * Supplychain using OSGi contributions, with nested jar files and bundles used + * by and + * + * SupplyChain v1 is a bundle containing jar files which are used by + * SupplyChain v2 is a bundle containing bundles which are used by + */ + +public class NestedBundleTestCase extends TestCase { + + + protected EmbeddedSCADomain domain; + + private SupplyChain supplyChainV1; + private SupplyChain supplyChainV2; + + @Override + protected void setUp() throws Exception { + + setUpOSGi(); + setUpSCA(); + } + + protected void setUpOSGi() throws Exception { + OSGiTestUtil.setUpFelixTestRuntime(); + } + + protected void setUpSCA() throws Exception { + //Create a test embedded SCA domain + ClassLoader cl = getClass().getClassLoader(); + domain = new EmbeddedSCADomain(cl, "http://localhost"); + + //Start the domain + domain.start(); + + // Contribute the SCA contribution + ContributionService contributionService = domain.getContributionService(); + supplyChainV1 = new SupplyChain("../contribution-classes/target/classes", + contributionService, "V1"); + supplyChainV1.setUpSCA(); + + supplyChainV2 = new SupplyChain("../contribution-classes-v2/target/classes", + contributionService, "V2"); + supplyChainV2.setUpSCA(); + } + + + + @Override + public void tearDown() throws Exception { + + + supplyChainV1.tearDownSCA(); + supplyChainV2.tearDownSCA(); + + domain.stop(); + + domain.close(); + + OSGiTestUtil.shutdownOSGiRuntime(); + } + + + @SuppressWarnings("unchecked") + public void test() throws Exception { + + ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer"); + customerClassRef = supplyChainV1.supplychainContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef); + Class customerClass = customerClassRef.getJavaClass(); + + Object customer = + domain.getService(customerClass, "CustomerComponent"); + + Method m = customerClass.getMethod("purchaseGoods"); + m.invoke(customer); + + System.out.println("Sleeping ..."); + Thread.sleep(1000); + + ClassReference customerClassRefV2 = new ClassReference("supplychain.customer.Customer"); + customerClassRefV2 = supplyChainV2.supplychainContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRefV2); + Class customerClassV2 = customerClassRefV2.getJavaClass(); + + Object customerV2 = + domain.getService(customerClassV2, "CustomerComponentV2"); + + Method mV2 = customerClassV2.getMethod("purchaseGoods"); + mV2.invoke(customerV2); + + System.out.println("Sleeping ..."); + Thread.sleep(2000); + + System.out.println("Test complete"); + + } + + private class SupplyChain { + + private String folderName; + private ContributionService contributionService; + private String version; + + private Contribution supplychainContribution; + + + public SupplyChain(String folderName, ContributionService contributionService, String version) { + this.folderName = folderName; + this.contributionService = contributionService; + this.version = version; + } + + protected void setUpSCA() throws Exception { + File supplychainLocation = new File(folderName + "/SupplyChain" + version + ".jar"); + URL supplychainContribURL = supplychainLocation.toURL(); + + + String supplychainURI = "SupplyChain" + version; + + supplychainContribution = contributionService.contribute( + supplychainURI, supplychainContribURL, true); + + for (Composite deployable : supplychainContribution.getDeployables()) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + // Start Components from my composite + for (Composite deployable : supplychainContribution.getDeployables() ) { + domain.getCompositeActivator().activate(deployable); + domain.getCompositeActivator().start(deployable); + } + } + + public void tearDownSCA() throws Exception { + // Remove the contribution from the in-memory repository + contributionService.remove("SupplyChain" + version); + + // Stop Components from my composite + for (Composite deployable : supplychainContribution.getDeployables() ) { + domain.getCompositeActivator().stop(deployable); + domain.getCompositeActivator().deactivate(deployable); + } + + } + + } + +} diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/OSGiResolverTestCase.java b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/OSGiResolverTestCase.java new file mode 100644 index 0000000000..03372349f8 --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/OSGiResolverTestCase.java @@ -0,0 +1,257 @@ +/* + * 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.contribution.osgi.test; + + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.util.Hashtable; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.osgi.OSGiTestUtil; +import org.apache.tuscany.sca.contribution.osgi.impl.OSGiModelResolverImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +/* + * + * Supplychain using OSGi contributions, using an OSGi ModelResolver + * + * Notes: + * All OSGi bundle references should be resolvable using pure OSGi bundle mechanisms. No + * dummy bundles will be created to resolve combinations of OSGi and non-OSGi contributions + * + * All dependent OSGi contribution bundles should be installed before the referring contribution. + * Hence dependencies should be a tree and cannot contain cycles. + * + * For Jar files contained within OSGi bundles, Bundle-Classpath should be + * set so that standard OSGi class resolution is sufficient to resolve classes containing in + * nested jars or bundles. + */ + +public class OSGiResolverTestCase extends TestCase { + + + protected EmbeddedSCADomain domain; + protected BundleContext bundleContext; + + private SupplyChain supplyChainV1; + private SupplyChain supplyChainV2; + + @Override + protected void setUp() throws Exception { + + setUpOSGi(); + setUpSCA(); + } + + protected void setUpOSGi() throws Exception { + bundleContext = OSGiTestUtil.setUpOSGiTestRuntime(); + } + + protected void setUpSCA() throws Exception { + //Create a test embedded SCA domain + ClassLoader cl = getClass().getClassLoader(); + domain = new EmbeddedSCADomain(cl, "http://localhost"); + + //Start the domain + domain.start(); + + // Contribute the SCA contribution + ContributionService contributionService = domain.getContributionService(); + supplyChainV1 = new SupplyChain("../contribution-classes/target/classes", + contributionService, "V1"); + supplyChainV1.setUpSCA(); + + supplyChainV2 = new SupplyChain("../contribution-classes-v2/target/classes", + contributionService, "V2"); + supplyChainV2.setUpSCA(); + } + + + + @Override + public void tearDown() throws Exception { + + + supplyChainV1.tearDownSCA(); + supplyChainV2.tearDownSCA(); + + domain.stop(); + + domain.close(); + + OSGiTestUtil.shutdownOSGiRuntime(); + } + + + @SuppressWarnings("unchecked") + public void test() throws Exception { + + Class customerClass = supplyChainV1.customerBundle.loadClass("supplychain.customer.Customer"); + + Object customer = + domain.getService(customerClass, "CustomerComponent"); + + Method m = customerClass.getMethod("purchaseGoods"); + m.invoke(customer); + + System.out.println("Sleeping ..."); + Thread.sleep(1000); + + Class customerClassV2 = supplyChainV2.customerBundle.loadClass("supplychain.customer.Customer"); + + Object customerV2 = + domain.getService(customerClassV2, "CustomerComponentV2"); + + Method mV2 = customerClassV2.getMethod("purchaseGoods"); + mV2.invoke(customerV2); + + System.out.println("Sleeping ..."); + Thread.sleep(2000); + + System.out.println("Test complete"); + + } + + private class SupplyChain { + + private String folderName; + private ContributionService contributionService; + private String version; + + private Bundle customerBundle; + + + private Contribution customerContribution; + private Contribution retailerContribution; + private Contribution warehouseContribution; + private Contribution shipperContribution; + + + public SupplyChain(String folderName, ContributionService contributionService, String version) { + this.folderName = folderName; + this.contributionService = contributionService; + this.version = version; + } + + protected void setUpSCA() throws Exception { + File customerLocation = new File(folderName + "/Customer" + version + ".jar"); + URL customerContribURL = customerLocation.toURL(); + File retailerLocation = new File(folderName + "/Retailer" + version + ".jar"); + URL retailerContribURL = retailerLocation.toURL(); + File warehouseLocation = new File(folderName + "/Warehouse" + version + ".jar"); + URL warehouseContribURL = warehouseLocation.toURL(); + File shipperLocation = new File(folderName + "/Shipper" + version + ".jar"); + URL shipperContribURL = shipperLocation.toURL(); + + customerBundle = bundleContext.installBundle(customerContribURL.toString()); + Bundle retailerBundle = bundleContext.installBundle(retailerContribURL.toString()); + Bundle warehouseBundle = bundleContext.installBundle(warehouseContribURL.toString()); + Bundle shipperBundle = bundleContext.installBundle(shipperContribURL.toString()); + + Hashtable bundles = new Hashtable(); + bundles.put("Customer" + version + ".jar", customerBundle); + bundles.put("Retailer" + version + ".jar", retailerBundle); + bundles.put("Warehouse" + version + ".jar", warehouseBundle); + bundles.put("Shipper" + version + ".jar", shipperBundle); + + ModelResolver customerResolver = new OSGiModelResolverImpl(bundles); + + bundles = new Hashtable(); + bundles.put("Retailer" + version + ".jar", retailerBundle); + ModelResolver retailerResolver = new OSGiModelResolverImpl(bundles); + + bundles = new Hashtable(); + bundles.put("Warehouse" + version + ".jar", warehouseBundle); + ModelResolver warehouseResolver = new OSGiModelResolverImpl(bundles); + + bundles = new Hashtable(); + bundles.put("Shipper" + version + ".jar", shipperBundle); + ModelResolver shipperResolver = new OSGiModelResolverImpl(bundles); + + + shipperContribution = contributionService.contribute( + "Shipper" + version, + shipperContribURL, shipperResolver, false); + warehouseContribution = contributionService.contribute( + "Warehouse" + version, + warehouseContribURL, warehouseResolver, false); + retailerContribution = contributionService.contribute( + "Retailer" + version, + retailerContribURL, retailerResolver, false); + + customerContribution = contributionService.contribute( + "Customer" + version, + customerContribURL, customerResolver, false); + + for (Composite deployable : customerContribution.getDeployables()) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + + for (Composite deployable : retailerContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + for (Composite deployable : warehouseContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + for (Composite deployable : shipperContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + // Start Components from my composite + for (Composite deployable : customerContribution.getDeployables() ) { + domain.getCompositeActivator().activate(deployable); + domain.getCompositeActivator().start(deployable); + } + } + + public void tearDownSCA() throws Exception { + // Remove the contribution from the in-memory repository + contributionService.remove("Customer" + version); + contributionService.remove("Retailer" + version); + contributionService.remove("Warehouse" + version); + contributionService.remove("Shipper" + version); + + + // Stop Components from my composite + for (Composite deployable : customerContribution.getDeployables() ) { + domain.getCompositeActivator().stop(deployable); + domain.getCompositeActivator().deactivate(deployable); + } + + } + + } + +} diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/SCAResolverTestCase.java b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/SCAResolverTestCase.java new file mode 100644 index 0000000000..a2b3a7bc92 --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/java/org/apache/tuscany/sca/contribution/osgi/test/SCAResolverTestCase.java @@ -0,0 +1,240 @@ +/* + * 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.contribution.osgi.test; + + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.osgi.OSGiTestUtil; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain; + +/* + * + * Supplychain using OSGi contributions, using default SCA resolver + * + * This test uses two sets of four contributions where each set contains a bundle corresponding + * to the four components of supplychain (customer, retailer, warehouse and shipper). + * Tests classes from the bundle used in , and the bundles themselves + * used as the bundle in . + * + * Notes: + * All OSGi bundle references should be resolvable using pure OSGi bundle mechanisms. No + * dummy bundles will be created to resolve combinations of OSGi and non-OSGi contributions + * + * Notes: + * All OSGi bundle references should be resolvable using pure OSGi bundle mechanisms. No + * dummy bundles will be created to resolve combinations of OSGi and non-OSGi contributions + * + * All dependent OSGi contribution bundles should be installed before the referring contribution. + * Hence dependencies should be a tree and cannot contain cycles. + * + * For Jar files contained within OSGi bundles, Bundle-Classpath should be + * set so that standard OSGi class resolution is sufficient to resolve classes containing in + * nested jars or bundles. + */ + +public class SCAResolverTestCase extends TestCase { + + + protected EmbeddedSCADomain domain; + + private SupplyChain supplyChainV1; + private SupplyChain supplyChainV2; + + + protected String customerJarName = "Customer"; + protected String retailerJarName = "Retailer"; + protected String warehouseJarName = "Warehouse"; + protected String shipperJarName = "Shipper"; + + + + @Override + protected void setUp() throws Exception { + + setUpOSGi(); + setUpSCA(); + } + + protected void setUpOSGi() throws Exception { + OSGiTestUtil.setUpFelixTestRuntime(); + } + + protected void setUpSCA() throws Exception { + //Create a test embedded SCA domain + ClassLoader cl = getClass().getClassLoader(); + domain = new EmbeddedSCADomain(cl, "http://localhost"); + + //Start the domain + domain.start(); + + // Contribute the SCA contribution + ContributionService contributionService = domain.getContributionService(); + supplyChainV1 = new SupplyChain("../contribution-classes/target/classes", + contributionService, "V1"); + supplyChainV1.setUpSCA(); + + supplyChainV2 = new SupplyChain("../contribution-classes-v2/target/classes", + contributionService, "V2"); + supplyChainV2.setUpSCA(); + } + + + + @Override + public void tearDown() throws Exception { + + + supplyChainV1.tearDownSCA(); + supplyChainV2.tearDownSCA(); + + domain.stop(); + + domain.close(); + + OSGiTestUtil.shutdownOSGiRuntime(); + } + + + @SuppressWarnings("unchecked") + public void test() throws Exception { + + ClassReference customerClassRef = new ClassReference("supplychain.customer.Customer"); + customerClassRef = supplyChainV1.customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRef); + Class customerClass = customerClassRef.getJavaClass(); + + Object customer = + domain.getService(customerClass, "CustomerComponent"); + + Method m = customerClass.getMethod("purchaseGoods"); + m.invoke(customer); + + System.out.println("Sleeping ..."); + Thread.sleep(1000); + + ClassReference customerClassRefV2 = new ClassReference("supplychain.customer.Customer"); + customerClassRefV2 = supplyChainV2.customerContribution.getModelResolver().resolveModel(ClassReference.class, customerClassRefV2); + Class customerClassV2 = customerClassRefV2.getJavaClass(); + + Object customerV2 = + domain.getService(customerClassV2, "CustomerComponentV2"); + + Method mV2 = customerClassV2.getMethod("purchaseGoods"); + mV2.invoke(customerV2); + + System.out.println("Sleeping ..."); + Thread.sleep(2000); + + System.out.println("Test complete"); + + } + + private class SupplyChain { + + private String folderName; + private ContributionService contributionService; + private String version; + + private Contribution customerContribution; + private Contribution retailerContribution; + private Contribution warehouseContribution; + private Contribution shipperContribution; + + + public SupplyChain(String folderName, ContributionService contributionService, String version) { + this.folderName = folderName; + this.contributionService = contributionService; + this.version = version; + } + + protected void setUpSCA() throws Exception { + File customerLocation = new File(folderName + "/" + customerJarName + version + ".jar"); + URL customerContribURL = customerLocation.toURL(); + File retailerLocation = new File(folderName + "/" + retailerJarName + version + ".jar"); + URL retailerContribURL = retailerLocation.toURL(); + File warehouseLocation = new File(folderName + "/" + warehouseJarName + version + ".jar"); + URL warehouseContribURL = warehouseLocation.toURL(); + File shipperLocation = new File(folderName + "/" + shipperJarName + version + ".jar"); + URL shipperContribURL = shipperLocation.toURL(); + + shipperContribution = contributionService.contribute("Shipper" + + version, shipperContribURL, true); + warehouseContribution = contributionService.contribute("Warehouse" + + version, warehouseContribURL, true); + retailerContribution = contributionService.contribute("Retailer" + + version, retailerContribURL, true); + customerContribution = contributionService.contribute("Customer" + + version, customerContribURL, true); + + + for (Composite deployable : customerContribution.getDeployables()) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + + for (Composite deployable : retailerContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + for (Composite deployable : warehouseContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + for (Composite deployable : shipperContribution.getDeployables() ) { + domain.getDomainComposite().getIncludes().add(deployable); + domain.buildComposite(deployable); + } + + // Start Components from my composite + for (Composite deployable : customerContribution.getDeployables() ) { + domain.getCompositeActivator().activate(deployable); + domain.getCompositeActivator().start(deployable); + } + } + + public void tearDownSCA() throws Exception { + // Remove the contribution from the in-memory repository + contributionService.remove("Customer" + version); + contributionService.remove("Retailer" + version); + contributionService.remove("Warehouse" + version); + contributionService.remove("Shipper" + version); + + + // Stop Components from my composite + for (Composite deployable : customerContribution.getDeployables() ) { + domain.getCompositeActivator().stop(deployable); + domain.getCompositeActivator().deactivate(deployable); + } + + } + + } + +} diff --git a/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/resources/osgi/felix/felix.config.properties b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/resources/osgi/felix/felix.config.properties new file mode 100644 index 0000000000..ea8d272a0c --- /dev/null +++ b/branches/sca-java-1.5.2/itest/osgi-contribution/contribution-test/src/test/resources/osgi/felix/felix.config.properties @@ -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. +# +# +# Framework config properties. +# +org.osgi.framework.system.packages=org.osgi.framework; version=1.3.0, \ + org.osgi.service.packageadmin; version=1.2.0, \ + org.osgi.service.startlevel; version=1.0.0, \ + org.osgi.service.url; version=1.0.0 \ + org.osgi.util.tracker; version=1.3.2 + + +felix.auto.start.1= \ + "file://${FELIX_DIR}/org.apache.felix.scr/1.0.2/org.apache.felix.scr-1.0.2.jar" \ + "file://${FELIX_DIR}/org.apache.felix.configadmin/1.0.1/org.apache.felix.configadmin-1.0.1.jar" + +# "file://${FELIX_DIR}/org.apache.felix.bundlerepository/1.0.3/org.apache.felix.bundlerepository-1.0.3.jar" \ +# "file://${FELIX_DIR}/org.apache.felix.shell/1.0.1/org.apache.felix.shell-1.0.1.jar" \ +# "file://${FELIX_DIR}/org.apache.felix.shell.tui/1.0.1/org.apache.felix.shell.tui-1.0.1.jar" \ + +felix.startlevel.framework=1 +felix.startlevel.bundle=1 + +# +# Bundle config properties. +# +org.osgi.service.http.port=8080 +obr.shell.telnet=on -- cgit v1.2.3