def test_class_equal():
    method1 = Method("a")
    method2 = Method("a")
    a = ClassData("a", methods=[method1])
    b = ClassData("a", methods=[method2])
    output = a == b
    assert output == True
def test_class_data_not_equal_name():
    method1 = Method("a")
    method2 = Method("a")
    a = ClassData("a", methods=[method1])
    b = ClassData("b", methods=[method2])
    output = a == b
    assert output == False
def test_class_data_diffent_method_number():
    method1 = Method("a")
    method2 = Method("a")
    method3 = Method("b")
    a = ClassData("a", methods=[method1])
    b = ClassData("a", methods=[method2, method3])
    output = a == b
    assert output == False
def test_class_data_methods_unordered():
    method1 = Method("a")
    method2 = Method("a")
    method3 = Method("b")
    method4 = Method("b")
    a = ClassData("a", methods=[method1, method4])
    b = ClassData("a", methods=[method3, method2])
    output = a == b
    assert output == False
def test_class_data_not_equal_method():
    method1 = Method("a")
    method2 = Method("a")
    method3 = Method("b")
    method4 = Method("c")
    a = ClassData("a", methods=[method1, method4])
    b = ClassData("a", methods=[method2, method3])
    output = a == b
    assert output == False
Example #6
0
 def create_context():
     attribute = Attribute("strategy",
                           "Strategy",
                           visibility=Visibility.public)
     method = Method("doSomeBusinessLogic")
     context = ClassData("Context", methods=[method], fields=[attribute])
     return context
Example #7
0
 def create_concrete_b():
     method = create_do_algorithm()
     strategy = create_strategy()
     concrete_b = ClassData("ConcreteStrategyB",
                            methods=[method],
                            implementations=[strategy])
     return concrete_b
Example #8
0
def test_java_example_2():
    param1 = Attribute("damage", "int")
    param2 = Attribute("entity", "Entity")
    param3 = Attribute("bonus", "Bonus")
    method1 = Method("attack", "void", [param1, param2, param3])
    method2 = Method("cry", "void", [], Visibility.protected, Modifier.static)
    orc_class = ClassData("Orc", [], [method1, method2],
                          [ClassData("Monster")],
                          [Interface("IWalk", []),
                           Interface("IAttack", [])])

    with open(examples_folder + "/java_example_2.txt", 'r') as java_example:
        expected = java_example.read()

    result = ClassToJava(orc_class).convert()
    assert result == expected
Example #9
0
def test_python_example_3():
    field1 = Attribute("mail_reader", "MailReader", Visibility.public)
    field2 = Attribute("configs", "Configs", Visibility.private)
    field3 = Attribute("network_adapter", "NetworkAdapter", Visibility.public)
    field4 = Attribute("test_runner", "TestRunner", Visibility.protected)

    param1 = Attribute("how_much", "int")
    param2 = Attribute("flag1", "bool")
    param3 = Attribute("flag2", "bool")

    method1 = Method("initialize", "void")
    method2 = Method("initialize_2", "void", modifier=Modifier.abstract)
    method3 = Method("do_things", "void", [param1, param2, param3],
                     Visibility.protected, Modifier.static)
    method4 = Method(
        "no_one_will_ever_use_this", "string",
        [Attribute("trash", "void"),
         Attribute("trash_can", "void")], Visibility.private)

    weird_god_class = ClassData("WeirdGodClass",
                                [field1, field2, field3, field4],
                                [method1, method2, method3, method4], [],
                                [Interface("IDoManyThings", [])])

    with open(examples_folder + "/python_example_3.txt",
              'r') as python_example:
        expected = python_example.read()

    result = ClassToPython(weird_god_class).convert()
    assert result == expected
Example #10
0
    def create_fat_orc():
        food = Attribute("food", "IFood", visibility=Visibility.public)

        eat = Method("eat", parameters=[food])

        orc = create_orc()

        fat_orc = ClassData("FatOrc", methods=[eat], inheritances=[orc])
        return fat_orc
Example #11
0
    def read_xml(uml_data: str):
        uml_data = uml_data.replace("<br>", "")
        uml_data = uml_data.replace("<br/>", "")
        list_of_attributes = []
        list_of_methods = []
        id_to_name = {}

        html = bs(uml_data, 'html.parser')

        result = html.find_all('p')

        class_name = ''

        for i in range(len(result)):
            if result[i].string is not None:
                if i == 0:
                    class_name = result[i].b.string
                    id_to_name[id] = class_name
                else:
                    visibility = VisibilityExtractor.extract_visibility(
                        result[i].string)
                    type_ = ReturnTypeExtractor.extract_type(result[i].string)

                    if '(' in result[i].string:
                        name = MethodNameExtractor.extract_name(
                            result[i].string)

                        list_of_parameters_string = ParametersExtractor.extract_parameters_string(
                            result[i].string)

                        list_of_parameters = []
                        if len(list_of_parameters_string
                               ) != 0 and list_of_parameters_string[0] != '':
                            for parameter_string in list_of_parameters_string:
                                parameter_name = AttributeNameExtractor.extract_name(
                                    parameter_string)
                                parameter_type = ReturnTypeExtractor.extract_type(
                                    parameter_string)
                                parameter = Attribute(parameter_name,
                                                      parameter_type)
                                list_of_parameters.append(parameter)

                        method = Method(name, type_, list_of_parameters,
                                        visibility)
                        list_of_methods.append(method)
                    else:
                        name = AttributeNameExtractor.extract_name(
                            result[i].string)
                        attribute = Attribute(name, type_, visibility)
                        list_of_attributes.append(attribute)

        return ClassData(class_name, list_of_attributes, list_of_methods)
Example #12
0
def test_java_example_1():
    att1 = Attribute("name", "String", Visibility.public)
    att2 = Attribute("age", "int", Visibility.private)

    method1 = Method("bark", "void", [], Visibility.public)
    param1 = Attribute("byAge", "int", Visibility.public)
    method2 = Method("growUp", "bool", [param1], Visibility.private)
    dog_class = ClassData("Dog", [att1, att2], [method1, method2])

    with open(path.join(examples_folder, "java_example_1.txt"),
              'r') as java_example:
        expected = java_example.read()

    result = ClassToJava(dog_class).convert()
    assert result == expected
Example #13
0
def test_python_example_4():
    att1 = Attribute("m", "String", Visibility.public)

    method = Method("v",
                    "void", [],
                    Visibility.public,
                    modifier=Modifier.abstract)
    dog_class = ClassData("Test4", [att1], [method])

    with open(path.join(examples_folder, "python_example_4.txt"),
              'r') as python_example:
        expected = python_example.read()

    result = ClassToPython(dog_class).convert()
    assert result == expected
Example #14
0
    def create_weapon():
        name = Attribute("name", "str", visibility=Visibility.public)
        age = Attribute("age", "int", visibility=Visibility.private)
        attribute = Attribute("attribute",
                              "Attribute",
                              visibility=Visibility.protected)

        getAttribute = Method("getAttribute", return_type="Attribute")
        setAttribute = Method("setAttribute",
                              return_type="void",
                              parameters=[attribute])
        weapon = ClassData("Weapon",
                           methods=[getAttribute, setAttribute],
                           fields=[name, age, attribute])
        return weapon
Example #15
0
    def create_obese_orc():
        food = Attribute("food", "IFood", visibility=Visibility.public)
        heart_attack = Attribute("heartAttackChance",
                                 "int",
                                 visibility=Visibility.public)

        eat = Method("eat", parameters=[food], modifier=Modifier.override)

        fat_orc = create_fat_orc()

        obese_orc = ClassData("ObeseOrc",
                              methods=[eat],
                              fields=[heart_attack],
                              inheritances=[fat_orc])
        return obese_orc
def test_classes_returned_read_xml():
    examples_folder = path.abspath(
        path.join(__file__, "../../../src/xmlToData/uml_samples/uml1.xml"))
    class_ = ClassData("Humano", [
        Attribute("idade", "int", Visibility.public),
        Attribute("anos", "float", Visibility.private)
    ], [
        Method("get_idade", "int",
               [Attribute("nome", "string"),
                Attribute("altura", "double")], Visibility.public),
        Method("get_anos", "float", [], Visibility.private)
    ])
    list_of_classes, list_of_interfaces = DrawIoXmlParser(
        examples_folder).read_xml()
    assert list_of_classes[0] == class_
Example #17
0
    def create_orc():
        name = Attribute("name", "str", visibility=Visibility.public)
        age = Attribute("age", "int", visibility=Visibility.private)
        damage = Attribute("damage", "int", visibility=Visibility.public)
        hours = Attribute("hours", "int", visibility=Visibility.public)

        walk = create_walk()
        attack_interface = create_attack()

        attack_method = Method("attack", parameters=[damage])
        sleep = Method("sleep",
                       parameters=[hours],
                       visibility=Visibility.private)

        orc = ClassData("Orc",
                        methods=[attack_method, sleep],
                        fields=[name, age],
                        implementations=[attack_interface, walk])
        return orc
Example #18
0
    def create_high_orc():
        damage = Attribute("damage", "int", visibility=Visibility.public)
        hours = Attribute("hours", "int", visibility=Visibility.public)
        spell = Attribute("spell", "ISpell", visibility=Visibility.public)

        attack = Method("attack",
                        parameters=[damage],
                        modifier=Modifier.override)
        sleep = Method("sleep",
                       parameters=[hours],
                       visibility=Visibility.private,
                       modifier=Modifier.override)

        orc = create_orc()

        high_orc = ClassData("HighOrc",
                             methods=[attack, sleep],
                             fields=[spell],
                             inheritances=[orc])
        return high_orc
def test_file_names_with_class(data_name, expected):
    assert FileNameToPython(ClassData(data_name)).get_file_name() == expected
Example #20
0
 def create_attribute():
     field1 = Attribute("value", "float", visibility=Visibility.public)
     field2 = Attribute("multiplier", "float", visibility=Visibility.public)
     attribute = ClassData("Attribute", fields=[field1, field2])
     return attribute
Example #21
0
def test_single_name_class():
    class_data = ClassData("Name")
    file_name_java = FileNameToJava(class_data)
    assert "Name.java" == file_name_java.get_file_name()
def test_single_inheritance_with_letters_only_and_no_space(inheritance_name):
    inheritance = ClassData(inheritance_name)
    inheritance_to_code = InheritanceToJava([inheritance])
    assert inheritance_to_code.get_formatted(
    ) == ' extends ' + inheritance_name
def test_double_inheritance_with_letters_only_and_no_space(name_one, name_two):
    inheritance_one = ClassData(name_one)
    inheritance_two = ClassData(name_two)
    inheritance_to_code = InheritanceToJava([inheritance_one, inheritance_two])
    assert inheritance_to_code.get_formatted(
    ) == ' extends ' + name_one + ", " + name_two
Example #24
0
 def create_attribute():
     method = Method("method")
     field = Attribute("field", "Type", visibility=Visibility.public)
     attribute = ClassData("Attribute", methods=[method], fields=[field])
     return attribute