@Test void testClassesWithGenericsAsReturnValueProxyDefault() { try { ProxyAspect aspect = ProxyAspect.of(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); } } }
@Test void testAdviceWithInnerClass() { ProxyAspect proxyAspect = new ProxyAspect(InvalidAdvice.class, methodInfo -> true); try { Proxetta.proxyProxetta().withAspect(proxyAspect).proxy().setTarget(Foo.class).newInstance(); fail("error"); } catch (ProxettaException ignore) { System.out.println(ignore); } } }
@Test void testClassesWithGenericsAsReturnValueProxy() { try { ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); } }
@Test void testCollector() throws NoSuchFieldException, IllegalAccessException { ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects( new ProxyAspect(CollectorAdvice.class, new AllTopMethodsPointcut()) ); // proxetta.setDebugFolder("d:\\"); Foo foo = (Foo) proxetta.proxy().setTarget(Foo.class).newInstance(); Field field = foo.getClass().getDeclaredField("$__methods$0"); field.setAccessible(true); List<String> list = (List<String>) field.get(foo); assertNotNull(list); assertEquals(0, list.size()); foo.m1(); assertEquals(1, list.size()); assertEquals("m1", list.get(0)); foo.m1(); assertEquals(2, list.size()); assertEquals("m1", list.get(0)); assertEquals("m1", list.get(1)); } }
@Test void testClassesWithGenericArraysAsReturnValueProxy() { try { ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspect(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } } }
Foo foo = (Foo) builder.newInstance(); foo = (Foo) builder.newInstance(); builder = proxyProxetta.proxy(); builder.setTarget(Foo.class); foo = (Foo) builder.newInstance(); builder = proxyProxetta.proxy().setTarget(Foo.class).setTargetProxyClassName(".Too"); foo = (Foo) builder.newInstance(); builder.setTarget(Foo.class); builder.setTargetProxyClassName("foo."); foo = (Foo) builder.newInstance(); builder.setTargetProxyClassName("foo.Fff"); builder.setTarget(Foo.class); foo = (Foo) builder.newInstance();
@Test void testInnerOverride() { ProxyProxetta proxyProxetta = Proxetta.proxyProxetta().withAspect(new ProxyAspect(FooProxyAdvice.class, new AllMethodsPointcut())); ProxyProxettaFactory builder = proxyProxetta.proxy(); builder.setTarget(Two.class); builder.setTargetProxyClassName("foo."); Two two = (Two) builder.newInstance(); assertNotNull(two); assertEquals("foo.Two" + ProxettaNames.proxyClassNameSuffix, two.getClass().getName()); }
builder.setTarget(Object.class); builder.setTargetProxyClassName("foo."); Object object = builder.newInstance(); List list = (List) builder.newInstance(); assertNotNull(list); assertEquals("foo.ArrayList" + ProxettaNames.proxyClassNameSuffix, list.getClass().getName()); Set set = (Set) builder.newInstance();
@Test void testAbstract2() { ProxyAspect proxyAspect = new ProxyAspect(FooProxyAdvice.class, methodInfo -> true); try { Proxetta.proxyProxetta().withAspect(proxyAspect).proxy().setTarget(Abstra2.class).newInstance(); fail("error"); } catch (ProxettaException ignore) { } }
@Test void testInterface() { ProxyAspect proxyAspect = new ProxyAspect(FooProxyAdvice.class, methodInfo -> true); try { Proxetta.proxyProxetta().withAspects(proxyAspect).proxy().setTarget(Inter.class).newInstance(); fail("error"); } catch (ProxettaException ignore) { } }
ProxyProxettaFactory pb = proxyProxetta.proxy(); pb.setTarget(Foo.class); Foo foo = (Foo) pb.newInstance();
@Test void testProxyInfo_createNotRightAfterTheMethod() { ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspects()); //proxetta.setDebugFolder(SystemUtil.userHome()); DateDao dateDateProxy = (DateDao) proxetta.proxy().setTarget(DateDao.class).newInstance(); LocalDateTime jDateTime = dateDateProxy.currentTime(); assertNotNull(jDateTime); }
@Test void testAbstract1() { ProxyAspect proxyAspect = new ProxyAspect(FooProxyAdvice.class, methodInfo -> true); Abstra aaa = (Abstra) Proxetta.proxyProxetta().withAspect(proxyAspect).proxy().setTarget(Abstra.class).newInstance(); assertNotNull(aaa); aaa.foo(); }
@Test void testMethRefOnProxifiedClass() { Methref<? extends Oink> m = Methref.on(Oink.class); m.to().woink(); assertEquals("woink", m.ref()); ProxyAspect a1 = new ProxyAspect(DummyAdvice.class, new AllTopMethodsPointcut()); ProxyProxetta pp = Proxetta.proxyProxetta().withAspect(a1); Oink oink = (Oink) pp.proxy().setTarget(Oink.class).newInstance(); assertFalse(oink.getClass().equals(Oink.class)); m = Methref.on(oink.getClass()); m.to().woink(); assertEquals("woink", m.ref()); }
@Test void testProxyProxetta_open() { ProxyAspect proxyAspect = ProxyAspect.of(LogProxyAdvice.class, MethodWithAnnotationPointcut.of(Transaction.class)); Test568OpenService service = (Test568OpenService) Proxetta.proxyProxetta() .withAspect(proxyAspect) .proxy() .setTarget(Test568OpenService.class) .newInstance(); String result = service.findMember(2L); assertEquals("2", result); } }
@Test void testExtendingGenerics() { ProxyAspect aspect = new ProxyAspect(LogAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(MyBoo.class); Boo boo = (Boo) builder.newInstance(); boo.save(new Foo()); } }
ProxyProxettaFactory pb = proxyProxetta.proxy(); pb.setTarget(Foo.class); Foo foo = (Foo) pb.newInstance();