Exemplo n.º 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()))
Exemplo n.º 2
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)
Exemplo n.º 3
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__())
Exemplo n.º 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")
Exemplo n.º 5
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()))
Exemplo n.º 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")
Exemplo n.º 7
0
    def testCallingProxiedMethodWithProxiedPositionalArguments(self):
        targetService = SampleService()

        service = ProxyFactoryObject(target=targetService, interceptors=WrappingInterceptor())

        self.assertEquals("<Wrapped>You made it! => test</Wrapped>", service.method("test"))
        self.assertEquals("<Wrapped>Alright!</Wrapped>", service.doSomething())
        self.assertEquals("<Wrapped>You made it! => Alright!</Wrapped>", service.method(targetService.doSomething()))
        self.assertEquals(
            "<Wrapped>You made it! => <Wrapped>Alright!</Wrapped></Wrapped>", service.method(service.doSomething())
        )
Exemplo n.º 8
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__())
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 11
0
    def weather_service(self):
        pointcut_advisor = RegexpMethodPointcutAdvisor(
            advice=[LoggingInterceptor(),
                    CacheInterceptor()],
            patterns=[".*check_.*"])

        return ProxyFactoryObject(target=self.target_weather_service(),
                                  interceptors=[pointcut_advisor])
Exemplo n.º 12
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)
Exemplo n.º 13
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()))
Exemplo n.º 14
0
    def getConnection(self, **kwargs):
        '''
        Gets an aop proxy wrapping a database connection, applying any
        interceptors passed into the factory's constructor.

        :param kwargs: connection parameters
        :type kwargs: dict or None
        :returns: a proxy wrapping a database connection
        :rtype: springpython.aop.ProxyFactoryObject_
        
        .. _springpython.aop.ProxyFactoryObject:
            http://static.springsource.org/spring-python/1.2.x/pydoc/springpython.aop.html#ProxyFactoryObject
        '''
        path = kwargs.get("path")
        if path:
            if path.endswith(".db"):
                return ProxyFactoryObject(target=SQLiteDatabase(**kwargs),
                                          interceptors=self.__interceptors)

            return ProxyFactoryObject(target=AccessDatabase(**kwargs),
                                      interceptors=self.__interceptors)

        return ProxyFactoryObject(target=PostgresDatabase(**kwargs),
                                  interceptors=self.__interceptors)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def __init__(self, tx_manager, target, tx_attributes):
     self.logger = logging.getLogger("springpython.database.transaction.TransactionProxyFactoryObject")
     ProxyFactoryObject.__init__(self, target, TransactionalInterceptor(tx_manager, tx_attributes))
Exemplo n.º 18
0
 def __init__(self, tx_manager, target, tx_attributes):
     self.logger = logging.getLogger("springpython.database.transaction.TransactionProxyFactoryObject")
     ProxyFactoryObject.__init__(self, target, TransactionalInterceptor(tx_manager, tx_attributes))