Пример #1
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)
Пример #2
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)
Пример #3
0
    def __build_inputs(self):
        # Create http context map for communication
        self.logger.debug(
            "Creating 'StandardHttpContextMap' for communication")
        self.http_context = canvas_ext.create_http_context_map(
            self.test_group, self.name)

        # Keep track of "cursor" location on canvas
        location = Location()

        # Create http request for starting a test
        self.logger.debug("Creating 'HandleHttpRequest' for starting a test")
        self.http_in = canvas_ext.create_request_handler(
            self.test_group, location, self.http_context, self.port)

        location.y += 200

        # Set start time
        self.logger.debug("Creating 'UpdateAttribute' to set test start time")
        in_attribute = canvas_ext.create_input_attribute(
            self.test_group, location, "Set test start time")

        location.y += 200

        self.logger.debug(
            "Connecting 'HandleHttpRequest' with 'UpdateAttribute'")
        canvas.create_connection(self.http_in, in_attribute, ["success"])

        # Route request to correct port
        self.logger.debug(
            "Creating 'RouteOnAttribute' to send each request to the correct input port"
        )
        in_route = canvas_ext.create_input_router(self.test_group, location,
                                                  self.inputs)

        location.y += 200

        self.logger.debug(
            "Connecting 'UpdateAttribute' with 'RouteOnAttribute'")
        canvas.create_connection(in_attribute, in_route, ["success"])

        location.y += 100  # Taking some extra vertical space, because we can have so many ports

        for test_input in self.inputs:
            input_name = test_input.component.name
            self.logger.debug("Creating port for input '%s'", input_name)
            output_port = canvas_ext.create_test_input(self.test_group,
                                                       location, input_name)
            location.x += 400
            self.logger.debug("Connecting 'RouteOnAttribute' to port '%s'",
                              input_name)
            canvas.create_connection(in_route, output_port, [input_name])
            self.logger.debug("Connecting port '%s' to processor '%s'",
                              input_name, input_name)
            canvas.create_connection(output_port, test_input)