Beispiel #1
0
    def testJavaCodeParser(self):
        create_code_db('project1', 'core', '3.0')

        codebase = parse_code('project1', 'core', '3.0', 'java')

        ### Test some Classes ###
        ce = CodeElement.objects.get(fqn='RootApplication')
        self.assertEqual('RootApplication', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Application')
        self.assertEqual('Application', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('p1', ce.containers.all()[0].fqn)

        self.assertEqual(2,
                CodeElement.objects.filter(simple_name='Application').count())

        # Test hierarchy
        ce = CodeElement.objects.get(fqn='p1.AnimalException')
        # Nothing because the parent is not in the codebase
        # (java.lang.Exception)
        self.assertEqual(0, ce.parents.count())

        ce = CodeElement.objects.get(fqn='p1.p2.Dog')
        fqns = [parent.fqn for parent in ce.parents.all()]
        self.assertTrue('p1.p2.Canidae' in fqns)
        self.assertTrue('p1.p2.Tag' in fqns)
        self.assertTrue('p1.p2.Tag2' in fqns)

        # Test internal classes
        ce = CodeElement.objects.get(fqn='p3.Special.InnerSpecial')
        self.assertEqual('InnerSpecial', ce.simple_name)
        self.assertEqual('p3.Special', ce.containers.all()[0].fqn)
        self.assertEqual('method1', ce.containees.all()[0].simple_name)
        self.assertEqual('p3.Special.InnerSpecial.method1',
                ce.containees.all()[0].fqn)

        ### Test some Methods and Parameters ###
        ce = CodeElement.objects.get(fqn='p1.BigCat.doSomething')
        method = ce.methodelement
        self.assertEqual(4, method.parameters_length)
        self.assertTrue(MethodElement.objects.filter(simple_name='doSomething')
                .filter(parameters_length=4).exists())
        self.assertEqual(4, ce.parameters().count())
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.BigCat', ce.containers.all()[0].fqn)

        self.assertEqual('specials', ce.parameters().all()[3].simple_name)
        # Array info is stripped from type.
        self.assertEqual('byte', ce.parameters().all()[2].type_fqn)
        # Generic info is stripped from type
        self.assertEqual('java.util.List', ce.parameters().all()[3].type_fqn)
        self.assertEqual('method parameter',
                ce.parameters().all()[3].kind.kind)

        ce = CodeElement.objects.get(fqn='p1.Animal.getParents')
        self.assertEqual('java.util.Collection', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Animal.run')
        self.assertEqual('void', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)

        ### Test some Fields ###
        ce = CodeElement.objects.get(fqn='p1.Animal.MAX_AGE')
        self.assertEqual('MAX_AGE', ce.simple_name)
        self.assertEqual('int', ce.fieldelement.type_simple_name)
        self.assertEqual('int', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Cat.name')
        self.assertEqual('java.lang.String', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Cat', ce.containers.all()[0].fqn)

        ### Test some Enumerations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        self.assertEqual('enumeration value',
                ce.containees.all()[0].kind.kind)
        self.assertEqual('p1.AnimalType',
                ce.containees.all()[0].fieldelement.type_fqn)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('NOT_SURE' in simple_names)
        self.assertEqual(3, len(simple_names))

        ce = CodeElement.objects.get(fqn='p1.SubAnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('SOFT' in simple_names)
        # Because it is private!
        self.assertTrue('SubAnimalType' not in simple_names)
        self.assertTrue('getOther' in simple_names)
        self.assertTrue('other' not in simple_names)
        self.assertEqual(3, len(simple_names))

        ### Test some Annotations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalTag')
        self.assertEqual('annotation', ce.kind.kind)
        self.assertEqual('annotation field', ce.containees.all()[0].kind.kind)
        fooBar = ce.containees.filter(simple_name='fooBar').all()[0]
        self.assertEqual('java.lang.String', fooBar.fieldelement.type_fqn)
        self.assertEqual(6, ce.containees.count())

        self.assertEqual(106, codebase.code_elements.count())

        clear_code_elements('project1', 'core', '3.0', 'xml')
        self.assertEqual(106, codebase.code_elements.count())
        clear_code_elements('project1', 'core', '3.0')
        self.assertEqual(0, codebase.code_elements.count())
Beispiel #2
0
    def testJavaCodeParser(self):
        create_code_db('project1', 'core', '3.0')

        codebase = parse_code('project1', 'core', '3.0', 'java')

        ### Test some Classes ###
        ce = CodeElement.objects.get(fqn='RootApplication')
        self.assertEqual('RootApplication', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Application')
        self.assertEqual('Application', ce.simple_name)
        self.assertEqual('class', ce.kind.kind)
        # Test containees & containers
        self.assertEqual(1, ce.containees.count())
        self.assertEqual('package', ce.containers.all()[0].kind.kind)
        self.assertEqual('p1', ce.containers.all()[0].fqn)

        self.assertEqual(
            2,
            CodeElement.objects.filter(simple_name='Application').count())

        # Test hierarchy
        ce = CodeElement.objects.get(fqn='p1.AnimalException')
        # Nothing because the parent is not in the codebase
        # (java.lang.Exception)
        self.assertEqual(0, ce.parents.count())

        ce = CodeElement.objects.get(fqn='p1.p2.Dog')
        fqns = [parent.fqn for parent in ce.parents.all()]
        self.assertTrue('p1.p2.Canidae' in fqns)
        self.assertTrue('p1.p2.Tag' in fqns)
        self.assertTrue('p1.p2.Tag2' in fqns)

        # Test internal classes
        ce = CodeElement.objects.get(fqn='p3.Special.InnerSpecial')
        self.assertEqual('InnerSpecial', ce.simple_name)
        self.assertEqual('p3.Special', ce.containers.all()[0].fqn)
        self.assertEqual('method1', ce.containees.all()[0].simple_name)
        self.assertEqual('p3.Special.InnerSpecial.method1',
                         ce.containees.all()[0].fqn)

        ### Test some Methods and Parameters ###
        ce = CodeElement.objects.get(fqn='p1.BigCat.doSomething')
        method = ce.methodelement
        self.assertEqual(4, method.parameters_length)
        self.assertTrue(
            MethodElement.objects.filter(simple_name='doSomething').filter(
                parameters_length=4).exists())
        self.assertEqual(4, ce.parameters().count())
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.BigCat', ce.containers.all()[0].fqn)

        self.assertEqual('specials', ce.parameters().all()[3].simple_name)
        # Array info is stripped from type.
        self.assertEqual('byte', ce.parameters().all()[2].type_fqn)
        # Generic info is stripped from type
        self.assertEqual('java.util.List', ce.parameters().all()[3].type_fqn)
        self.assertEqual('method parameter',
                         ce.parameters().all()[3].kind.kind)

        ce = CodeElement.objects.get(fqn='p1.Animal.getParents')
        self.assertEqual('java.util.Collection', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Animal.run')
        self.assertEqual('void', ce.methodelement.return_fqn)
        self.assertEqual('method', ce.kind.kind)

        ### Test some Fields ###
        ce = CodeElement.objects.get(fqn='p1.Animal.MAX_AGE')
        self.assertEqual('MAX_AGE', ce.simple_name)
        self.assertEqual('int', ce.fieldelement.type_simple_name)
        self.assertEqual('int', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Animal', ce.containers.all()[0].fqn)

        ce = CodeElement.objects.get(fqn='p1.Cat.name')
        self.assertEqual('java.lang.String', ce.fieldelement.type_fqn)
        self.assertEqual('field', ce.kind.kind)
        # Test container
        self.assertEqual('p1.Cat', ce.containers.all()[0].fqn)

        ### Test some Enumerations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        self.assertEqual('enumeration value', ce.containees.all()[0].kind.kind)
        self.assertEqual('p1.AnimalType',
                         ce.containees.all()[0].fieldelement.type_fqn)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('NOT_SURE' in simple_names)
        self.assertEqual(3, len(simple_names))

        ce = CodeElement.objects.get(fqn='p1.SubAnimalType')
        self.assertEqual('enumeration', ce.kind.kind)
        self.assertTrue(ce.kind.is_type)
        simple_names = [v.simple_name for v in ce.containees.all()]
        self.assertTrue('SOFT' in simple_names)
        # Because it is private!
        self.assertTrue('SubAnimalType' not in simple_names)
        self.assertTrue('getOther' in simple_names)
        self.assertTrue('other' not in simple_names)
        self.assertEqual(3, len(simple_names))

        ### Test some Annotations ###
        ce = CodeElement.objects.get(fqn='p1.AnimalTag')
        self.assertEqual('annotation', ce.kind.kind)
        self.assertEqual('annotation field', ce.containees.all()[0].kind.kind)
        fooBar = ce.containees.filter(simple_name='fooBar').all()[0]
        self.assertEqual('java.lang.String', fooBar.fieldelement.type_fqn)
        self.assertEqual(6, ce.containees.count())

        self.assertEqual(106, codebase.code_elements.count())

        clear_code_elements('project1', 'core', '3.0', 'xml')
        self.assertEqual(106, codebase.code_elements.count())
        clear_code_elements('project1', 'core', '3.0')
        self.assertEqual(0, codebase.code_elements.count())
Beispiel #3
0
 def handle_noargs(self, **options):
     pname = smart_decode(options.get('pname'))
     bname = smart_decode(options.get('bname'))
     release = smart_decode(options.get('release'))
     parser = smart_decode(options.get('parser'))
     clear_code_elements(pname, bname, release, parser)
Beispiel #4
0
 def handle_noargs(self, **options):
     pname = smart_decode(options.get('pname'))
     bname = smart_decode(options.get('bname'))
     release = smart_decode(options.get('release'))
     parser = smart_decode(options.get('parser'))
     clear_code_elements(pname, bname, release, parser)