Search in sources :

Example 11 with ProxyProxettaBuilder

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());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) AllMethodsPointcut(jodd.proxetta.pointcuts.AllMethodsPointcut) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) Test(org.junit.Test)

Example 12 with ProxyProxettaBuilder

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());
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) AllMethodsPointcut(jodd.proxetta.pointcuts.AllMethodsPointcut) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) Test(org.junit.Test)

Example 13 with ProxyProxettaBuilder

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());
    }
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 14 with ProxyProxettaBuilder

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();
}
Also used : ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder)

Aggregations

ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)14 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)10 Test (org.junit.Test)9 AllMethodsPointcut (jodd.proxetta.pointcuts.AllMethodsPointcut)5 Field (java.lang.reflect.Field)2 Retro (jodd.proxetta.data.Retro)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ProxettaBeanDefinition (jodd.petite.proxetta.ProxettaBeanDefinition)1 ProxyAspect (jodd.proxetta.ProxyAspect)1 Foo (jodd.proxetta.data.Foo)1 FooAnn (jodd.proxetta.data.FooAnn)1 ReflectionReplacementAdvice (jodd.proxetta.data.ReflectionReplacementAdvice)1 ReturnNullAdvice (jodd.proxetta.data.ReturnNullAdvice)1