Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 65738 invoked from network); 22 Dec 2010 16:05:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Dec 2010 16:05:51 -0000 Received: (qmail 77583 invoked by uid 500); 22 Dec 2010 16:05:50 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 77499 invoked by uid 500); 22 Dec 2010 16:05:50 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 77489 invoked by uid 99); 22 Dec 2010 16:05:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Dec 2010 16:05:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Dec 2010 16:05:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F1CBB23888E8; Wed, 22 Dec 2010 16:05:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1051964 - in /incubator/aries/trunk/proxy: pom.xml proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java Date: Wed, 22 Dec 2010 16:05:23 -0000 To: aries-commits@incubator.apache.org From: not@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101222160523.F1CBB23888E8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: not Date: Wed Dec 22 16:05:23 2010 New Revision: 1051964 URL: http://svn.apache.org/viewvc?rev=1051964&view=rev Log: ARIES-522 Commit a test that ensures that the equals method for proxies works correctly Added: incubator/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java Modified: incubator/aries/trunk/proxy/pom.xml Modified: incubator/aries/trunk/proxy/pom.xml URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/pom.xml?rev=1051964&r1=1051963&r2=1051964&view=diff ============================================================================== --- incubator/aries/trunk/proxy/pom.xml (original) +++ incubator/aries/trunk/proxy/pom.xml Wed Dec 22 16:05:23 2010 @@ -52,6 +52,21 @@ 3.2 + org.apache.felix + org.apache.felix.configadmin + 1.2.4 + + + org.apache.felix + org.osgi.core + + + org.apache.felix + org.osgi.compendium + + + + org.apache.aries org.apache.aries.util ${project.version} @@ -88,6 +103,7 @@ proxy-api proxy-impl proxy-bundle + proxy-itests Added: incubator/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java?rev=1051964&view=auto ============================================================================== --- incubator/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java (added) +++ incubator/aries/trunk/proxy/proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java Wed Dec 22 16:05:23 2010 @@ -0,0 +1,136 @@ +/* + * 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.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 java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; + +import org.apache.aries.proxy.ProxyManager; +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 +{ + 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)); + + } + 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"), + + // 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"), + + 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