From d5f1d093fe6fa491cdec392dca7137639e98d149 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 15 Sep 2008 00:26:00 +0000 Subject: Pulled a recent revision of trunk into the sca-android branch, to apply the android patches from JIRA TUSCANY-2440 to it. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695318 13f79535-47bb-0310-9956-ffa450edef68 --- .../osgi/CouldNotLocateOSGiBundleTestCase.java | 64 ++++++++++++ .../osgi/MissingComponentTypeFileTestCase.java | 64 ++++++++++++ .../src/test/java/impl/osgi/OSGiTestBundles.java | 111 +++++++++++++++++++++ .../impl/osgi/PropertyShouldSpecifySRTestCase.java | 64 ++++++++++++ 4 files changed, 303 insertions(+) create mode 100644 branches/sca-android/itest/validation/src/test/java/impl/osgi/CouldNotLocateOSGiBundleTestCase.java create mode 100644 branches/sca-android/itest/validation/src/test/java/impl/osgi/MissingComponentTypeFileTestCase.java create mode 100644 branches/sca-android/itest/validation/src/test/java/impl/osgi/OSGiTestBundles.java create mode 100644 branches/sca-android/itest/validation/src/test/java/impl/osgi/PropertyShouldSpecifySRTestCase.java (limited to 'branches/sca-android/itest/validation/src/test/java/impl/osgi') diff --git a/branches/sca-android/itest/validation/src/test/java/impl/osgi/CouldNotLocateOSGiBundleTestCase.java b/branches/sca-android/itest/validation/src/test/java/impl/osgi/CouldNotLocateOSGiBundleTestCase.java new file mode 100644 index 0000000000..6f54ad140c --- /dev/null +++ b/branches/sca-android/itest/validation/src/test/java/impl/osgi/CouldNotLocateOSGiBundleTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 impl.osgi; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.logging.impl.DefaultLoggingMonitorImpl; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +import domain.CustomCompositeBuilder; + +/** + * This shows how to test the Calculator service component. + */ +public class CouldNotLocateOSGiBundleTestCase extends TestCase { + + private CustomCompositeBuilder customDomain; + + @Override + protected void setUp() throws Exception + { + //OSGiTestBundles.createBundle("src/main/resources/impl/osgi/MissingComponentTypeFile/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class); + + customDomain = CustomCompositeBuilder.getInstance(); + try { + customDomain.loadContribution("src/main/resources/impl/osgi/CouldNotLocateOSGiBundle/osgitest.composite", + "TestContribution", "src/main/resources/impl/osgi/CouldNotLocateOSGiBundle/"); + } catch (Exception ex){ + //throw ex; + } + } + + @Override + protected void tearDown() throws Exception { + //nothing to do + OSGiRuntime.stop(); + } + + public void testCalculator() { + Monitor monitor = customDomain.getMonitorInstance(); + Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem(); + + assertNotNull(problem); + assertEquals("CouldNotLocateOSGiBundle", problem.getMessageId()); + } +} diff --git a/branches/sca-android/itest/validation/src/test/java/impl/osgi/MissingComponentTypeFileTestCase.java b/branches/sca-android/itest/validation/src/test/java/impl/osgi/MissingComponentTypeFileTestCase.java new file mode 100644 index 0000000000..3d75fa8ccc --- /dev/null +++ b/branches/sca-android/itest/validation/src/test/java/impl/osgi/MissingComponentTypeFileTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 impl.osgi; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.logging.impl.DefaultLoggingMonitorImpl; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +import domain.CustomCompositeBuilder; + +/** + * This shows how to test the Calculator service component. + */ +public class MissingComponentTypeFileTestCase extends TestCase { + + private CustomCompositeBuilder customDomain; + + @Override + protected void setUp() throws Exception + { + OSGiTestBundles.createBundle("src/main/resources/impl/osgi/MissingComponentTypeFile/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class); + + customDomain = CustomCompositeBuilder.getInstance(); + try { + customDomain.loadContribution("src/main/resources/impl/osgi/MissingComponentTypeFile/osgitest.composite", + "TestContribution", "src/main/resources/impl/osgi/MissingComponentTypeFile/"); + } catch (Exception ex){ + //throw ex; + } + } + + @Override + protected void tearDown() throws Exception { + //nothing to do + OSGiRuntime.stop(); + } + + public void testCalculator() { + Monitor monitor = customDomain.getMonitorInstance(); + Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem(); + + assertNotNull(problem); + assertEquals("MissingComponentTypeFile", problem.getMessageId()); + } +} diff --git a/branches/sca-android/itest/validation/src/test/java/impl/osgi/OSGiTestBundles.java b/branches/sca-android/itest/validation/src/test/java/impl/osgi/OSGiTestBundles.java new file mode 100644 index 0000000000..398c028dd8 --- /dev/null +++ b/branches/sca-android/itest/validation/src/test/java/impl/osgi/OSGiTestBundles.java @@ -0,0 +1,111 @@ +/* + * 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 impl.osgi; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.net.URL; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + + +/** + * + * Utility class to create OSGi bundles + * + * @version $Rev$ $Date$ + */ +public class OSGiTestBundles { + + public static void createBundle(String jarName, + Class interfaceClass, Class implClass) throws Exception { + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + String EOL = System.getProperty("line.separator"); + + String packageName = interfaceClass.getPackage().getName(); + String bundleName = interfaceClass.getName(); + + String manifestStr = "Manifest-Version: 1.0" + EOL + + "Bundle-ManifestVersion: 2" + EOL + "Bundle-Name: " + + bundleName + EOL + "Bundle-SymbolicName: " + bundleName + EOL + + "Bundle-Version: " + "1.0.0" + EOL + + "Bundle-Localization: plugin" + EOL; + + StringBuilder manifestBuf = new StringBuilder(); + manifestBuf.append(manifestStr); + manifestBuf.append("Export-Package: " + packageName + EOL); + manifestBuf.append("Import-Package: org.osgi.framework" + EOL); + manifestBuf.append("Bundle-Activator: " + implClass.getName() + EOL); + + ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes()); + Manifest manifest = new Manifest(); + manifest.read(manifestStream); + + + JarOutputStream jarOut = new JarOutputStream(out, manifest); + + String interfaceClassName = interfaceClass.getName().replaceAll("\\.", + "/") + + ".class"; + + URL url = interfaceClass.getClassLoader().getResource( + interfaceClassName); + String path = url.getPath(); + + ZipEntry ze = new ZipEntry(interfaceClassName); + + jarOut.putNextEntry(ze); + FileInputStream file = new FileInputStream(path); + byte[] fileContents = new byte[file.available()]; + file.read(fileContents); + jarOut.write(fileContents); + + String implClassName = implClass.getName().replaceAll("\\.", + "/") + + ".class"; + + url = implClass.getClassLoader().getResource(implClassName); + path = url.getPath(); + + ze = new ZipEntry(implClassName); + + jarOut.putNextEntry(ze); + file = new FileInputStream(path); + fileContents = new byte[file.available()]; + file.read(fileContents); + jarOut.write(fileContents); + + file.close(); + + jarOut.close(); + out.close(); + + FileOutputStream fileOut = new FileOutputStream(jarName); + fileOut.write(out.toByteArray()); + fileOut.close(); + + + } +} diff --git a/branches/sca-android/itest/validation/src/test/java/impl/osgi/PropertyShouldSpecifySRTestCase.java b/branches/sca-android/itest/validation/src/test/java/impl/osgi/PropertyShouldSpecifySRTestCase.java new file mode 100644 index 0000000000..117a94337a --- /dev/null +++ b/branches/sca-android/itest/validation/src/test/java/impl/osgi/PropertyShouldSpecifySRTestCase.java @@ -0,0 +1,64 @@ +/* + * 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 impl.osgi; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.logging.impl.DefaultLoggingMonitorImpl; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +import domain.CustomCompositeBuilder; + +/** + * This shows how to test the Calculator service component. + */ +public class PropertyShouldSpecifySRTestCase extends TestCase { + + private CustomCompositeBuilder customDomain; + + @Override + protected void setUp() throws Exception + { + OSGiTestBundles.createBundle("src/main/resources/impl/osgi/PropertyShouldSpecifySR/OSGiTestService.jar", OSGiTestInterface.class, OSGiTestImpl.class); + + customDomain = CustomCompositeBuilder.getInstance(); + try { + customDomain.loadContribution("src/main/resources/impl/osgi/PropertyShouldSpecifySR/osgitest.composite", + "TestContribution", "src/main/resources/impl/osgi/PropertyShouldSpecifySR/"); + } catch (Exception ex){ + //throw ex; + } + } + + @Override + protected void tearDown() throws Exception { + //nothing to do + OSGiRuntime.stop(); + } + + public void testCalculator() { + Monitor monitor = customDomain.getMonitorInstance(); + Problem problem = ((DefaultLoggingMonitorImpl)monitor).getLastLoggedProblem(); + + assertNotNull(problem); + assertEquals("PropertyShouldSpecifySR", problem.getMessageId()); + } +} -- cgit v1.2.3