You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by no...@apache.org on 2010/12/22 17:05:23 UTC

svn commit: r1051964 - in /incubator/aries/trunk/proxy: pom.xml proxy-itests/src/test/java/org/apache/aries/proxy/itests/BasicProxyTest.java

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 @@
                 <version>3.2</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>org.apache.felix.configadmin</artifactId>
+                <version>1.2.4</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.apache.felix</groupId>
+                        <artifactId>org.osgi.core</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.apache.felix</groupId>
+                        <artifactId>org.osgi.compendium</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
             	<groupId>org.apache.aries</groupId>
             	<artifactId>org.apache.aries.util</artifactId>
             	<version>${project.version}</version>
@@ -88,6 +103,7 @@
       <module>proxy-api</module>
       <module>proxy-impl</module>
       <module>proxy-bundle</module>
+      <module>proxy-itests</module>
     </modules>
 
 </project>

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<Object> {
+    private List<?> list = new ArrayList<Object>();
+
+    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<Object> c = new TestCallable();
+    Callable<Object> c2 = new TestCallable();
+    ((List<Object>)c2.call()).add("Some test data");
+    
+    Collection<Class<?>> classes = new ArrayList<Class<?>>();
+    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> T getService(Class<T> 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