Search in sources :

Example 1 with IOther

use of cn.taketoday.beans.testfixture.beans.IOther in project today-framework by TAKETODAY.

the class ProxyFactoryTests method testGetsAllInterfaces.

@Test
public void testGetsAllInterfaces() throws Exception {
    // Extend to get new interface
    class TestBeanSubclass extends TestBean implements Comparable<Object> {

        @Override
        public int compareTo(Object arg0) {
            throw new UnsupportedOperationException("compareTo");
        }
    }
    TestBeanSubclass raw = new TestBeanSubclass();
    ProxyFactory factory = new ProxyFactory(raw);
    // System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
    assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
    ITestBean tb = (ITestBean) factory.getProxy();
    assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
    raw.setAge(25);
    assertThat(tb.getAge() == raw.getAge()).isTrue();
    long t = 555555L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
    Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
    factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
    assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
    TimeStamped ts = (TimeStamped) factory.getProxy();
    assertThat(ts.getTimeStamp() == t).isTrue();
    // Shouldn't fail;
    ((IOther) ts).absquatulate();
}
Also used : ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) IOther(cn.taketoday.beans.testfixture.beans.IOther) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Test(org.junit.jupiter.api.Test)

Example 2 with IOther

use of cn.taketoday.beans.testfixture.beans.IOther in project today-framework by TAKETODAY.

the class ProxyFactoryTests method testGetsAllInterfaces.

@Test
public void testGetsAllInterfaces() {
    // Extend to get new interface
    class TestBeanSubclass extends TestBean implements Comparable<Object> {

        @Override
        public int compareTo(Object arg0) {
            throw new UnsupportedOperationException("compareTo");
        }
    }
    TestBeanSubclass raw = new TestBeanSubclass();
    ProxyFactory factory = new ProxyFactory(raw);
    // System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
    assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
    ITestBean tb = (ITestBean) factory.getProxy();
    assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
    raw.setAge(25);
    assertThat(tb.getAge() == raw.getAge()).isTrue();
    long t = 555555L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
    Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
    factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
    assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
    TimeStamped ts = (TimeStamped) factory.getProxy();
    assertThat(ts.getTimeStamp() == t).isTrue();
    // Shouldn't fail;
    ((IOther) ts).absquatulate();
}
Also used : TimestampIntroductionInterceptor(cn.taketoday.aop.testfixture.interceptor.TimestampIntroductionInterceptor) IOther(cn.taketoday.beans.testfixture.beans.IOther) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Test(org.junit.jupiter.api.Test)

Example 3 with IOther

use of cn.taketoday.beans.testfixture.beans.IOther in project today-framework by TAKETODAY.

the class AbstractAopProxyTests method testEquals.

@Test
public void testEquals() {
    IOther a = new AllInstancesAreEqual();
    IOther b = new AllInstancesAreEqual();
    NopInterceptor i1 = new NopInterceptor();
    NopInterceptor i2 = new NopInterceptor();
    ProxyFactory pfa = new ProxyFactory(a);
    pfa.addAdvice(i1);
    ProxyFactory pfb = new ProxyFactory(b);
    pfb.addAdvice(i2);
    IOther proxyA = (IOther) createProxy(pfa);
    IOther proxyB = (IOther) createProxy(pfb);
    assertThat(pfb.getAdvisors().length).isEqualTo(pfa.getAdvisors().length);
    assertThat(b).isEqualTo(a);
    assertThat(i2).isEqualTo(i1);
    assertThat(proxyB).isEqualTo(proxyA);
    assertThat(proxyB.hashCode()).isEqualTo(proxyA.hashCode());
    assertThat(proxyA.equals(a)).isFalse();
    // Equality checks were handled by the proxy
    assertThat(i1.getCount()).isEqualTo(0);
    // When we invoke A, it's NopInterceptor will have count == 1
    // and won't think it's equal to B's NopInterceptor
    proxyA.absquatulate();
    assertThat(i1.getCount()).isEqualTo(1);
    assertThat(proxyA.equals(proxyB)).isFalse();
}
Also used : NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) IOther(cn.taketoday.beans.testfixture.beans.IOther) Test(org.junit.jupiter.api.Test)

Example 4 with IOther

use of cn.taketoday.beans.testfixture.beans.IOther in project today-infrastructure by TAKETODAY.

the class AbstractAopProxyTests method testEquals.

@Test
public void testEquals() {
    IOther a = new AllInstancesAreEqual();
    IOther b = new AllInstancesAreEqual();
    NopInterceptor i1 = new NopInterceptor();
    NopInterceptor i2 = new NopInterceptor();
    ProxyFactory pfa = new ProxyFactory(a);
    pfa.addAdvice(i1);
    ProxyFactory pfb = new ProxyFactory(b);
    pfb.addAdvice(i2);
    IOther proxyA = (IOther) createProxy(pfa);
    IOther proxyB = (IOther) createProxy(pfb);
    assertThat(pfb.getAdvisors().length).isEqualTo(pfa.getAdvisors().length);
    assertThat(b).isEqualTo(a);
    assertThat(i2).isEqualTo(i1);
    assertThat(proxyB).isEqualTo(proxyA);
    assertThat(proxyB.hashCode()).isEqualTo(proxyA.hashCode());
    assertThat(proxyA.equals(a)).isFalse();
    // Equality checks were handled by the proxy
    assertThat(i1.getCount()).isEqualTo(0);
    // When we invoke A, it's NopInterceptor will have count == 1
    // and won't think it's equal to B's NopInterceptor
    proxyA.absquatulate();
    assertThat(i1.getCount()).isEqualTo(1);
    assertThat(proxyA.equals(proxyB)).isFalse();
}
Also used : NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) IOther(cn.taketoday.beans.testfixture.beans.IOther) Test(org.junit.jupiter.api.Test)

Example 5 with IOther

use of cn.taketoday.beans.testfixture.beans.IOther in project today-infrastructure by TAKETODAY.

the class ProxyFactoryTests method testGetsAllInterfaces.

@Test
public void testGetsAllInterfaces() {
    // Extend to get new interface
    class TestBeanSubclass extends TestBean implements Comparable<Object> {

        @Override
        public int compareTo(Object arg0) {
            throw new UnsupportedOperationException("compareTo");
        }
    }
    TestBeanSubclass raw = new TestBeanSubclass();
    ProxyFactory factory = new ProxyFactory(raw);
    // System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
    assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
    ITestBean tb = (ITestBean) factory.getProxy();
    assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
    raw.setAge(25);
    assertThat(tb.getAge() == raw.getAge()).isTrue();
    long t = 555555L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
    Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
    factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
    assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
    TimeStamped ts = (TimeStamped) factory.getProxy();
    assertThat(ts.getTimeStamp() == t).isTrue();
    // Shouldn't fail;
    ((IOther) ts).absquatulate();
}
Also used : TimestampIntroductionInterceptor(cn.taketoday.aop.testfixture.interceptor.TimestampIntroductionInterceptor) IOther(cn.taketoday.beans.testfixture.beans.IOther) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Test(org.junit.jupiter.api.Test)

Aggregations

IOther (cn.taketoday.beans.testfixture.beans.IOther)6 Test (org.junit.jupiter.api.Test)6 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)3 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)3 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)3 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)2 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)2 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)2 TimestampIntroductionInterceptor (cn.taketoday.aop.testfixture.interceptor.TimestampIntroductionInterceptor)2 TimeStamped (cn.taketoday.core.testfixture.TimeStamped)2 NopInterceptor (cn.taketoday.aop.NopInterceptor)1 SerializableNopInterceptor (cn.taketoday.aop.SerializableNopInterceptor)1