use of org.apache.aries.proxy.impl.AsmProxyManager in project aries by apache.
the class WovenProxyGeneratorTest method getProxyInstance.
@Override
protected Object getProxyInstance(Class<?> proxyClass) {
try {
if (proxyClass.getName().equals(ProxyTestClassAbstract.class.getName())) {
Collection<Class<?>> coll = new ArrayList<Class<?>>();
coll.add(proxyClass);
return new AsmProxyManager().createNewProxy(null, coll, new Callable() {
public Object call() throws Exception {
return null;
}
}, null);
}
return proxyClass.newInstance();
} catch (Exception e) {
return null;
}
}
use of org.apache.aries.proxy.impl.AsmProxyManager in project aries by apache.
the class WovenProxyGeneratorTest method testWovenClassPlusInterfaces.
/**
* This test checks that we can add interfaces to classes that don't implement
* them using dynamic subclassing. This is a little odd, but it came for
* free with support for proxying abstract classes!
* @throws Exception
*/
@Test
public void testWovenClassPlusInterfaces() throws Exception {
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() {
public Object call() throws Exception {
return weavingLoader.loadClass(ProxyTestClassChildOfAbstract.class.getName()).newInstance();
}
}, null);
//Should proxy the abstract method on the class
Method m = getProxyClass(ProxyTestClassAbstract.class).getMethod("getMessage");
assertEquals("Working", m.invoke(toCall));
//Should be a callable too!
assertEquals("Callable Works too!", ((Callable) toCall).call());
}
use of org.apache.aries.proxy.impl.AsmProxyManager in project aries by apache.
the class ProxySubclassGeneratorTest method testClassLoaders.
@SuppressWarnings("unchecked")
@Test
public void testClassLoaders() throws Exception {
ClassLoader clA = new LimitedClassLoader("org.apache.aries.proxy.test.a", null, null);
ClassLoader clB = new LimitedClassLoader("org.apache.aries.proxy.test.b", "org.apache.aries.proxy.test.a", clA);
ClassLoader clC = new LimitedClassLoader("org.apache.aries.proxy.test.c", "org.apache.aries.proxy.test.b", clB);
Class<?> clazzA = clA.loadClass("org.apache.aries.proxy.test.a.ProxyTestClassA");
Class<?> clazzB = clB.loadClass("org.apache.aries.proxy.test.b.ProxyTestClassB");
Class<?> clazzC = clC.loadClass("org.apache.aries.proxy.test.c.ProxyTestClassC");
final Object object = clazzC.getConstructor(String.class).newInstance("hello");
o = new AsmProxyManager().createNewProxy(null, Arrays.asList(clazzA, clazzB, clazzC), constantly(object), null);
generatedProxySubclass = o.getClass();
Method m = generatedProxySubclass.getDeclaredMethod("hello", new Class[] {});
Object returned = m.invoke(o);
assertEquals("hello", returned);
}
Aggregations