def testCreatingAProxyFactoryObjectAndAddingAnInterceptorProgrammatically(self): service = ProxyFactoryObject() service.target = SampleService() service.interceptors = [WrappingInterceptor()] self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test")) self.assertEquals("sample", service.attribute)
def testWrappingStringFunctionWithInterceptor(self): service = ProxyFactoryObject() service.target = SampleService() service.interceptors = [WrappingInterceptor()] self.assertEquals("This is a sample service.", service.target.__str__()) self.assertEquals("This is a sample service.", str(service.target)) self.assertEquals("<Wrapped>This is a sample service.</Wrapped>", str(service)) self.assertEquals("<Wrapped>This is a sample service.</Wrapped>", service.__str__())
def testCreatingAProxyFactoryObjectAndAddingAnInterceptorProgrammatically( self): service = ProxyFactoryObject() service.target = SampleService() service.interceptors = [WrappingInterceptor()] self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test")) self.assertEquals("sample", service.attribute)
def testApplyingASingleConditionalPointcutProgrammatically(self): wrappingAdvice = WrappingInterceptor() pointcutAdvisor = RegexpMethodPointcutAdvisor() pointcutAdvisor.advice = wrappingAdvice pointcutAdvisor.patterns = [".*do.*"] targetService = SampleService() sampleService = ProxyFactoryObject(interceptors = pointcutAdvisor) sampleService.target = targetService self.assertEquals(sampleService.doSomething(), "<Wrapped>Alright!</Wrapped>") self.assertEquals(sampleService.method("testdata"), "You made it! => testdata")
def testApplyingTwoConditionalPointcutsProgrammatically(self): beginEndAdvice = BeforeAndAfterInterceptor() wrappingAdvice = WrappingInterceptor() pointcutAdvisor = RegexpMethodPointcutAdvisor() pointcutAdvisor.advice = [beginEndAdvice, wrappingAdvice] pointcutAdvisor.patterns = [".*do.*"] targetService = SampleService() sampleService = ProxyFactoryObject(interceptors = pointcutAdvisor) sampleService.target = targetService self.assertEquals(sampleService.doSomething(), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER") self.assertEquals(sampleService.method("testdata"), "You made it! => testdata")
def testApplyingASingleConditionalPointcutProgrammatically(self): wrappingAdvice = WrappingInterceptor() pointcutAdvisor = RegexpMethodPointcutAdvisor() pointcutAdvisor.advice = wrappingAdvice pointcutAdvisor.patterns = [".*do.*"] targetService = SampleService() sampleService = ProxyFactoryObject(interceptors=pointcutAdvisor) sampleService.target = targetService self.assertEquals(sampleService.doSomething(), "<Wrapped>Alright!</Wrapped>") self.assertEquals(sampleService.method("testdata"), "You made it! => testdata")
def testApplyingTwoConditionalPointcutsProgrammatically(self): beginEndAdvice = BeforeAndAfterInterceptor() wrappingAdvice = WrappingInterceptor() pointcutAdvisor = RegexpMethodPointcutAdvisor() pointcutAdvisor.advice = [beginEndAdvice, wrappingAdvice] pointcutAdvisor.patterns = [".*do.*"] targetService = SampleService() sampleService = ProxyFactoryObject(interceptors=pointcutAdvisor) sampleService.target = targetService self.assertEquals(sampleService.doSomething(), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER") self.assertEquals(sampleService.method("testdata"), "You made it! => testdata")
def testProxyFactoryObjectInterceptorsNotWrappedInAList(self): service = ProxyFactoryObject() service.target = SampleService() # Note that it isn't wrapped in a list. service.interceptors = WrappingInterceptor() self.assertEquals("This is a sample service.", service.target.__str__()) self.assertEquals("This is a sample service.", str(service.target)) self.assertEquals("<Wrapped>This is a sample service.</Wrapped>", str(service)) self.assertEquals("<Wrapped>This is a sample service.</Wrapped>", service.__str__()) # sampleService6 has an interceptor which isn't wrapped in a list # inside its XMLConfig. service = self.appContext.get_object("sampleService6") self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test")) self.assertEquals("sample", service.attribute)