1 16 17 package org.springframework.aop.framework.adapter; 18 19 import junit.framework.TestCase; 20 21 import org.springframework.aop.Advisor; 22 import org.springframework.aop.SimpleBeforeAdviceImpl; 23 import org.springframework.aop.framework.Advised; 24 import org.springframework.beans.ITestBean; 25 import org.springframework.context.ApplicationContext; 26 import org.springframework.context.support.ClassPathXmlApplicationContext; 27 28 33 public class AdvisorAdapterRegistrationTests extends TestCase { 34 35 public void testAdvisorAdapterRegistrationManagerNotPresentInContext() { 36 ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml"); 37 ITestBean tb = (ITestBean) ctx.getBean("testBean"); 38 try { 40 tb.getName(); 41 fail("Should throw UnknownAdviceTypeException"); 42 } 43 catch (UnknownAdviceTypeException ex) { 44 assertEquals(0, getAdviceImpl(tb).getInvocationCounter()); 46 } 47 } 48 49 public void testAdvisorAdapterRegistrationManagerPresentInContext() { 50 ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml"); 51 ITestBean tb = (ITestBean) ctx.getBean("testBean"); 52 try { 54 tb.getName(); 55 assertEquals(1, getAdviceImpl(tb).getInvocationCounter()); 56 } 57 catch (UnknownAdviceTypeException ex) { 58 fail("Should not throw UnknownAdviceTypeException"); 59 } 60 } 61 62 private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) { 63 Advised advised = (Advised) tb; 64 Advisor advisor = advised.getAdvisors()[0]; 65 return (SimpleBeforeAdviceImpl) advisor.getAdvice(); 66 } 67 68 } 69 | Popular Tags |