You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2017/01/11 14:38:34 UTC
svn commit: r1778298 - in /aries/trunk/proxy/proxy-impl: ./
src/main/java/org/apache/aries/proxy/impl/interfaces/
src/test/java/org/apache/aries/blueprint/proxy/
src/test/java/org/apache/aries/util/
Author: cschneider
Date: Wed Jan 11 14:38:34 2017
New Revision: 1778298
URL: http://svn.apache.org/viewvc?rev=1778298&view=rev
Log:
[ARIES-1657] Make proxy impl indepdendent of aries test support
Removed:
aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ClassLoaderProxy.java
aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/util/AriesFrameworkUtil.java
Modified:
aries/trunk/proxy/proxy-impl/pom.xml
aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/AbstractProxyTest.java
aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java
Modified: aries/trunk/proxy/proxy-impl/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/pom.xml?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/pom.xml (original)
+++ aries/trunk/proxy/proxy-impl/pom.xml Wed Jan 11 14:38:34 2017
@@ -119,10 +119,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.aries.testsupport</groupId>
- <artifactId>org.apache.aries.testsupport.unit</artifactId>
- <version>1.0.0</version>
- <scope>test</scope>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.5.5</version>
</dependency>
</dependencies>
Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java (original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/ProxyClassLoader.java Wed Jan 11 14:38:34 2017
@@ -69,7 +69,6 @@ final class ProxyClassLoader extends Cla
private static ClassLoader getClassloader(Bundle bundle) {
if (bundle == null) return ProxyClassLoader.class.getClassLoader();
- if (bundle instanceof ClassLoaderProxy) return ((ClassLoaderProxy) bundle).getClassLoader();
BundleWiring wiring = bundle != null ? bundle.adapt(BundleWiring.class) : null;
return wiring != null ? wiring.getClassLoader() : null;
}
Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/AbstractProxyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/AbstractProxyTest.java?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/AbstractProxyTest.java (original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/AbstractProxyTest.java Wed Jan 11 14:38:34 2017
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -33,6 +35,7 @@ import org.apache.aries.blueprint.proxy.
import org.apache.aries.proxy.InvocationListener;
import org.apache.aries.proxy.impl.SingleInstanceDispatcher;
import org.junit.Test;
+import org.osgi.framework.wiring.BundleWiring;
public abstract class AbstractProxyTest {
@@ -375,4 +378,10 @@ public abstract class AbstractProxyTest
Method m = ptca.getClass().getDeclaredMethod("getMessage");
assertEquals("Working", m.invoke(ptca));
}
+
+ public static BundleWiring getWiring(ClassLoader loader) throws Exception {
+ BundleWiring wiring = mock(BundleWiring.class);
+ when(wiring.getClassLoader()).thenReturn(loader);
+ return wiring;
+ }
}
Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java (original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java Wed Jan 11 14:38:34 2017
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
@@ -31,22 +33,16 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import org.apache.aries.blueprint.proxy.AbstractProxyTest.TestListener;
-import org.apache.aries.mocks.BundleMock;
-import org.apache.aries.proxy.impl.interfaces.ClassLoaderProxy;
import org.apache.aries.proxy.impl.interfaces.InterfaceProxyGenerator;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
import org.osgi.framework.wiring.BundleWiring;
@@ -74,32 +70,11 @@ public class InterfaceProxyingTest {
private Bundle testBundle;
- /**
- * Extended BundleMock which handles update() and adapt() methods
- */
- public static class BundleMockEx extends BundleMock {
- private BundleWiring currentWiring = Skeleton.newMock(BundleWiring.class);
-
- public BundleMockEx(String name, Dictionary<?, ?> properties) {
- super(name, properties);
- }
-
- public <A> A adapt(Class<A> type) {
- if (type == BundleWiring.class) {
- return (A) currentWiring;
- }
- return null;
- }
-
- public void update() throws BundleException {
- this.currentWiring = Skeleton.newMock(BundleWiring.class);
- }
- }
-
@Before
public void setup() {
- testBundle = Skeleton.newMock(new BundleMockEx("test",
- new Hashtable<Object, Object>()), Bundle.class);
+ testBundle = Mockito.mock(Bundle.class);
+ BundleWiring bundleWiring = Mockito.mock(BundleWiring.class);
+ Mockito.when(testBundle.adapt(BundleWiring.class)).thenReturn(bundleWiring);
}
@Test
@@ -268,14 +243,12 @@ public class InterfaceProxyingTest {
@Test
public void testNoStaleProxiesForRefreshedBundle() throws Exception {
- Bundle bundle = (Bundle) Skeleton.newMock(new Class<?>[] { Bundle.class, ClassLoaderProxy.class });
- Skeleton skel = Skeleton.getSkeleton(bundle);
+ Bundle bundle = mock(Bundle.class);
TestClassLoader loader = new TestClassLoader();
- skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loader);
- skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 10l);
- skel.setReturnValue(new MethodCall(Bundle.class, "adapt", BundleWiring.class), Skeleton.newMock(BundleWiring.class));
-
+ when(bundle.getLastModified()).thenReturn(10l);
+ BundleWiring wiring = AbstractProxyTest.getWiring(loader);
+ when(bundle.adapt(BundleWiring.class)).thenReturn(wiring);
Class<?> clazz = loader.loadClass("org.apache.aries.blueprint.proxy.TestInterface");
Object proxy = InterfaceProxyGenerator.getProxyInstance(bundle, null, Arrays.<Class<?>>asList(clazz), constantly(null), null);
@@ -286,11 +259,11 @@ public class InterfaceProxyingTest {
/* Now again but with a changed classloader as if the bundle had refreshed */
TestClassLoader loaderToo = new TestClassLoader();
- skel.setReturnValue(new MethodCall(ClassLoaderProxy.class, "getClassLoader"), loaderToo);
- skel.setReturnValue(new MethodCall(Bundle.class, "getLastModified"), 20l);
+ when(bundle.getLastModified()).thenReturn(20l);
// let's change the returned revision
- skel.setReturnValue(new MethodCall(Bundle.class, "adapt", BundleWiring.class), Skeleton.newMock(BundleWiring.class));
+ BundleWiring wiring2 = AbstractProxyTest.getWiring(loaderToo);
+ when(bundle.adapt(BundleWiring.class)).thenReturn(wiring2);
Class<?> clazzToo = loaderToo.loadClass("org.apache.aries.blueprint.proxy.TestInterface");
@@ -299,8 +272,8 @@ public class InterfaceProxyingTest {
ClassLoader parent2= proxyToo.getClass().getClassLoader().getParent();
- // parents should be different, as the are the classloaders of different bundle revisions
- assertTrue(parent1 != parent2);
+ //
+ assertTrue("parents should be different, as the are the classloaders of different bundle revisions", parent1 != parent2);
}
protected void assertCalled(TestListener listener, boolean pre, boolean post, boolean ex) {
@@ -316,4 +289,5 @@ public class InterfaceProxyingTest {
}
};
}
+
}
Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java (original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java Wed Jan 11 14:38:34 2017
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -48,11 +50,8 @@ import org.apache.aries.proxy.impl.AsmPr
import org.apache.aries.proxy.impl.SingleInstanceDispatcher;
import org.apache.aries.proxy.impl.SystemModuleClassLoader;
import org.apache.aries.proxy.impl.gen.ProxySubclassMethodHashSet;
-import org.apache.aries.proxy.impl.interfaces.ClassLoaderProxy;
import org.apache.aries.proxy.impl.weaving.WovenProxyGenerator;
import org.apache.aries.proxy.weaving.WovenProxy;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
import org.junit.BeforeClass;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -498,13 +497,9 @@ public class WovenProxyGeneratorTest ext
*/
@Test
public void testWovenClassPlusInterfaces() throws Exception {
- Bundle b = (Bundle) Skeleton.newMock(new Class<?>[] {Bundle.class, ClassLoaderProxy.class});
- BundleWiring bw = (BundleWiring) Skeleton.newMock(BundleWiring.class);
-
- Skeleton.getSkeleton(b).setReturnValue(new MethodCall(
- ClassLoaderProxy.class, "getClassLoader"), weavingLoader);
- Skeleton.getSkeleton(b).setReturnValue(new MethodCall(
- ClassLoaderProxy.class, "adapt", BundleWiring.class), bw);
+ Bundle b = mock(Bundle.class);
+ BundleWiring wiring = getWiring(weavingLoader);
+ when(b.adapt(BundleWiring.class)).thenReturn(wiring);
Object toCall = new AsmProxyManager().createDelegatingProxy(b, Arrays.asList(
getProxyClass(ProxyTestClassAbstract.class), Callable.class), new Callable() {
Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java?rev=1778298&r1=1778297&r2=1778298&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java (original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyPlusSubclassGeneratorTest.java Wed Jan 11 14:38:34 2017
@@ -21,6 +21,8 @@ package org.apache.aries.blueprint.proxy
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -36,11 +38,8 @@ import org.apache.aries.proxy.Invocation
import org.apache.aries.proxy.UnableToProxyException;
import org.apache.aries.proxy.impl.SingleInstanceDispatcher;
import org.apache.aries.proxy.impl.gen.ProxySubclassGenerator;
-import org.apache.aries.proxy.impl.interfaces.ClassLoaderProxy;
import org.apache.aries.proxy.impl.interfaces.InterfaceProxyGenerator;
import org.apache.aries.proxy.weaving.WovenProxy;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.Skeleton;
import org.junit.BeforeClass;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -57,17 +56,13 @@ public class WovenProxyPlusSubclassGener
private Callable<Object> testCallable = null;
private static Bundle testBundle;
- private static BundleWiring testBundleWiring;
@BeforeClass
- public static void createTestBundle() {
- testBundle = (Bundle) Skeleton.newMock(new Class<?>[] {Bundle.class, ClassLoaderProxy.class});
- testBundleWiring = (BundleWiring) Skeleton.newMock(BundleWiring.class);
-
- Skeleton.getSkeleton(testBundle).setReturnValue(new MethodCall(
- ClassLoaderProxy.class, "getClassLoader"), weavingLoader);
- Skeleton.getSkeleton(testBundle).setReturnValue(new MethodCall(
- ClassLoaderProxy.class, "adapt", BundleWiring.class), testBundleWiring);
+ public static void createTestBundle() throws Exception {
+ testBundle = mock(Bundle.class);
+ BundleWiring wiring = AbstractProxyTest.getWiring(weavingLoader);
+ when(testBundle.adapt(BundleWiring.class))
+ .thenReturn(wiring);
}
//Avoid running four weaving tests that don't apply to us