Ejemplo n.º 1
0
 def __delete_test_group(self):
     nav = CanvasNavigator()
     nav.cd_to_id(self.base.component.id)
     pgs = nav.groups(self.name)
     for pg in pgs:
         canvas.delete_process_group(pg, True)
     self.test_group = None
Ejemplo n.º 2
0
    def setUpClass(cls):
        super(Test1ToNTest, cls).setUpClass()
        print("Start of tests: preparing nifi objects")
        config.nifi_config.host = 'http://192.168.56.5:8080/nifi-api'

        flow_name = "Test1ToNTest"

        nav = CanvasNavigator()
        # Delete all leftovers from previous (failed?) tests
        pgs_to_be_deleted = nav.groups(flow_name)
        for pg in pgs_to_be_deleted:
            canvas.delete_process_group(pg, force=True)
        # Create new process group in root
        Test1ToNTest.pg_test = canvas.create_process_group(nav.current, flow_name, (0, 0))

        # Create simple flow to test
        Test1ToNTest.proc_start = canvas.create_processor(
            Test1ToNTest.pg_test,
            canvas.get_processor_type("GenerateFlowFile"),
            CANVAS_CENTER,
            "Start")
        Test1ToNTest.proc_2 = canvas.create_processor(
            Test1ToNTest.pg_test,
            canvas.get_processor_type("DebugFlow"),
            CANVAS_CENTER,
            "Processor 2")
        Test1ToNTest.proc_3 = canvas.create_processor(
            Test1ToNTest.pg_test,
            canvas.get_processor_type("DebugFlow"),
            CANVAS_CENTER,
            "Processor 3")
        Test1ToNTest.proc_end_1 = canvas.create_processor(
            Test1ToNTest.pg_test,
            canvas.get_processor_type("DebugFlow"),
            CANVAS_CENTER,
            "End 1")
        Test1ToNTest.proc_end_2 = canvas.create_processor(
            Test1ToNTest.pg_test,
            canvas.get_processor_type("DebugFlow"),
            CANVAS_CENTER,
            "End 2")
        canvas.update_processor(Test1ToNTest.proc_end_1,
                                nifi.ProcessorConfigDTO(auto_terminated_relationships=["success", "failure"]))
        canvas.update_processor(Test1ToNTest.proc_end_2,
                                nifi.ProcessorConfigDTO(auto_terminated_relationships=["success", "failure"]))
        Test1ToNTest.conn_1 = canvas.create_connection(Test1ToNTest.proc_start, Test1ToNTest.proc_2, ["success"])
        Test1ToNTest.conn_2 = canvas.create_connection(Test1ToNTest.proc_2, Test1ToNTest.proc_3, ["success", "failure"])
        Test1ToNTest.conn_3 = canvas.create_connection(Test1ToNTest.proc_3, Test1ToNTest.proc_end_1, ["success", "failure"])
        Test1ToNTest.conn_4 = canvas.create_connection(Test1ToNTest.proc_3, Test1ToNTest.proc_end_2, ["success", "failure"])

        canvas.schedule_process_group(Test1ToNTest.pg_test.component.id, scheduled=True)
Ejemplo n.º 3
0
 def test_create_request_handler(self):
     nav = CanvasNavigator()
     loc = Location()
     name = "nipytest - unit test - test_create_request_handler"
     controller = canvas_ext.create_http_context_map(nav.current, name)
     # Testing incorrect inputs
     with self.assertRaises(AssertionError):
         canvas_ext.create_request_handler("id", loc, controller, PORT)
         # noinspection PyTypeChecker
         canvas_ext.create_request_handler(nav.current, 1, controller, PORT)
         canvas_ext.create_request_handler(nav.current, loc, 1, PORT)
         # noinspection PyTypeChecker
         canvas_ext.create_request_handler(nav.current, loc, controller,
                                           "string")
     # Run function
     request_handler = canvas_ext.create_request_handler(
         nav.current, loc, controller, PORT)
     # If output is ok type, function was successful
     self.assertIsInstance(request_handler, nifi.ProcessorEntity)
     self.assertEqual(
         request_handler.component.config.properties["Listening Port"],
         str(PORT))
     # Remove temporary created object(s)
     canvas.delete_processor(request_handler, force=True)
     canvas.delete_controller(controller, True)
Ejemplo n.º 4
0
 def test_create_http_context_map(self):
     nav = CanvasNavigator()
     name = "nipytest - unit test - test_create_http_context_map"
     # Testing incorrect inputs
     with self.assertRaises(AssertionError):
         canvas_ext.create_http_context_map("id", "name")
         # noinspection PyTypeChecker
         canvas_ext.create_http_context_map(nav.current, 1)
     # Run function
     controller = canvas_ext.create_http_context_map(nav.current, name)
     # If output is ok type, function was successful
     self.assertIsInstance(controller, nifi.ControllerServiceEntity)
     self.assertIn(controller.component.state, ["ENABLED", "ENABLING"])
     # Remove temporary created object(s)
     canvas.delete_controller(controller, True)
Ejemplo n.º 5
0
 def test_create_test_input(self):
     nav = CanvasNavigator()
     loc = Location()
     name = "nipytest - unit test - test_create_test_input"
     # Testing incorrect inputs
     with self.assertRaises(AssertionError):
         canvas_ext.create_test_input("id", loc, name)
         # noinspection PyTypeChecker
         canvas_ext.create_test_input(nav.current, 1, name)
         # noinspection PyTypeChecker
         canvas_ext.create_test_input(nav.current, loc, 1)
     # Run function
     output_port = canvas_ext.create_test_input(nav.current, loc, name)
     # If output is ok type, function was successful
     self.assertIsInstance(output_port, nifi.PortEntity)
     self.assertEqual(output_port.component.name, name)
     # Remove temporary created object(s)
     canvas.delete_port(output_port)
Ejemplo n.º 6
0
 def test_create_output_router(self):
     nav = CanvasNavigator()
     loc = Location()
     name = "nipytest - unit test - test_create_output_router"
     # Testing incorrect inputs
     with self.assertRaises(AssertionError):
         canvas_ext.create_output_router("id", loc, name)
         # noinspection PyTypeChecker
         canvas_ext.create_output_router(nav.current, 1, name)
         # noinspection PyTypeChecker
         canvas_ext.create_output_router(nav.current, loc, 1)
     # Run function
     output_router = canvas_ext.create_output_router(nav.current, loc, name)
     # If output is ok type, function was successful
     self.assertIsInstance(output_router, nifi.ProcessorEntity)
     self.assertIsNotNone(output_router.component.name, name)
     # Remove temporary created object(s)
     canvas.delete_processor(output_router, force=True)
Ejemplo n.º 7
0
 def test_recreate_connection(self):
     nav = CanvasNavigator()
     loc = Location()
     name = "nipytest - unit test - test_recreate_connection"
     # Testing incorrect inputs
     with self.assertRaises(AssertionError):
         canvas_ext.recreate_connection(1)
     # Create connection
     input_port = canvas_ext.create_test_output(nav.current, loc, name)
     output_port = canvas_ext.create_test_input(nav.current, loc, name)
     connection = canvas.create_connection(input_port, output_port)
     canvas.delete_connection(connection)
     # Run function
     new_connection = canvas_ext.recreate_connection(connection)
     # If output is ok type, function was successful
     self.assertIsInstance(new_connection, nifi.ConnectionEntity)
     self.assertNotEqual(connection.component.id,
                         new_connection.component.id)
     # Remove temporary created object(s)
     canvas.delete_connection(new_connection)
     canvas.delete_port(input_port)
     canvas.delete_port(output_port)
 def setUp(self):
     self.nav = CanvasNavigator()
class CanvasNavigatorTest(unittest.TestCase):
    nav = None
    pg_parent = None
    pg_child1 = None
    pg_child2 = None
    pg_grandchild1 = None

    proc = None
    input_port = None
    output_port = None
    controller = None

    @classmethod
    def setUpClass(cls):
        super(CanvasNavigatorTest, cls).setUpClass()
        print("Start of tests: preparing nifi objects")
        config.nifi_config.host = 'http://192.168.56.5:8080/nifi-api'

        root = canvas.get_process_group(canvas.get_root_pg_id(), 'id')
        # Create new process group in root
        CanvasNavigatorTest.pg_parent = canvas.create_process_group(
            root, "parent", CANVAS_CENTER)
        # Create new child process groups in unittest
        CanvasNavigatorTest.pg_child1 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child1", CANVAS_CENTER)
        CanvasNavigatorTest.pg_child2 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child2", CANVAS_CENTER)
        CanvasNavigatorTest.pg_child2_2 = canvas.create_process_group(
            CanvasNavigatorTest.pg_parent, "child2", CANVAS_CENTER)
        CanvasNavigatorTest.pg_grandchild1 = canvas.create_process_group(
            CanvasNavigatorTest.pg_child1, "grandchild1", CANVAS_CENTER)

        # Create other objects as well
        CanvasNavigatorTest.proc = canvas.create_processor(
            CanvasNavigatorTest.pg_parent,
            canvas.get_processor_type("GenerateFlowFile"), CANVAS_CENTER,
            "proc")
        CanvasNavigatorTest.input_port = canvas.create_port(
            CanvasNavigatorTest.pg_parent.component.id, "INPUT_PORT",
            "input_port", "STOPPED", CANVAS_CENTER)
        CanvasNavigatorTest.output_port = canvas.create_port(
            CanvasNavigatorTest.pg_parent.component.id, "OUTPUT_PORT",
            "output_port", "STOPPED", CANVAS_CENTER)
        CanvasNavigatorTest.controller = canvas.create_controller(
            CanvasNavigatorTest.pg_parent,
            canvas.list_all_controller_types()[0], "controller")

    @classmethod
    def tearDownClass(cls):
        print("Tests done: deleting nifi objects")
        canvas.delete_controller(
            canvas.get_controller(CanvasNavigatorTest.controller.component.id,
                                  'id'), True)
        canvas.delete_process_group(CanvasNavigatorTest.pg_parent, True)

    def setUp(self):
        self.nav = CanvasNavigator()

    def test_init(self):
        print("Testing init")
        self.assertEqual(self.nav.current.component.name, "NiFi Flow",
                         'incorrect root component name')

    def test_cd_to_id(self):
        print("Testing cd to id")
        self.nav.cd_to_id(CanvasNavigatorTest.pg_parent.component.id)
        self.assertEqual(self.nav.current.component.name, "parent",
                         'did not go to correct process group id')

    def test_cd(self):
        print("Testing cd")
        self.nav.cd("parent")
        self.assertEqual(self.nav.current.component.name, "parent",
                         'incorrect jump to child')
        self.nav.cd("child1/grandchild1")
        self.assertEqual(self.nav.current.component.name, "grandchild1",
                         'incorrect jump to nested child')
        self.nav.cd("..")
        self.assertEqual(self.nav.current.component.name, "child1",
                         'incorrect jump to parent')
        self.nav.cd("/parent/child1/grandchild1")
        self.assertEqual(self.nav.current.component.name, "grandchild1",
                         'incorrect jump to nested child from root')
        # Was already called in init, but let's test again
        self.nav.cd("/")
        self.assertEqual(self.nav.current.component.name, "NiFi Flow",
                         'incorrect jump to root')

    def test_current_id(self):
        print("Testing current id")
        self.assertEqual(self.nav.current_id(), canvas.get_root_pg_id(),
                         'incorrect current id')

    def test_current_name(self):
        print("Testing current name")
        self.assertEqual(
            self.nav.current_name(),
            canvas.get_process_group(canvas.get_root_pg_id(),
                                     'id').component.name,
            'incorrect current name')

    def test_current_parent_id(self):
        print("Testing current parent id")
        self.nav.cd("parent/child1")
        self.assertEqual(self.nav.current_parent_id(),
                         CanvasNavigatorTest.pg_parent.component.id,
                         'incorrect current parent id')

    def test_group(self):
        print("Testing group")
        self.assertEqual(
            self.nav.group("parent").component.id,
            CanvasNavigatorTest.pg_parent.component.id, 'incorrect group')
        self.assertRaises(Exception, self.nav.group, "doesnotexist")
        self.nav.cd("parent")
        self.assertRaises(Exception, self.nav.group, "child2")

    def test_processor(self):
        print("Testing processor")
        self.nav.cd("parent")
        self.assertEqual(
            self.nav.processor("proc").component.id,
            CanvasNavigatorTest.proc.component.id, 'incorrect processor')

    def test_input_port(self):
        print("Testing input port")
        self.nav.cd("parent")
        self.assertEqual(
            self.nav.input_port("input_port").component.id,
            CanvasNavigatorTest.input_port.component.id,
            'incorrect input port')

    def test_output_port(self):
        print("Testing output port")
        self.nav.cd("parent")
        self.assertEqual(
            self.nav.output_port("output_port").component.id,
            CanvasNavigatorTest.output_port.component.id,
            'incorrect output port')

    def test_controller_service(self):
        print("Testing controller service")
        self.nav.cd("parent")
        self.assertEqual(
            self.nav.controller_service("controller").component.id,
            CanvasNavigatorTest.controller.component.id,
            'incorrect controller service')