org.springframework.tests.sample.beans.IOther Java Examples
The following examples show how to use
org.springframework.tests.sample.beans.IOther.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAopProxyTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); AdvisedSupport pc = new AdvisedSupport(new Class<?>[] {ITestBean.class, IOther.class}); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // Assert that target matches BEFORE invocation returns assertEquals("Target is correct", expectedTarget, invocation.getThis()); return super.invoke(invocation); } }; pc.addAdvice(tii); pc.setTarget(expectedTarget); AopProxy aop = createAopProxy(pc); ITestBean tb = (ITestBean) aop.getProxy(); tb.getName(); }
Example #2
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // Assert that target matches BEFORE invocation returns assertEquals("Target is correct", expectedTarget, invocation.getThis()); return super.invoke(invocation); } }; pc.addAdvice(tii); pc.setTarget(expectedTarget); AopProxy aop = createAopProxy(pc); ITestBean tb = (ITestBean) aop.getProxy(); tb.getName(); }
Example #3
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testTargetCanGetInvocation() throws Throwable { final InvocationCheckExposedInvocationTestBean expectedTarget = new InvocationCheckExposedInvocationTestBean(); AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class); pc.addAdvice(ExposeInvocationInterceptor.INSTANCE); TrapTargetInterceptor tii = new TrapTargetInterceptor() { @Override public Object invoke(MethodInvocation invocation) throws Throwable { // Assert that target matches BEFORE invocation returns assertEquals("Target is correct", expectedTarget, invocation.getThis()); return super.invoke(invocation); } }; pc.addAdvice(tii); pc.setTarget(expectedTarget); AopProxy aop = createAopProxy(pc); ITestBean tb = (ITestBean) aop.getProxy(); tb.getName(); }
Example #4
Source File: ProxyFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@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(); }
Example #5
Source File: AbstractAopProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); }
Example #6
Source File: ProxyFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #7
Source File: TypePatternClassFilterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testSubclassMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #8
Source File: TypePatternClassFilterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testValidPatternMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(IOther.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #9
Source File: AbstractAopProxyTests.java From java-technology-stack with MIT License | 5 votes |
@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)); }
Example #10
Source File: TypePatternClassFilterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testValidPatternMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(IOther.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #11
Source File: TypePatternClassFilterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testSubclassMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #12
Source File: TypePatternClassFilterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testValidPatternMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(IOther.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class)); assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #13
Source File: AbstractAopProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@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)); }
Example #14
Source File: ProxyFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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(); }
Example #15
Source File: TypePatternClassFilterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testSubclassMatching() { TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+"); assertTrue("Must match: in package", tpcf.matches(TestBean.class)); assertTrue("Must match: in package", tpcf.matches(ITestBean.class)); assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class)); assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class)); }
Example #16
Source File: MethodMatchersTests.java From java-technology-stack with MIT License | 4 votes |
public MethodMatchersTests() throws Exception { EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage"); ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge"); ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", int.class); IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate"); }
Example #17
Source File: MethodMatchersTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
public MethodMatchersTests() throws Exception { EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage", (Class[]) null); ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge", (Class[]) null); ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", new Class[] { int.class }); IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate", (Class[]) null); }
Example #18
Source File: MethodMatchersTests.java From spring-analysis-note with MIT License | 4 votes |
public MethodMatchersTests() throws Exception { EXCEPTION_GETMESSAGE = Exception.class.getMethod("getMessage"); ITESTBEAN_GETAGE = ITestBean.class.getMethod("getAge"); ITESTBEAN_SETAGE = ITestBean.class.getMethod("setAge", int.class); IOTHER_ABSQUATULATE = IOther.class.getMethod("absquatulate"); }