예제 #1
0
 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)
예제 #2
0
 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__())
예제 #3
0
 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)
예제 #4
0
 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")
예제 #5
0
 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__())
예제 #6
0
 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")
예제 #7
0
 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")
예제 #8
0
 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")
예제 #9
0
    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)
예제 #10
0
    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)