martinzink commented on code in PR #1810:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1810#discussion_r1648482163


##########
extensions/standard-processors/tests/unit/LogAttributeTests.cpp:
##########
@@ -0,0 +1,145 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <string>
+#include <catch2/generators/catch_generators.hpp>
+
+#include "unit/Catch.h"
+#include "processors/LogAttribute.h"
+#include "unit/SingleProcessorTestController.h"
+#include "unit/TestUtils.h"
+
+using LogAttribute = org::apache::nifi::minifi::processors::LogAttribute;
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::test {
+
+TEST_CASE("LogAttribute logs payload", "[LogAttribute]") {
+  const auto log_attribute = std::make_shared<LogAttribute>("log_attribute");
+  SingleProcessorTestController controller{log_attribute};
+  LogTestController::getInstance().setTrace<LogAttribute>();
+
+  const auto [hexencode_payload, expected_payload] = GENERATE(
+    std::make_tuple("false", "hello world"),
+    std::make_tuple("true", "68656c6c6f20776f726c64"));
+
+  REQUIRE(controller.plan->setProperty(log_attribute, 
LogAttribute::LogPayload, "true"));
+  REQUIRE(controller.plan->setProperty(log_attribute, 
LogAttribute::HexencodePayload, hexencode_payload));
+
+  controller.plan->scheduleProcessor(log_attribute);
+  const auto result = controller.trigger("hello world", {{"eng", "apple"}, 
{"ger", "Apfel"}, {"fra", "pomme"}});
+  CHECK(result.at(LogAttribute::Success).size() == 1);
+  
CHECK(LogTestController::getInstance().contains("-------------------------------------------------",
 1s));
+  CHECK(LogTestController::getInstance().contains("Size:11 Offset:0", 0s));
+  CHECK(LogTestController::getInstance().contains("FlowFile Attributes Map 
Content", 0s));
+  CHECK(LogTestController::getInstance().contains("key:eng value:apple", 0s));
+  CHECK(LogTestController::getInstance().contains("key:ger value:Apfel", 0s));
+  CHECK(LogTestController::getInstance().contains("key:fra value:pomme", 0s));
+
+  CHECK(LogTestController::getInstance().contains(fmt::format("Payload:\n{}", 
expected_payload), 0s));
+}
+
+TEST_CASE("LogAttribute LogLevel and LogPrefix", "[LogAttribute]") {
+  const auto log_attribute = std::make_shared<LogAttribute>("log_attribute");
+  SingleProcessorTestController controller{log_attribute};
+  LogTestController::getInstance().setTrace<LogAttribute>();
+
+  const auto [log_level, log_prefix, expected_dash] = GENERATE(
+    std::make_tuple("info", "", 
"-------------------------------------------------"),
+    std::make_tuple("critical", "foo", 
"-----------------------foo------------------------"),
+    std::make_tuple("debug", "Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Morbi mollis neque sit amet dui pretium sodales.",
+        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis 
neque sit amet dui pretium sodales."),
+    std::make_tuple("error", "", 
"-------------------------------------------------"));

Review Comment:
   good catch :+1: fixed it in 
https://github.com/apache/nifi-minifi-cpp/pull/1810/commits/a2dd56c5681a182325eeb18f1199ce99063fe633



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to