コード例 #1
0
 def __Consumer_start__(self):
   path = os.path.dirname(__file__)
   self.serviceContext = ApplicationContext(XMLConfig(path+"/dataValidator.xml"))
   self.mqConnection = self.serviceContext.get_object("mqConnection")    
   
   try:
     # Open the channel
     channel = self.mqConnection.channel()
 
     # Declare the exchange
     exchange = channel.exchange_declare(exchange='rawdata', type='fanout', passive=False, durable=True, auto_delete=False, internal=False, nowait=False, arguments={})
 
     # Declare the queue
     #channel.queue_declare(queue="test", durable=True, exclusive=False, auto_delete=False)
     result = channel.queue_declare(durable=False, exclusive=True, auto_delete=False)
     queue_name = result.method.queue
     channel.queue_bind(exchange='rawdata', queue=queue_name)
 
     # We're stuck looping here since this is a blocking adapter
     channel.basic_consume(self.__Consumer_handler__, queue=queue_name, no_ack=True)
     
     self.debug("Raw Data Writer STARTED")
     self.debug("amqp connection : %s" % self.mqConnection)
     self.debug("amqp channel : %s" % channel)
     self.debug("amqp exchange : %s" % exchange)
     self.debug("amqp queue : %s" % result)
     
     channel.start_consuming()
   except Exception as ex:
     # Gracefully close the connection
     self.mqConnection.close()
     # Loop until we're fully closed, will stop on its own
     #connection.ioloop.start()
     self.error(ex)
コード例 #2
0
    def testIoCGeneralQueryWithDictionaryRowMapper(self):
        appContext = ApplicationContext(XMLConfig("support/databaseTestSqliteApplicationContext.xml"))
        factory = appContext.get_object("connection_factory")

        databaseTemplate = DatabaseTemplate(factory)

        databaseTemplate.execute("DROP TABLE IF EXISTS animal")
        databaseTemplate.execute("""
            CREATE TABLE animal (
              id serial PRIMARY KEY,
              name VARCHAR(11),
              category VARCHAR(20),
              population integer
            )
        """)
        factory.commit()
        databaseTemplate.execute("DELETE FROM animal")
        factory.commit()
        self.assertEquals(len(databaseTemplate.query_for_list("SELECT * FROM animal")), 0)
        databaseTemplate.execute("INSERT INTO animal (name, category, population) VALUES ('snake', 'reptile', 1)")
        databaseTemplate.execute("INSERT INTO animal (name, category, population) VALUES ('racoon', 'mammal', 0)")
        databaseTemplate.execute ("INSERT INTO animal (name, category, population) VALUES ('black mamba', 'kill_bill_viper', 1)")
        databaseTemplate.execute ("INSERT INTO animal (name, category, population) VALUES ('cottonmouth', 'kill_bill_viper', 1)")
        factory.commit()
        self.assertEquals(len(databaseTemplate.query_for_list("SELECT * FROM animal")), 4)

        results = databaseTemplate.query("select * from animal", rowhandler=DictionaryRowMapper())
コード例 #3
0
def main():
    """
    Main function

    """
    #TODO: Написать тесты
    context = ApplicationContext(XMLConfig(contextFile))
    objKernel = context.get_object("Kernel")
    objKernel.run()
コード例 #4
0
 def setupContext(self, username, password):
     applicationContext = ApplicationContext(
         XMLConfig("support/unanimousBasedApplicationContext.xml"))
     token = UsernamePasswordAuthenticationToken(username, password)
     auth_manager = applicationContext.get_object("auth_manager")
     SecurityContextHolder.setContext(SecurityContext())
     SecurityContextHolder.getContext(
     ).authentication = auth_manager.authenticate(token)
     self.sampleService = applicationContext.get_object("sampleService")
     self.block1 = SampleBlockOfData("block1")
     self.block2 = SampleBlockOfData("block2")
コード例 #5
0
    def testIoCGeneralQuery(self):
        appContext = ApplicationContext(XMLConfig("support/databaseTestApplicationContext.xml"))
        mockConnectionFactory = appContext.get_object("mockConnectionFactory")
        mockConnectionFactory.stubConnection.mockCursor = self.mock
        
        self.mock.expects(once()).method("execute")
        self.mock.expects(once()).method("fetchall").will(return_value([("me", "myphone")]))
        

        databaseTemplate = DatabaseTemplate(connection_factory = mockConnectionFactory)
        results = databaseTemplate.query("select * from foobar", rowhandler=testSupportClasses.SampleRowMapper())
コード例 #6
0
 def setupContext(self, username, password):
     applicationContext = ApplicationContext(
         XMLConfig("support/labelBasedAclVoterApplicationContext.xml"))
     token = UsernamePasswordAuthenticationToken(username, password)
     auth_manager = applicationContext.get_object("auth_manager")
     SecurityContextHolder.setContext(SecurityContext())
     SecurityContextHolder.getContext(
     ).authentication = auth_manager.authenticate(token)
     self.sampleService = applicationContext.get_object("sampleService")
     self.blueblock = SampleBlockOfData("blue")
     self.orangeblock = SampleBlockOfData("orange")
     self.sharedblock = SampleBlockOfData("blue-orange")
コード例 #7
0
    def testExportingAServiceThroughIoC(self):
        self.run_jetty()

        appContext = ApplicationContext(
            XMLConfig("support/remotingHessianTestApplicationContext.xml"))
        clientSideProxy = appContext.get_object("personService")

        results = clientSideProxy.transform("Greg Turnquist a,b,c,x,y,z")

        self.assertEquals(results["firstName"], "Greg")
        self.assertEquals(results["lastName"], "Turnquist")
        self.assertEquals(results["attributes"],
                          ["a", "b", "c", "x", "y", "z"])

        time.sleep(self.postdelay)
コード例 #8
0
ファイル: simpleTcpServer.py プロジェクト: fossabot/beecell
    def __init__(self, configFile):
        self.allow_reuse_address = True

        self.serviceContext = ApplicationContext(XMLConfig(configFile))
        self.config = self.serviceContext.get_object("mainConfiguration")

        SocketServer.TCPServer.__init__(self,
                                        (self.config.host, self.config.port),
                                        self.RequestHandler)

        self.poll_interval = 0.5
        self.mainProcess = multiprocessing.current_process()
        self.mainThread = threading.current_thread()
        self.adminThread = None
        '''
コード例 #9
0
    def ttestExportingAServiceThroughIoC(self):
        import logging
        logger = logging.getLogger("springpython.test")

        logger.info("Creating appContext")
        appContext = ApplicationContext(
            XMLConfig("support/remotingPyro4TestApplicationContext.xml"))

        logger.info("Fetching server 1 stuff...")
        remoteService1 = appContext.get_object("remoteServiceServer1")
        logger.info("remoteService1 = %s" % remoteService1)
        serviceExporter1 = appContext.get_object("serviceExporter1")
        clientSideProxy1 = appContext.get_object("accountServiceClient1")

        remoteService2 = appContext.get_object("remoteServiceServer2")
        serviceExporter2 = appContext.get_object("serviceExporter2")
        clientSideProxy2 = appContext.get_object("accountServiceClient2")

        time.sleep(10.01)

        argument1 = ['a', 1, 'b']
        self.assertEquals(remoteService1.getData(argument1),
                          "You got remote data => %s" % argument1)
        self.assertEquals(remoteService1.getMoreData(argument1),
                          "You got more remote data => %s" % argument1)

        self.assertEquals(clientSideProxy1.getData(argument1),
                          "You got remote data => %s" % argument1)
        self.assertEquals(clientSideProxy1.getMoreData(argument1),
                          "You got more remote data => %s" % argument1)

        routineToRun = "testit"
        self.assertEquals(remoteService2.executeOperation(routineToRun),
                          "Operation %s has been carried out" % routineToRun)
        self.assertEquals(
            remoteService2.executeOtherOperation(routineToRun),
            "Other operation %s has been carried out" % routineToRun)

        self.assertEquals(clientSideProxy2.executeOperation(routineToRun),
                          "Operation %s has been carried out" % routineToRun)
        self.assertEquals(
            clientSideProxy2.executeOtherOperation(routineToRun),
            "Other operation %s has been carried out" % routineToRun)

        serviceExporter1.__del__()
        serviceExporter2 = None
コード例 #10
0
    def testExportingAServiceUsingNonStandardPortsWithValueAttribute(self):
        appContext = ApplicationContext(
            XMLConfig("support/remotingPyroTestApplicationContext.xml"))

        time.sleep(0.01)

        remoteService1 = appContext.get_object("remoteServiceServer1")
        serviceExporter4 = appContext.get_object("serviceExporter4")
        clientSideProxy4 = appContext.get_object("accountServiceClient4")

        time.sleep(0.01)

        argument = ['a', 1, 'b']
        self.assertEquals(remoteService1.getData(argument),
                          "You got remote data => %s" % argument)
        self.assertEquals(remoteService1.getMoreData(argument),
                          "You got more remote data => %s" % argument)

        self.assertEquals(clientSideProxy4.getData(argument),
                          "You got remote data => %s" % argument)
        self.assertEquals(clientSideProxy4.getMoreData(argument),
                          "You got more remote data => %s" % argument)
コード例 #11
0
    def ttestExportingAServiceThroughIoCWithoutPullingTheIntermediateComponent(
            self):
        appContext = ApplicationContext(
            XMLConfig("support/remotingPyro4TestApplicationContext.xml"))

        remoteService1 = appContext.get_object("remoteServiceServer1")
        clientSideProxy1 = appContext.get_object("accountServiceClient1")

        remoteService2 = appContext.get_object("remoteServiceServer2")
        clientSideProxy2 = appContext.get_object("accountServiceClient2")

        time.sleep(0.01)

        argument1 = ['a', 1, 'b']
        self.assertEquals(remoteService1.getData(argument1),
                          "You got remote data => %s" % argument1)
        self.assertEquals(remoteService1.getMoreData(argument1),
                          "You got more remote data => %s" % argument1)

        self.assertEquals(clientSideProxy1.getData(argument1),
                          "You got remote data => %s" % argument1)
        self.assertEquals(clientSideProxy1.getMoreData(argument1),
                          "You got more remote data => %s" % argument1)

        routineToRun = "testit"
        self.assertEquals(remoteService2.executeOperation(routineToRun),
                          "Operation %s has been carried out" % routineToRun)
        self.assertEquals(
            remoteService2.executeOtherOperation(routineToRun),
            "Other operation %s has been carried out" % routineToRun)

        self.assertEquals(clientSideProxy2.executeOperation(routineToRun),
                          "Operation %s has been carried out" % routineToRun)
        self.assertEquals(
            clientSideProxy2.executeOtherOperation(routineToRun),
            "Other operation %s has been carried out" % routineToRun)

        del (appContext)
コード例 #12
0
    def ttestExportingAServiceUsingNonStandardPortsWithConstructorArgsByElement(
            self):
        appContext = ApplicationContext(
            XMLConfig("support/remotingPyro4TestApplicationContext.xml"))

        time.sleep(0.01)

        remoteService1 = appContext.get_object("remoteServiceServer1")
        serviceExporter6 = appContext.get_object("serviceExporter6")
        clientSideProxy6 = appContext.get_object("accountServiceClient6")

        time.sleep(0.01)

        argument = ['a', 1, 'b']
        self.assertEquals(remoteService1.getData(argument),
                          "You got remote data => %s" % argument)
        self.assertEquals(remoteService1.getMoreData(argument),
                          "You got more remote data => %s" % argument)

        self.assertEquals(clientSideProxy6.getData(argument),
                          "You got remote data => %s" % argument)
        self.assertEquals(clientSideProxy6.getMoreData(argument),
                          "You got more remote data => %s" % argument)
コード例 #13
0
    def context(self):
        if self._context is None:
            config_loaders = []
            if self.app.config['SPRING_YAML']:
                [
                    config_loaders.append(YamlConfig(config_yaml)) for
                    config_yaml in self.app.config['SPRING_YAML'].split(',')
                ]

            if self.app.config['SPRING_XML']:
                [
                    config_loaders.append(XMLConfig(config_xml))
                    for config_xml in self.app.config['SPRING_XML'].split(',')
                ]

            if self.app.config['SPRING_OBJS']:
                [
                    config_loaders.append(conf_obj)
                    for conf_obj in self.app.config['SPRING_OBJS']
                ]

            self._context = ApplicationContext(config_loaders)

        return self._context
コード例 #14
0
    def testIoCGeneralQueryWithDictionaryRowMapper(self):
        appContext = ApplicationContext(XMLConfig("support/databaseTestMySQLApplicationContext.xml"))
        factory = appContext.get_object("connection_factory")

        databaseTemplate = DatabaseTemplate(factory)
        results = databaseTemplate.query("select * from animal", rowhandler=DictionaryRowMapper())
コード例 #15
0
ファイル: aopTestCases.py プロジェクト: ws-os/spring-python
 def setUp(self):
     self.appContext = ApplicationContext(
         XMLConfig("support/aopApplicationContext.xml"))
コード例 #16
0
 def setUp(self):
     SecurityContextHolder.setContext(SecurityContext())
     self.appContext = ApplicationContext(XMLConfig("support/providerApplicationContext.xml"))
     self.auth_manager = self.appContext.get_object("dao_mgr_hiding_exception")
     self.mock = self.mock()
     self.appContext.get_object("dataSource").stubConnection.mockCursor = self.mock
コード例 #17
0
 def test_main_has_Kernel_object(self):
     context = ApplicationContext(XMLConfig(contextFile))
     self.assertTrue('Kernel' in context.objects)
コード例 #18
0
def before_all(context):
    configuration = XMLConfig("resources/spring/application-context.xml")
    context.container = ApplicationContext(configuration)
コード例 #19
0
    # This turns on debugging, so you can see everything Spring Python is doing in the background
    # while executing the sample application.

    logger = logging.getLogger("springpython")
    loggingLevel = logging.DEBUG
    logger.setLevel(loggingLevel)
    ch = logging.StreamHandler()
    ch.setLevel(loggingLevel)
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") 
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # This sample loads the IoC container from an XML file. The XML-based application context
    # automatically resolves all dependencies and order of instantiation for you. 

    applicationContext = ApplicationContext(XMLConfig("applicationContext-client.xml"))
    applicationContext.get_object("filterChainProxy")
    
    SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)
    SecurityContextHolder.getContext()
    
    conf = {'/': 	{"tools.staticdir.root": os.getcwd(),
                         "tools.sessions.on": True,
                         "tools.filterChainProxy.on": True},
            "/images": 	{"tools.staticdir.on": True,
                         "tools.staticdir.dir": "images"},
            "/html": 	{"tools.staticdir.on": True,
                      	 "tools.staticdir.dir": "html"}
            }

    form = applicationContext.get_object(name = "root")
コード例 #20
0
 def setUp(self):
     SecurityContextHolder.setContext(SecurityContext())
     self.appContext = ApplicationContext(XMLConfig("support/ldapApplicationContext.xml"))
コード例 #21
0
 def setUp(self):
     self.appContext = ApplicationContext(
         XMLConfig("support/encodingApplicationContext.xml"))
     self.user = SaltedUser("user1", "testPassword", True)
     self.encoder = self.appContext.get_object("plainEncoder")
コード例 #22
0
 def setUp(self):
     SecurityContextHolder.setContext(SecurityContext())
     self.appContext = ApplicationContext(XMLConfig("support/providerApplicationContext.xml"))
     self.auth_manager = self.appContext.get_object("inMemoryDaoAuthenticationManager")
コード例 #23
0
    logger = logging.getLogger("springpython")
    loggingLevel = logging.DEBUG
    logger.setLevel(loggingLevel)
    ch = logging.StreamHandler()
    ch.setLevel(loggingLevel)
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # This sample loads the IoC container from an XML file. The XML-based application context
    # automatically resolves all dependencies and order of instantiation for you.

    applicationContext = ApplicationContext(
        XMLConfig(config_location="applicationContext.xml"))
    applicationContext.get_object("filterChainProxy")

    SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)
    SecurityContextHolder.getContext()

    conf = {
        '/': {
            "tools.staticdir.root": os.getcwd(),
            "tools.sessions.on": True,
            "tools.filterChainProxy.on": True
        },
        "/images": {
            "tools.staticdir.on": True,
            "tools.staticdir.dir": "images"
        },
コード例 #24
0
 def testIoCGeneralQuery(self):
     appContext = ApplicationContext(XMLConfig("support/databaseTestSQLServerApplicationContext.xml"))
     factory = appContext.get_object("connection_factory")
     
     databaseTemplate = DatabaseTemplate(factory)
     results = databaseTemplate.query("select * from animal", rowhandler=testSupportClasses.SampleRowMapper())
コード例 #25
0
if __name__ == "__main__":
    # Turn on some logging in order to see what is happening behind the scenes...
    logger = logging.getLogger("dataValidator")
    loggingLevel = logging.DEBUG
    logger.setLevel(loggingLevel)
    #ch = logging.StreamHandler()
    ch = logging.FileHandler("dataValidator.log", mode='a')
    ch.setLevel(loggingLevel)
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    path = os.path.dirname(__file__)
    appContext = ApplicationContext(XMLConfig(path + "/dataValidator.xml"))
    connection = appContext.get_object("mqConnection")

    try:
        # Open the channel
        channel = connection.channel()

        # Declare the exchange
        exchange = channel.exchange_declare(exchange='rawdata',
                                            type='fanout',
                                            passive=False,
                                            durable=True,
                                            auto_delete=False,
                                            internal=False,
                                            nowait=False,
                                            arguments={})