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