示例#1
0
 def testUnrecognizedOption(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   parser = Parser()
       
   try:
     commandLine = parser.parse(options,['-q'])
   except UnrecognizedOptionException as uoe:
     self.assertEquals(uoe.getMessage(), 'unrecognized option -q')
示例#2
0
 def testMissingArgument(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   parser = Parser()
   commandLine = parser.parse(options,['-s'])
   
   try:
     parser.checkRequiredArguments()
   except MissingArgumentException as mae:
     self.assertEquals(mae.getMessage(), 'missing argument in option -s')
示例#3
0
 def testMissingArgumentValue(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   option = options.getOption("-s")
   option.setValues(['localhost'])
   parser = Parser()
   
   
   
   try:
     commandLine = parser.parse(options,['-s=orcl'])
     
   except UnrecognizedArgumentException as uae:
     self.assertEquals(uae.getMessage(), 'unrecognized argument orcl')
示例#4
0
 def testOptions(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, False, "scheme (user) of the database.")
   self.assertEquals(options.size(),3, "invalid number of options")
   parser = Parser()
   commandLine = parser.parse(options,['-s=orcl','--user=apps'])
   
   self.assertEquals(commandLine.hasOption('-s'), True, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-?'), False, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-t'), False, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-u'), True, "invalid parameter")
   self.assertEquals(commandLine.getOptionValues('-s'), ['orcl'], "invalid option value")
   self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value")
   self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value")
示例#5
0
    def testGenerateUpdateGuess(self):
        properties = Properties()
        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("plugin.dir",
                               Path.path(NOORA_DIR, "org", "noora", "plugin"))
        properties.setProperty("current.dir",
                               Path.path(os.path.abspath('.'), 'example'))
        properties.setProperty(
            "alter.dir",
            Path.path(properties.getPropertyValue("current.dir"), "alter"))
        properties.setProperty(
            "create.dir",
            Path.path(properties.getPropertyValue("current.dir"), "create"))
        properties.setProperty("project.file", "myproject.conf")

        #connectable=MysqlConnector()
        generatePlugin = GeneratePlugin()
        print(generatePlugin.getRevision())
        options = generatePlugin.getOptions(properties)

        arguments = []
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        generatePlugin.execute(commandLine, properties)
示例#6
0
    def testUpdatePass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty(
            "plugin.dir",
            NOORA_DIR + os.sep + "org" + os.sep + "noora" + os.sep + "plugin")
        properties.setProperty("current.dir", os.path.abspath('.'))
        properties.setProperty(
            "alter.dir",
            properties.getPropertyValue("current.dir") + os.sep + "alter")
        properties.setProperty(
            "create.dir",
            properties.getPropertyValue("current.dir") + os.sep + "create")

        #connectable=MysqlConnector()
        updatePlugin = UpdatePlugin()
        print(updatePlugin.getRevision())
        options = updatePlugin.getOptions(properties)

        arguments = ['-h=localhost', '-e=dev', '-v=1.0.1']
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        updatePlugin.execute(commandLine, properties)
示例#7
0
    def testDropPass(self):

        NOORA_DIR = os.path.abspath('.').split('test')[0] + "src"

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)

        #connectable=MysqlConnector()
        dropPlugin = DropPlugin()
        options = dropPlugin.getOptions(properties)

        arguments = ['-h=localhost', '-d=orcl', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)

        dropPlugin.execute(commandLine, properties)
示例#8
0
    def testDropPluginPass(self):

        NOORA_DIR = os.path.abspath('.').split('test')[0] + "src"

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("project.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("noora.script.dir",
                               NOORA_DIR + os.sep + "scripts")

        connectable = OracleConnectorStub()
        dropPlugin = PluginFactory.newOracleDropPlugin(connectable)
        options = dropPlugin.getOptions(properties)

        arguments = ['-s=orcl', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)

        dropPlugin.execute(commandLine, properties)
示例#9
0
    def testNoOraAppPass(self):

        NOORA_DIR = os.path.abspath('.').split('test')[0] + "src"

        sys.path.append(NOORA_DIR)
        CURRENT_DIR = os.path.abspath('.')

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("current.dir", CURRENT_DIR)
        properties.setProperty(
            "plugin.dir",
            NOORA_DIR + os.sep + 'org' + os.sep + 'noora' + os.sep + 'plugin')
        app = NoOraApp()
        file = app.getConfigFile(properties)
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        classLoader = ClassLoader()
        options = Options()
        pluginManager = PluginManager(classLoader, options)
        pluginsProperty = properties.getProperty('PLUGINS')
        pluginManager.load(pluginsProperty)
        options = pluginManager.getOptions()

        arguments = [
            'drop', 'create', 'update', '-h=localhost', '-d=orcl', '-e=dev',
            '-v=1.0.1'
        ]

        parser = Parser()
        commands = parser.parse(options, arguments)

        for command in commands.getOptions().getOptions():
            plugin = pluginManager.findByType(command.getType())

            options = plugin.getOptions(properties)
            commandLine = parser.parse(options, arguments)
            parser.checkRequiredOptions()
            parser.checkRequiredArguments()

            plugin.execute(commandLine, properties)
示例#10
0
    def testCreatePass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)

        #connectable=MysqlConnector()
        createPlugin = CreatePlugin()
        print(createPlugin.getRevision())
        options = createPlugin.getOptions(properties)

        arguments = ['-h=localhost', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        createPlugin.execute(commandLine, properties)
示例#11
0
    def execute(self, commandLine, properties):

        host = commandLine.getOption('-h')
        database = commandLine.getOption('-d')
        environment = commandLine.getOption('-e')

        # drop section
        arguments = ArgumentBuilder.build(host, database, environment)

        dropPlugin = DropPlugin()
        options = dropPlugin.getOptions(properties)
        parser = Parser()
        dropLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        dropPlugin.execute(dropLine, properties)

        # create section
        createPlugin = CreatePlugin()
        options = createPlugin.getOptions(properties)
        parser = Parser()
        createLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        createPlugin.execute(createLine, properties)

        # update section
        versions = Versions()
        versionLoader = VersionLoader(versions)
        versionLoader.load(properties)
        versions.sort()

        lastVersion = versions.last().toString()
        targetVersion = commandLine.getOptionValue('-v', lastVersion)
        print "targetVersion", targetVersion
        for version in versions.list()[1:]:

            targetOption = Option('-v', "--version", True, True,
                                  "version folder to install.")
            targetOption.setValues([version.toString()])

            arguments = ArgumentBuilder.build(host, database, environment,
                                              targetOption)

            updatePlugin = UpdatePlugin()
            options = updatePlugin.getOptions(properties)
            parser = Parser()
            updateLine = parser.parse(options, arguments)
            parser.checkRequiredOptions()
            parser.checkRequiredArguments()
            updatePlugin.execute(updateLine, properties)

            if version.toString() == targetVersion:
                break
示例#12
0
        properties.getPropertyValue("current.dir") + os.sep + "create")

    app = NoOraApp()
    file = app.getConfigFile(properties)
    fileReader = FileReader(file)
    propertyLoader.load(fileReader)

    classLoader = ClassLoader()
    options = Options()
    pluginManager = PluginManager(classLoader, options)
    pluginsProperty = properties.getProperty('PLUGINS')
    pluginManager.load(pluginsProperty)
    options = pluginManager.getOptions()

    #arguments = ['drop','create','update','-h=localhost','-d=orcl','-e=dev','-v=1.0.1']
    arguments = sys.argv[1:]

    parser = Parser()
    commands = parser.parse(options, arguments)

    for command in commands.getOptions().getOptions():

        plugin = pluginManager.findByType(command.getType())

        options = plugin.getOptions(properties)
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()

        plugin.execute(commandLine, properties)