use of jodd.proxetta.impl.ProxyProxettaBuilder in project jodd by oblac.
the class SubclassTest method testProxyClassNames.
@Test
public void testProxyClassNames() {
ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(new ProxyAspect(FooProxyAdvice.class, new AllMethodsPointcut()));
proxyProxetta.setVariableClassName(true);
ProxyProxettaBuilder builder = proxyProxetta.builder();
builder.setTarget(Foo.class);
Foo foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals(Foo.class.getName() + "$$Proxetta", StringUtil.substring(foo.getClass().getName(), 0, -1));
builder = proxyProxetta.builder();
builder.setTarget(Foo.class);
foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals(Foo.class.getName() + "$$Proxetta", StringUtil.substring(foo.getClass().getName(), 0, -1));
proxyProxetta.setClassNameSuffix("$$Ppp");
builder = proxyProxetta.builder();
builder.setTarget(Foo.class);
foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals(Foo.class.getName() + "$$Ppp", StringUtil.substring(foo.getClass().getName(), 0, -1));
proxyProxetta.setClassNameSuffix("$$Proxetta");
proxyProxetta.setVariableClassName(false);
builder = proxyProxetta.builder(Foo.class, ".Too");
foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals(Foo.class.getPackage().getName() + ".Too$$Proxetta", foo.getClass().getName());
builder = proxyProxetta.builder();
builder.setTarget(Foo.class);
builder.setTargetProxyClassName("foo.");
foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals("foo.Foo$$Proxetta", foo.getClass().getName());
proxyProxetta.setClassNameSuffix(null);
builder = proxyProxetta.builder();
builder.setTargetProxyClassName("foo.Fff");
builder.setTarget(Foo.class);
foo = (Foo) builder.newInstance();
assertNotNull(foo);
assertEquals("foo.Fff", foo.getClass().getName());
}
use of jodd.proxetta.impl.ProxyProxettaBuilder in project jodd by oblac.
the class SubclassTest method testInnerOverride.
@Test
public void testInnerOverride() {
ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(new ProxyAspect(FooProxyAdvice.class, new AllMethodsPointcut()));
ProxyProxettaBuilder builder = proxyProxetta.builder();
builder.setTarget(Two.class);
builder.setTargetProxyClassName("foo.");
Two two = (Two) builder.newInstance();
assertNotNull(two);
assertEquals("foo.Two$$Proxetta", two.getClass().getName());
}
use of jodd.proxetta.impl.ProxyProxettaBuilder in project jodd by oblac.
the class SubclassTest method test1.
@Test
public void test1() {
ProxyAspect a1 = new ProxyAspect(FooProxyAdvice.class, new ProxyPointcut() {
public boolean apply(MethodInfo methodInfo) {
return true;
}
});
/*
byte[] b = Proxetta.withAspects(a1).createProxy(Foo.class);
try {
FileUtil.writeBytes("d:\\Foo.class", b);
} catch (IOException e) {
e.printStackTrace();
}
*/
ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(a1);
proxyProxetta.setClassNameSuffix("$$$Proxetta");
ProxyProxettaBuilder pb = proxyProxetta.builder();
pb.setTarget(Foo.class);
Foo foo = (Foo) pb.newInstance();
Class fooProxyClass = foo.getClass();
assertNotNull(fooProxyClass);
Method[] methods = fooProxyClass.getMethods();
assertEquals(12, methods.length);
try {
fooProxyClass.getMethod("m1");
} catch (NoSuchMethodException nsmex) {
fail(nsmex.toString());
}
methods = fooProxyClass.getDeclaredMethods();
assertEquals(15, methods.length);
try {
fooProxyClass.getDeclaredMethod("m2");
} catch (NoSuchMethodException nsmex) {
fail(nsmex.toString());
}
}
use of jodd.proxetta.impl.ProxyProxettaBuilder in project jodd by oblac.
the class MethrefProxetta method defineProxy.
/**
* Generates new class.
*/
public Class defineProxy(Class target) {
ProxyProxettaBuilder builder = proxetta.builder();
builder.setTarget(target);
return builder.define();
}
Aggregations