def test_rule_load_with_replatform_advice(self): rule = """ - category: "JEE Config" app_type: java file_type: config refactor_rating: 1 replatform_advice: "Convert to Spring based application configuration" description: "JEE specific config file" files: - "application.xml" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(1, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("JEE Config", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Convert to Spring based application configuration", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("JEE specific config file", rule.description, "Description should be mapped") self.assertEqual("application.xml", rule.file_name, "File Name should be mapped")
def test_rule_load_with_multiple_text_patterns(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" text_patterns: [ "pattern1", "pattern2" ] files: [ "file1" ] """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("file1", rule.file_name, "File name should be mapped") self.assertTrue(rule.text_pattern == "pattern1" or rule.text_pattern == "pattern2") if rule.text_pattern == "pattern1": found1 = True elif rule.text_pattern == "pattern2": found2 = True self.assertTrue(found1 and found2, "Should have found pattern1 and pattern2")
def test_rule_load_with_file_pattern(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" file_pattern: "*.file1" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(1, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("*.file1", rule.file_name, "File name should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc1", rule.description, "Description should be mapped")
def test_rule_load_with_overriden_description_replatform_advice_refactor_rating(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 0 replatform_advice: "foo" description: "desc1" files: - "file1": { description: "desc2", replatform_advice: "bar", refactor_rating: 2 } - "file2" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertTrue(rule.file_name == "file1" or rule.file_name == "file2") if rule.file_name == "file1": found1 = True self.assertEqual("2", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("bar", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc2", rule.description, "Description should be mapped") elif rule.file_name == "file2": found2 = True self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc1", rule.description, "Description should be mapped") self.assertEqual("file2", rule.file_name, "File Name should be mapped") self.assertTrue(found1 and found2, "Should have found both file1 and file2")
def test_multiple_file_rule_load(self): rule = """ - category: "Web Profile" app_type: java file_type: config refactor_rating: 0 description: "Web application config file" files: - "web.xml" - "foo.barml" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("Web Profile", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Web application config file", rule.description, "Description should be mapped") self.assertEqual("web.xml", rule.file_name, "File Name should be mapped") rule = Scanner.rulebase[1] self.assertEqual("Web Profile", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Web application config file", rule.description, "Description should be mapped") self.assertEqual("foo.barml", rule.file_name, "File Name should be mapped")
def test_rule_load_with_multiple_text_patterns_overrides_and_file_pattern(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" text_patterns: - "pattern1" - "pattern2": { description: "desc2", replatform_advice: "bar", refactor_rating: 2 } file_pattern: "*.file1" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("*.file1", rule.file_name, "File name should be mapped") self.assertTrue(rule.text_pattern == "pattern1" or rule.text_pattern == "pattern2") if rule.text_pattern == "pattern1": found1 = True self.assertEqual("desc1", rule.description, "Description should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform advice should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor rating should be mapped") elif rule.text_pattern == "pattern2": found2 = True self.assertEqual("desc2", rule.description, "Description should be mapped") self.assertEqual("bar", rule.replatform_advice, "Replatform advice should be mapped") self.assertEqual("2", rule.refactor_rating, "Refactor rating should be mapped") self.assertTrue(found1 and found2, "Should have found pattern1 and pattern2")
def test_rule_load_with_multiple_text_patterns(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" text_patterns: [ "pattern1", "pattern2" ] files: [ "file1" ] """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("file1", rule.file_name, "File name should be mapped") self.assertTrue(rule.text_pattern == "pattern1" or rule.text_pattern == "pattern2") if rule.text_pattern == "pattern1": found1 = True elif rule.text_pattern == "pattern2": found2 = True self.assertTrue(found1 and found2, "Should have found pattern1 and pattern2")
def test_rule_load_with_multiple_text_patterns_overrides_and_file_pattern( self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" text_patterns: - "pattern1" - "pattern2": { description: "desc2", replatform_advice: "bar", refactor_rating: 2 } file_pattern: "*.file1" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("*.file1", rule.file_name, "File name should be mapped") self.assertTrue(rule.text_pattern == "pattern1" or rule.text_pattern == "pattern2") if rule.text_pattern == "pattern1": found1 = True self.assertEqual("desc1", rule.description, "Description should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform advice should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor rating should be mapped") elif rule.text_pattern == "pattern2": found2 = True self.assertEqual("desc2", rule.description, "Description should be mapped") self.assertEqual("bar", rule.replatform_advice, "Replatform advice should be mapped") self.assertEqual("2", rule.refactor_rating, "Refactor rating should be mapped") self.assertTrue(found1 and found2, "Should have found pattern1 and pattern2")
def test_rule_load_with_overriden_description_replatform_advice_refactor_rating( self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 0 replatform_advice: "foo" description: "desc1" files: - "file1": { description: "desc2", replatform_advice: "bar", refactor_rating: 2 } - "file2" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) found1 = False found2 = False for rule in Scanner.rulebase: self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertTrue(rule.file_name == "file1" or rule.file_name == "file2") if rule.file_name == "file1": found1 = True self.assertEqual("2", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("bar", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc2", rule.description, "Description should be mapped") elif rule.file_name == "file2": found2 = True self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc1", rule.description, "Description should be mapped") self.assertEqual("file2", rule.file_name, "File Name should be mapped") self.assertTrue(found1 and found2, "Should have found both file1 and file2")
def test_rule_load_with_file_pattern(self): rule = """ - category: "cat1" app_type: app1 file_type: type1 refactor_rating: 1 replatform_advice: "foo" description: "desc1" file_pattern: "*.file1" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(1, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("cat1", rule.file_category, "Category should be mapped") self.assertEqual("app1", rule.app_type, "App Type should be mapped") self.assertEqual("type1", rule.file_type, "File Type should be mapped") self.assertEqual("*.file1", rule.file_name, "File name should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("foo", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("desc1", rule.description, "Description should be mapped")
def test_multiple_file_rule_load(self): rule = """ - category: "Web Profile" app_type: java file_type: config refactor_rating: 0 description: "Web application config file" files: - "web.xml" - "foo.barml" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(2, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("Web Profile", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Web application config file", rule.description, "Description should be mapped") self.assertEqual("web.xml", rule.file_name, "File Name should be mapped") rule = Scanner.rulebase[1] self.assertEqual("Web Profile", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("0", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Web application config file", rule.description, "Description should be mapped") self.assertEqual("foo.barml", rule.file_name, "File Name should be mapped")
def test_rule_load_with_replatform_advice(self): rule = """ - category: "JEE Config" app_type: java file_type: config refactor_rating: 1 replatform_advice: "Convert to Spring based application configuration" description: "JEE specific config file" files: - "application.xml" """ Scanner.load_yaml_rules_stream(rule) self.assertEqual(1, len(Scanner.rulebase)) rule = Scanner.rulebase[0] self.assertEqual("JEE Config", rule.file_category, "Category should be mapped") self.assertEqual("java", rule.app_type, "App Type should be mapped") self.assertEqual("config", rule.file_type, "File Type should be mapped") self.assertEqual("1", rule.refactor_rating, "Refactor Rating should be mapped") self.assertEqual("Convert to Spring based application configuration", rule.replatform_advice, "Replatform Advice should be mapped") self.assertEqual("JEE specific config file", rule.description, "Description should be mapped") self.assertEqual("application.xml", rule.file_name, "File Name should be mapped")