diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..6b0b1270ff --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000000..424644d055 --- /dev/null +++ b/NOTICE @@ -0,0 +1,8 @@ + +Apache Aries +Copyright 2009-2011 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + + diff --git a/pom.xml b/pom.xml index 7caa6fe064..81f3897030 100644 --- a/pom.xml +++ b/pom.xml @@ -1,191 +1,211 @@ - - - 4.0.0 - - org.apache.aries - java5-parent - 0.3 - - - org.apache.aries.proxy - org.apache.aries.proxy.itests - Apache Aries Proxy iTests - - Integration tests using the standalone proxy-bundle. - - 0.4 - - - scm:svn:http://svn.apache.org/repos/asf/aries/tags/org.apache.aries.proxy.itests-0.4 - scm:svn:https://svn.apache.org/repos/asf/aries/tags/org.apache.aries.proxy.itests-0.4 - http://svn.apache.org/viewvc/aries/tags/org.apache.aries.proxy.itests-0.4 - - - - - - org.apache.aries.proxy - org.apache.aries.proxy - 0.4 - test - - - - org.apache.aries - org.apache.aries.util - 0.3 - test - - - - org.osgi - org.osgi.core - provided - - - org.osgi - org.osgi.compendium - provided - - - org.eclipse - osgi - provided - - - org.ops4j.pax.exam - pax-exam - test - - - org.ops4j.pax.exam - pax-exam-junit - test - - - org.ops4j.pax.exam - pax-exam-container-default - test - - - org.ops4j.pax.exam - pax-exam-junit-extender-impl - test - - - org.ops4j.pax.runner - pax-runner-no-jcl - - - junit - junit - test - - - org.apache.felix - org.apache.felix.configadmin - 1.2.4 - test - - - org.ops4j.pax.logging - pax-logging-api - test - - - org.ops4j.pax.logging - pax-logging-service - test - - - org.ops4j.pax.url - pax-url-mvn - test - - - asm - asm-all - 3.2 - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - pertest - - **/*$* - **/Abstract*.java - - - **/Test*.java - **/*Test.java - - - - - org.ops4j.pax.exam - maven-paxexam-plugin - - - generate-config - - generate-depends-file - - - ${project.build.directory}/test-classes/META-INF/maven/dependencies.properties - - - - - - - - - - ci-build-profile - - - maven.repo.local - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - -Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local} - - - - - - - - + + + 4.0.0 + + org.apache.aries + java5-parent + 0.5 + + + + org.apache.aries.proxy + org.apache.aries.proxy.itests + 0.4 + + Apache Aries Proxy iTests + + Integration tests using the standalone proxy-bundle. + + + + scm:svn:http://svn.apache.org/repos/asf/aries/tags/org.apache.aries.proxy.itests-0.4 + scm:svn:https://svn.apache.org/repos/asf/aries/tags/org.apache.aries.proxy.itests-0.4 + http://svn.apache.org/viewvc/aries/tags/org.apache.aries.proxy.itests-0.4 + + + + + org.osgi + org.osgi.core + provided + + + org.osgi + org.osgi.compendium + provided + + + org.eclipse + osgi + provided + + + org.eclipse.tycho + org.eclipse.osgi + 3.7.0.v20110613 + test + + + org.apache.aries.proxy + org.apache.aries.proxy + test + 0.4 + + + org.apache.aries + org.apache.aries.util + test + 0.4 + + + org.apache.aries.testsupport + org.apache.aries.testsupport.unit + 0.4 + test + + + org.ops4j.pax.exam + pax-exam + test + + + org.ops4j.pax.exam + pax-exam-junit + test + + + org.ops4j.pax.exam + pax-exam-container-default + test + + + org.ops4j.pax.exam + pax-exam-junit-extender-impl + test + + + org.ops4j.pax.runner + pax-runner-no-jcl + + + junit + junit + test + + + org.apache.felix + org.apache.felix.configadmin + 1.2.4 + + + org.apache.felix + org.osgi.compendium + + + org.apache.felix + org.osgi.core + + + + + org.ops4j.pax.logging + pax-logging-api + test + + + org.ops4j.pax.logging + pax-logging-service + test + + + org.ops4j.pax.url + pax-url-mvn + test + + + asm + asm-all + test + 3.2 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + pertest + + **/*$* + **/Abstract*.java + + + **/Test*.java + **/*Test.java + + + + + org.ops4j.pax.exam + maven-paxexam-plugin + + + generate-config + + generate-depends-file + + + ${project.build.directory}/test-classes/META-INF/maven/dependencies.properties + + + + + + + + + + ci-build-profile + + + maven.repo.local + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + -Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local} + + + + + + + + diff --git a/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java b/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java new file mode 100644 index 0000000000..13926595bc --- /dev/null +++ b/src/test/java/org/apache/aries/proxy/itests/AbstractProxyTest.java @@ -0,0 +1,268 @@ +/* + * 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 WARRANTIESOR 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.aries.proxy.itests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.lang.reflect.Method; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; + +import org.apache.aries.itest.AbstractIntegrationTest; +import org.apache.aries.proxy.InvocationListener; +import org.apache.aries.proxy.ProxyManager; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +public class AbstractProxyTest extends AbstractIntegrationTest { + + public final static class TestCallable implements Callable { + private Object list = new ArrayList(); + + public Object call() throws Exception { + return list; + } + + public void setReturn(Object o) { + list = o; + } + } + + public static class TestDelegate extends AbstractList implements Callable { + + private final String message; + + public TestDelegate(String message) { + super(); + this.message = message; + } + + public String call() throws Exception { + return message; + } + + public boolean equals(Object o) { + if(o instanceof TestDelegate){ + return message.equals(((TestDelegate)o).message); + } + return false; + } + + public void throwException() { + throw new RuntimeException(); + } + + public void testInternallyCaughtException() { + try { + throw new RuntimeException(); + } catch (RuntimeException re) { + // no op + } + } + + @Override + public String get(int location) { + return null; + } + + @Override + public int size() { + return 0; + } + } + + private class TestListener implements InvocationListener { + + boolean preInvoke = false; + boolean postInvoke = false; + boolean postInvokeExceptionalReturn = false; + Object token; + + public Object preInvoke(Object proxy, Method m, Object[] args) + throws Throwable { + preInvoke = true; + token = new Object(); + return token; + } + + public void postInvoke(Object token, Object proxy, Method m, + Object returnValue) throws Throwable { + postInvoke = this.token == token; + } + + public void postInvokeExceptionalReturn(Object token, Object proxy, + Method m, Throwable exception) throws Throwable { + postInvokeExceptionalReturn = this.token == token; + } + + public void clear() { + preInvoke = false; + postInvoke = false; + postInvokeExceptionalReturn = false; + token = null; + } + } + + @SuppressWarnings("unchecked") + @Test + public void testEquals() throws Exception { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + + TestCallable c = new TestCallable(); + c.setReturn(new TestDelegate("One")); + + TestCallable c2 = new TestCallable(); + c.setReturn(new TestDelegate("Two")); + + Collection> classes = new ArrayList>(); + classes.add(List.class); + Object proxy = mgr.createDelegatingProxy(b, classes, c, new TestDelegate("Three")); + Object otherProxy = mgr.createDelegatingProxy(b, classes, c, new TestDelegate("Four")); + Object totallyOtherProxy = mgr.createDelegatingProxy(b, classes, c2, new TestDelegate("Five")); + assertTrue("The object is not equal to itself", proxy.equals(proxy)); + assertTrue("The object is not equal to another proxy of itself", proxy.equals(otherProxy)); + assertFalse("The object is equal to proxy to another object", proxy.equals(totallyOtherProxy)); + } + + @Test + public void testDelegation() throws Exception { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + + TestCallable c = new TestCallable(); + + Collection> classes = new ArrayList>(); + classes.add(TestDelegate.class); + + TestDelegate proxy = (TestDelegate) mgr.createDelegatingProxy(b, classes, c, new TestDelegate("")); + + c.setReturn(new TestDelegate("Hello")); + + assertEquals("Wrong message", "Hello", proxy.call()); + + c.setReturn(new TestDelegate("Hello again")); + assertEquals("Wrong message", "Hello again", proxy.call()); + } + + @Test + public void testInterception() throws Exception { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + + TestDelegate td = new TestDelegate("Hello"); + + Collection> classes = new ArrayList>(); + classes.add(TestDelegate.class); + + TestListener tl = new TestListener(); + + TestDelegate proxy = (TestDelegate) mgr.createInterceptingProxy(b, classes, td, tl); + + //We need to call clear here, because the object will have had its toString() called + tl.clear(); + assertCalled(tl, false, false, false); + + assertEquals("Wrong message", "Hello", proxy.call()); + assertCalled(tl, true, true, false); + + tl.clear(); + assertCalled(tl, false, false, false); + + try { + proxy.throwException(); + fail("Should throw an exception"); + } catch (RuntimeException re) { + assertCalled(tl, true, false, true); + } + + tl.clear(); + assertCalled(tl, false, false, false); + + try { + proxy.testInternallyCaughtException(); + } finally { + assertCalled(tl, true, true, false); + } + } + + @Test + public void testDelegationAndInterception() throws Exception { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + + + TestCallable c = new TestCallable(); + + Collection> classes = new ArrayList>(); + classes.add(TestDelegate.class); + + TestListener tl = new TestListener(); + + TestDelegate proxy = (TestDelegate) mgr.createDelegatingInterceptingProxy(b, classes, c, new TestDelegate(""), tl); + + c.setReturn(new TestDelegate("Hello")); + + //We need to call clear here, because the object will have had its toString() called + tl.clear(); + assertCalled(tl, false, false, false); + + assertEquals("Wrong message", "Hello", proxy.call()); + assertCalled(tl, true, true, false); + + tl.clear(); + assertCalled(tl, false, false, false); + + c.setReturn(new TestDelegate("Hello again")); + + assertEquals("Wrong message", "Hello again", proxy.call()); + assertCalled(tl, true, true, false); + + tl.clear(); + assertCalled(tl, false, false, false); + + try { + proxy.throwException(); + fail("Should throw an exception"); + } catch (RuntimeException re) { + assertCalled(tl, true, false, true); + } + + tl.clear(); + assertCalled(tl, false, false, false); + + try { + proxy.testInternallyCaughtException(); + } finally { + assertCalled(tl, true, true, false); + } + } + + private void assertCalled(TestListener listener, boolean pre, boolean post, boolean ex) { + assertEquals(pre, listener.preInvoke); + assertEquals(post, listener.postInvoke); + assertEquals(ex, listener.postInvokeExceptionalReturn); + } +} diff --git a/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java b/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java index a0a54c8241..ba17bd1e48 100644 --- a/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java +++ b/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java @@ -19,17 +19,12 @@ package org.apache.aries.proxy.itests; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.ops4j.pax.exam.CoreOptions.equinox; -import static org.ops4j.pax.exam.CoreOptions.options; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; -import static org.ops4j.pax.exam.CoreOptions.wrappedBundle; -import static org.ops4j.pax.exam.OptionUtils.combine; +import static org.apache.aries.itest.ExtraOptions.*; import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.concurrent.Callable; import org.apache.aries.proxy.FinalModifierException; @@ -37,47 +32,14 @@ import org.apache.aries.proxy.UnableToProxyException; import org.junit.Test; import org.junit.runner.RunWith; -import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.JUnit4TestRunner; -import org.ops4j.pax.exam.options.MavenArtifactProvisionOption; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; @RunWith(JUnit4TestRunner.class) -public class BasicProxyTest +public class BasicProxyTest extends AbstractProxyTest { - private final class TestCallable implements Callable { - private List list = new ArrayList(); - - public Object call() throws Exception { - return list; - } - } - - @SuppressWarnings("unchecked") - @Test - public void testEquals() throws Exception - { - ProxyManager mgr = getService(ProxyManager.class); - Bundle b = FrameworkUtil.getBundle(this.getClass()); - - Callable c = new TestCallable(); - Callable c2 = new TestCallable(); - ((List)c2.call()).add("Some test data"); - - Collection> classes = new ArrayList>(); - classes.add(List.class); - Object proxy = mgr.createProxy(b, classes, c); - Object otherProxy = mgr.createProxy(b, classes, c); - Object totallyOtherProxy = mgr.createProxy(b, classes, c2); - assertTrue("The object is not equal to itself", proxy.equals(proxy)); - assertTrue("The object is not equal to another proxy of itself", proxy.equals(otherProxy)); - assertFalse("The object is equal to proxy to another object", proxy.equals(totallyOtherProxy)); - } - /** * This test does two things. First of all it checks that we throw a FinalModifierException if we * try to proxy a final class. It also validates that the message and toString in the exception @@ -86,13 +48,13 @@ public void testEquals() throws Exception @Test public void checkProxyFinalClass() throws UnableToProxyException { - ProxyManager mgr = getService(ProxyManager.class); + ProxyManager mgr = context().getService(ProxyManager.class); Bundle b = FrameworkUtil.getBundle(this.getClass()); Callable c = new TestCallable(); Collection> classes = new ArrayList>(); classes.add(TestCallable.class); try { - mgr.createProxy(b, classes, c); + mgr.createDelegatingProxy(b, classes, c, null); } catch (FinalModifierException e) { String msg = e.getMessage(); assertEquals("The message didn't look right", "The class " + TestCallable.class.getName() + " is final.", msg); @@ -107,7 +69,7 @@ public void checkProxyFinalClass() throws UnableToProxyException @Test public void checkProxyFinalMethods() throws UnableToProxyException { - ProxyManager mgr = getService(ProxyManager.class); + ProxyManager mgr = context().getService(ProxyManager.class); Bundle b = FrameworkUtil.getBundle(this.getClass()); Callable c = new TestCallable(); Collection> classes = new ArrayList>(); @@ -117,35 +79,16 @@ public final void run() { }; classes.add(r.getClass()); try { - mgr.createProxy(b, classes, c); + mgr.createDelegatingProxy(b, classes, c, null); } catch (FinalModifierException e) { assertTrue("The methods didn't appear in the message", e.getMessage().contains("run")); } } - private T getService(Class clazz) - { - BundleContext ctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - ServiceReference ref = ctx.getServiceReference(ProxyManager.class.getName()); - if (ref != null) { - return clazz.cast(ctx.getService(ref)); - } - return null; - } @org.ops4j.pax.exam.junit.Configuration public static Option[] configuration() { - Option[] options = options( - // Log - mavenBundle("org.ops4j.pax.logging", "pax-logging-api"), - mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), - // Felix Config Admin - mavenBundle("org.apache.felix", "org.apache.felix.configadmin"), - // Felix mvn url handler - mavenBundle("org.ops4j.pax.url", "pax-url-mvn"), - - - // this is how you set the default log level when using pax logging (logProfile) - systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"), + return testOptions( + paxLogging("DEBUG"), // Bundles mavenBundle("org.apache.aries", "org.apache.aries.util"), @@ -158,27 +101,5 @@ public static Option[] configuration() { equinox().version("3.5.0") ); - - options = updateOptions(options); - return options; - } - - public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) - { - return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject(); - } - protected static Option[] updateOptions(Option[] options) - { - // We need to add pax-exam-junit here when running with the ibm - // jdk to avoid the following exception during the test run: - // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration - if ("IBM Corporation".equals(System.getProperty("java.vendor"))) { - Option[] ibmOptions = options( - wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit")) - ); - options = combine(ibmOptions, options); - } - - return options; } } \ No newline at end of file diff --git a/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java b/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java new file mode 100644 index 0000000000..748069dd75 --- /dev/null +++ b/src/test/java/org/apache/aries/proxy/itests/WeavingProxyTest.java @@ -0,0 +1,108 @@ +/* + * 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.aries.proxy.itests; + +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; +import static org.ops4j.pax.exam.CoreOptions.equinox; +import static org.apache.aries.itest.ExtraOptions.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.Callable; + +import org.apache.aries.proxy.ProxyManager; +import org.apache.aries.proxy.weaving.WovenProxy; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.container.def.PaxRunnerOptions; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +@RunWith(JUnit4TestRunner.class) +public class WeavingProxyTest extends AbstractProxyTest +{ + + /** + * This test does two things. First of all it checks that we can proxy a final + * class. It also validates that the class implements WovenProxy, and that the + * delegation still works + */ + @Test + public void checkProxyFinalClass() throws Exception + { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + TestCallable dispatcher = new TestCallable(); + TestCallable template = new TestCallable(); + Collection> classes = new ArrayList>(); + classes.add(TestCallable.class); + Callable o = (Callable) mgr.createDelegatingProxy(b, classes, + dispatcher, template); + if(!!!(o instanceof WovenProxy)) + fail("Proxy should be woven!"); + + Object inner = new Integer(3); + dispatcher.setReturn(new TestCallable()); + ((TestCallable)dispatcher.call()).setReturn(inner); + + assertSame("Should return the same object", inner, o.call()); + } + + /** + * This method checks that we correctly proxy a class with final methods. + */ + @Test + public void checkProxyFinalMethods() throws Exception + { + ProxyManager mgr = context().getService(ProxyManager.class); + Bundle b = FrameworkUtil.getBundle(this.getClass()); + Callable c = new TestCallable(); + Collection> classes = new ArrayList>(); + Runnable r = new Runnable() { + public final void run() { + } + }; + classes.add(r.getClass()); + Object o = mgr.createDelegatingProxy(b, classes, c, r); + if(!!!(o instanceof WovenProxy)) + fail("Proxy should be woven!"); + } + + @org.ops4j.pax.exam.junit.Configuration + public static Option[] configuration() { + return testOptions( + paxLogging("DEBUG"), + + // Bundles + mavenBundle("org.apache.aries", "org.apache.aries.util"), + mavenBundle("org.apache.aries.proxy", "org.apache.aries.proxy"), + mavenBundle("asm", "asm-all"), + // don't install the blueprint sample here as it will be installed onto the same framework as the blueprint core bundle + // mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(), + mavenBundle("org.osgi", "org.osgi.compendium"), +// org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"), + PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"), + + equinox().version("3.7.0.v20110613") + ); + } +} \ No newline at end of file diff --git a/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java b/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java new file mode 100644 index 0000000000..48d29b2de5 --- /dev/null +++ b/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java @@ -0,0 +1,50 @@ +/* + * 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.ops4j.pax.runner.platform.equinox.internal; + +import org.ops4j.pax.runner.platform.PlatformBuilder; +import org.ops4j.pax.runner.platform.builder.AbstractPlatformBuilderActivator; +import org.osgi.framework.BundleContext; + +public class SsActivator extends AbstractPlatformBuilderActivator +{ + + /** + * {@inheritDoc} + */ + @Override + protected PlatformBuilder[] createPlatformBuilders( final BundleContext bundleContext ) + { + return new PlatformBuilder[]{ + new EquinoxPlatformBuilder( bundleContext, "3.2.1" ), + new EquinoxPlatformBuilder( bundleContext, "3.3.0" ), + new EquinoxPlatformBuilder( bundleContext, "3.3.1" ), + new EquinoxPlatformBuilder( bundleContext, "3.3.2" ), + new EquinoxPlatformBuilder( bundleContext, "3.4.0" ), + new EquinoxPlatformBuilder( bundleContext, "3.4.1" ), + new EquinoxPlatformBuilder( bundleContext, "3.4.2" ), + new EquinoxPlatformBuilder( bundleContext, "3.5.0" ), + new EquinoxPlatformBuilder( bundleContext, "3.5.1" ), + new EquinoxPlatformBuilder( bundleContext, "3.6.0" ), + new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20110613" ), + new EquinoxPlatformBuilderSnapshot( bundleContext ) + }; + } + +} diff --git a/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110613.xml b/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110613.xml new file mode 100644 index 0000000000..b59031547d --- /dev/null +++ b/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110613.xml @@ -0,0 +1,26 @@ + + + + Equinox 3.7.0 + mvn:org.eclipse.tycho/org.eclipse.osgi/3.7.0.v20110613 + + + + diff --git a/src/test/resources/ss-runner.properties b/src/test/resources/ss-runner.properties new file mode 100644 index 0000000000..6f98ce9dd8 --- /dev/null +++ b/src/test/resources/ss-runner.properties @@ -0,0 +1,244 @@ +# +# 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. +# + +# -------------------------------------------------------------------------------------------------------------------- +# The following bundles will always be instantiated +# -------------------------------------------------------------------------------------------------------------------- +# handler service (extender for url stream handlers) +handler.service=org.ops4j.pax.runner.handler.internal.Activator +# provision service (extender for scanners) +provision.service=org.ops4j.pax.scanner.internal.Activator +# platform service (extender for platforms) +platform.service=org.ops4j.pax.runner.platform.internal.Activator + +# -------------------------------------------------------------------------------------------------------------------- +# Known handlers +# -------------------------------------------------------------------------------------------------------------------- +# assembly protocol handler +handler.assembly=org.ops4j.pax.url.assembly.internal.Activator +# cache protocol handler +handler.cache=org.ops4j.pax.url.cache.internal.Activator +# classpath protocol handler +handler.classpath=org.ops4j.pax.url.classpath.internal.Activator +# dir protocol handler +handler.dir=org.ops4j.pax.url.dir.internal.Activator +# mvn protocol handler +handler.mvn=org.ops4j.pax.url.mvn.internal.Activator +# link protocol handler +handler.link=org.ops4j.pax.url.link.internal.Activator +# obr protocol handler +handler.obr=org.ops4j.pax.url.obr.internal.Activator +# war protocol handler +handler.war=org.ops4j.pax.url.war.internal.Activator +# wrap protocol handler +handler.wrap=org.ops4j.pax.url.wrap.internal.Activator + +# -------------------------------------------------------------------------------------------------------------------- +# Known scanners +# -------------------------------------------------------------------------------------------------------------------- +# scan-bundle +scanner.bundle=org.ops4j.pax.scanner.bundle.internal.Activator +# scan-composite +scanner.composite=org.ops4j.pax.scanner.composite.internal.Activator +# scan-dir +scanner.dir=org.ops4j.pax.scanner.dir.internal.Activator +# scan-file +scanner.features=org.ops4j.pax.scanner.features.internal.Activator +# scan-file +scanner.file=org.ops4j.pax.scanner.file.internal.Activator +# scan-obr +scanner.obr=org.ops4j.pax.scanner.obr.internal.Activator +# scan-pom +scanner.pom=org.ops4j.pax.scanner.pom.internal.Activator + +# -------------------------------------------------------------------------------------------------------------------- +# Known platforms +# -------------------------------------------------------------------------------------------------------------------- +## Equinox +platform.equinox.3.2.1=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.3.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.3.1=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.3.2=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.4.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.4.1=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.4.2=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.5.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.5.1=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.6.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.SNAPSHOT=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.V43PROTOTYPE-3.6.0.201003231329=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +platform.equinox.3.7.0.V20110613=org.ops4j.pax.runner.platform.equinox.internal.SsActivator +# Felix +platform.felix.1.0.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.0.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.0.3=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.0.4=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.2.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.2.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.2.2=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.4.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.4.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.6.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.6.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.8.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.1.8.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.2.0.0=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.2.0.1=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.2.0.2=org.ops4j.pax.runner.platform.felix.internal.Activator +platform.felix.SNAPSHOT=org.ops4j.pax.runner.platform.felix.internal.Activator +# Knopflerfish +platform.knopflerfish.2.0.0=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.0.1=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.0.2=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.0.3=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.0.4=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.0.5=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.1.0=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.1.1=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.2.0=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.3.0=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.3.1=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.3.2=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.2.3.3=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.3.0.0=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +platform.knopflerfish.SNAPSHOT=org.ops4j.pax.runner.platform.knopflerfish.internal.Activator +#Concierge +platform.concierge.1.0.0=org.ops4j.pax.runner.platform.concierge.internal.Activator +platform.concierge.SNAPSHOT=org.ops4j.pax.runner.platform.concierge.internal.Activator + +# -------------------------------------------------------------------------------------------------------------------- +# Aditional Services +# -------------------------------------------------------------------------------------------------------------------- +service.obr=org.apache.felix.bundlerepository.Activator + +# -------------------------------------------------------------------------------------------------------------------- +# Default values. +# Default values are used in case that an option / configuration property is not set. +# -------------------------------------------------------------------------------------------------------------------- +# defaults for runner options +# default list of handlers +default.handlers=handler.mvn,handler.classpath,handler.war,handler.wrap,handler.obr,handler.link,handler.cache,handler.assembly,handler.dir +# default list of scanners +default.scanners=scanner.bundle,scanner.composite,scanner.dir,scanner.features,scanner.file,scanner.obr,scanner.pom +# default platfom +default.platform=platform.felix +# default felix platform version +default.platform.felix.version=2.0.2 +# default equinox platform version +default.platform.equinox.version=3.5.1 +# default knopflerfish platform version +default.platform.knopflerfish.version=2.3.3 +# default concierge platform version +default.platform.concierge.version=1.0.0 +# default list of additional services +default.services=service.obr +# default obr repositories +default.obr.repository.url=http://bundles.osgi.org/obr/browse?_xml=1&cmd=repository +# default profiles repository +default.profilesRepositories=http://scm.ops4j.org/repos/ops4j/projects/pax/runner-repository +# default group id +default.profilesGroupId=org.ops4j.pax.runner.profiles +# default "snapshot" platform definition repository +default.snapshotsRepository=http://scm.ops4j.org/repos/ops4j/projects/pax/runner-repository +# default "snapshot" Felix platform definition URL +default.felix.snapshot.definition.url=mvn:${snapshotsRepository}!org.ops4j.pax.runner.platforms/felix//xml +# default "snapshot" Equinox platform definition URL +default.equinox.snapshot.definition.url=mvn:${snapshotsRepository}!org.ops4j.pax.runner.platforms/equinox//xml +# default "snapshot" Knopflerfish platform definition URL +default.knopflerfish.snapshot.definition.url=mvn:${snapshotsRepository}!org.ops4j.pax.runner.platforms/knopflerfish//xml +# default "snapshot" Concierge platform definition URL +default.concierge.snapshot.definition.url=mvn:${snapshotsRepository}!org.ops4j.pax.runner.platforms/concierge//xml +# default working directory +default.workingDirectory=runner +# default caching directory +default.org.ops4j.pax.url.cache.workingDirectory=${workingDirectory}/cache +# default platform working directory +default.org.ops4j.pax.runner.platform.workingDirectory=${workingDirectory} + + +# -------------------------------------------------------------------------------------------------------------------- +# Configuration properties alias +# Alias are used to transform configuration properties from the fully qualified ones to simple option name or +# to convert simple values from start arguments to the actual ones. +# -------------------------------------------------------------------------------------------------------------------- +# aliases for runner options +alias.platform=p +alias.platform.equinox=platform.equinox +alias.platform.e=platform.equinox +alias.platform.eq=platform.equinox +alias.platform.felix=platform.felix +alias.platform.f=platform.felix +alias.platform.knopflerfish=platform.knopflerfish +alias.platform.k=platform.knopflerfish +alias.platform.kf=platform.knopflerfish +alias.platform.concierge=platform.concierge +alias.platform.c=platform.concierge +alias.version=v +alias.snapshot=s +alias.workingDirectory=dir + +# aliases for handlers +alias.org.ops4j.pax.url.mvn.certificateCheck=certificateCheck +alias.org.ops4j.pax.url.mvn.defaultRepositories=defaultRepositories,dr +alias.org.ops4j.pax.url.mvn.localRepository=localRepository,lr,maven.repo.local +alias.org.ops4j.pax.url.mvn.repositories=repositories,repos +alias.org.ops4j.pax.url.mvn.settings=settings +alias.org.ops4j.pax.url.mvn.useFallbackRepositories=useFallbackRepositories,ufr +alias.org.ops4j.pax.url.obr.certificateCheck=certificateCheck +alias.org.ops4j.pax.url.war.certificateCheck=certificateCheck +alias.org.ops4j.pax.url.wrap.certificateCheck=certificateCheck +alias.org.ops4j.pax.scanner.composite.certificateCheck=certificateCheck +alias.org.ops4j.pax.scanner.features.certificateCheck=certificateCheck + +# aliases for platform options +alias.org.ops4j.pax.runner.platform.bootDelegation=bootDelegation,bd +alias.org.ops4j.pax.runner.platform.bundleStartLevel=bundleStartLevel,bsl +alias.org.ops4j.pax.runner.platform.classpath=classPath,cp +alias.org.ops4j.pax.runner.platform.console=console +alias.org.ops4j.pax.runner.platform.definitionURL=definitionURL +alias.org.ops4j.pax.runner.platform.frameworkProfile=frameworkProfile,fp +alias.org.ops4j.pax.runner.platform.ee=ee +alias.org.ops4j.pax.runner.platform.javaHome=javaHome,home +alias.org.ops4j.pax.runner.platform.overwrite=overwrite +alias.org.ops4j.pax.runner.platform.overwriteUserBundles=overwriteUserBundles +alias.org.ops4j.pax.runner.platform.overwriteSystemBundles=overwriteSystemBundles +alias.org.ops4j.pax.runner.platform.profileStartLevel=profileStartLevel,psl +alias.org.ops4j.pax.runner.platform.startLevel=startLevel,sl +alias.org.ops4j.pax.runner.platform.systemPackages=systemPackages,sp +alias.org.ops4j.pax.runner.platform.usePersistedState=usePersistedState,ups +alias.org.ops4j.pax.runner.platform.vmOptions=vmOptions,vmo +alias.org.ops4j.pax.runner.platform.debugClassLoading=debugClassLoading,dcl +alias.org.ops4j.pax.runner.platform.downloadFeedback=downloadFeedback,df +alias.org.ops4j.pax.runner.platform.autoWrap=autoWrap +alias.org.ops4j.pax.runner.platform.keepOriginalUrls=keepOriginalUrls,kou +alias.org.ops4j.pax.runner.platform.bundleValidation=bundleValidation +alias.org.ops4j.pax.runner.platform.skipInvalidBundles=skipInvalidBundles,sib +alias.org.ops4j.pax.runner.platform.useAbsoluteFilePaths=useAbsoluteFilePaths,absoluteFilePaths,uafp + +# aliases for scanners +alias.org.ops4j.pax.scanner.bundle.start=start +alias.org.ops4j.pax.scanner.composite.start=start +alias.org.ops4j.pax.scanner.dir.start=start +alias.org.ops4j.pax.scanner.features.start=start +alias.org.ops4j.pax.scanner.file.start=start +alias.org.ops4j.pax.scanner.obr.start=start +alias.org.ops4j.pax.scanner.pom.start=start + +# aliases for additional services +alias.obr.repository.url=obrRepositories|obrRepos