def testCallingRegExpProxiedMethodThatHasArgumentsWithProxiedPositionalArguments(self): pointcutAdvisor = RegexpMethodPointcutAdvisor(advice=WrappingInterceptor(), patterns=["SampleService.method"]) service = ProxyFactoryObject(target=SampleService(), interceptors=pointcutAdvisor) self.assertEquals("Alright!", service.doSomething()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test")) self.assertEquals("<Wrapped>You made it! => Alright!</Wrapped>", service.method(service.doSomething()))
def testCallingProxiedMethodWithProxiedNamedArguments(self): targetService = SampleService() service = ProxyFactoryObject(target = targetService, interceptors = WrappingInterceptor()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method(data="test")) self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething()) self.assertEquals("<Wrapped>You made it! => Alright!</Wrapped>", service.method(data=targetService.doSomething())) self.assertEquals("<Wrapped>You made it! => <Wrapped>Alright!</Wrapped></Wrapped>", service.method(service.doSomething()))
def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedNamedArguments( self): pointcutAdvisor = RegexpMethodPointcutAdvisor( advice=WrappingInterceptor(), patterns=["SampleService.doSomething"]) service = ProxyFactoryObject(target=SampleService(), interceptors=pointcutAdvisor) self.assertEquals("You made it! => test", service.method(data="test")) self.assertEquals("You made it! => <Wrapped>Alright!</Wrapped>", service.method(data=service.doSomething()))
def testCallingProxiedMethodWithProxiedNamedArguments(self): targetService = SampleService() service = ProxyFactoryObject(target=targetService, interceptors=WrappingInterceptor()) self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method(data="test")) self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething()) self.assertEquals("<Wrapped>You made it! => Alright!</Wrapped>", service.method(data=targetService.doSomething())) self.assertEquals( "<Wrapped>You made it! => <Wrapped>Alright!</Wrapped></Wrapped>", service.method(service.doSomething()))
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 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)