def test_class_serialization(self):
        """Tests JSON serialization of a class dependency graph."""
        test_graph = class_dependency.JavaClassDependencyGraph()
        test_graph.add_edge_if_new(self.CLASS_1, self.CLASS_2)
        test_graph.add_edge_if_new(self.CLASS_1, self.CLASS_3)
        test_graph.add_edge_if_new(self.CLASS_2, self.CLASS_3)
        test_graph.add_nested_class_to_key(self.CLASS_1, self.CLASS_1_NESTED_1)
        test_graph.add_nested_class_to_key(self.CLASS_1, self.CLASS_1_NESTED_2)
        test_graph.add_nested_class_to_key(self.CLASS_2, self.CLASS_2_NESTED_1)

        test_json_obj = serialization.create_json_obj_from_graph(test_graph)

        self.assertEqual(test_json_obj, self.JSON_CLASS_GRAPH)
Example #2
0
    def test_package_serialization(self):
        """Tests JSON serialization of a package dependency graph."""
        class_graph = class_dependency.JavaClassDependencyGraph()
        class_graph.add_edge_if_new(self.CLASS_1, self.CLASS_2)
        class_graph.add_edge_if_new(self.CLASS_1, self.CLASS_3)
        class_graph.add_edge_if_new(self.CLASS_2, self.CLASS_3)
        class_graph.get_node_by_key(self.CLASS_1).add_nested_class(
            self.CLASS_1_NESTED_1)
        class_graph.get_node_by_key(self.CLASS_1).add_nested_class(
            self.CLASS_1_NESTED_2)
        class_graph.get_node_by_key(self.CLASS_2).add_nested_class(
            self.CLASS_2_NESTED_1)

        package_graph = package_dependency.JavaPackageDependencyGraph(
            class_graph)
        test_json_obj = serialization.create_json_obj_from_graph(package_graph)

        self.assertEqual(test_json_obj, self.JSON_PACKAGE_GRAPH)
Example #3
0
def create_class_graph_from_json_obj(
        json_obj: Dict) -> class_dependency.JavaClassDependencyGraph:
    """Creates a JavaClassDependencyGraph from a JSON representation."""
    class_graph = class_dependency.JavaClassDependencyGraph()

    for node_json_obj in json_obj[json_consts.NODES]:
        name = node_json_obj[json_consts.NAME]
        nested = node_json_obj[json_consts.META][
            class_json_consts.NESTED_CLASSES]
        added_node = class_graph.add_node_if_new(name)
        added_node.nested_classes = set(nested)

    for edge_json_obj in json_obj[json_consts.EDGES]:
        begin_key = edge_json_obj[json_consts.BEGIN]
        end_key = edge_json_obj[json_consts.END]
        class_graph.add_edge_if_new(begin_key, end_key)

    return class_graph
 def __init__(self):  # pylint: disable=missing-function-docstring
     self._graph = class_dependency.JavaClassDependencyGraph()
 def setUp(self):
     """Sets up a new JavaClassDependencyGraph."""
     self.test_graph = class_dependency.JavaClassDependencyGraph()