Search in sources :

Example 1 with IOther

use of org.springframework.tests.sample.beans.IOther in project spring-framework by spring-projects.

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(), ","));
    assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
    ITestBean tb = (ITestBean) factory.getProxy();
    assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));
    raw.setAge(25);
    assertTrue(tb.getAge() == raw.getAge());
    long t = 555555L;
    TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
    Class<?>[] oldProxiedInterfaces = factory.getProxiedInterfaces();
    factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
    Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
    assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
    TimeStamped ts = (TimeStamped) factory.getProxy();
    assertTrue(ts.getTimeStamp() == t);
    // Shouldn't fail;
    ((IOther) ts).absquatulate();
}
Also used : IOther(org.springframework.tests.sample.beans.IOther) ITestBean(org.springframework.tests.sample.beans.ITestBean) TimeStamped(org.springframework.tests.TimeStamped) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DefaultIntroductionAdvisor(org.springframework.aop.support.DefaultIntroductionAdvisor) Test(org.junit.Test)

Example 2 with IOther

use of org.springframework.tests.sample.beans.IOther in project spring-framework by spring-projects.

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);
    assertEquals(pfa.getAdvisors().length, pfb.getAdvisors().length);
    assertEquals(a, b);
    assertEquals(i1, i2);
    assertEquals(proxyA, proxyB);
    assertEquals(proxyA.hashCode(), proxyB.hashCode());
    assertFalse(proxyA.equals(a));
    // Equality checks were handled by the proxy
    assertEquals(0, i1.getCount());
    // When we invoke A, it's NopInterceptor will have count == 1
    // and won't think it's equal to B's NopInterceptor
    proxyA.absquatulate();
    assertEquals(1, i1.getCount());
    assertFalse(proxyA.equals(proxyB));
}
Also used : SerializableNopInterceptor(org.springframework.tests.aop.interceptor.SerializableNopInterceptor) NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) IOther(org.springframework.tests.sample.beans.IOther) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 IOther (org.springframework.tests.sample.beans.IOther)2 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)1 TimeStamped (org.springframework.tests.TimeStamped)1 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)1 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1