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


##########
extensions/standard-processors/tests/unit/JsonRecordTests.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.c
+ */
+
+#include <numbers>
+#include <variant>
+
+#include "Catch.h"
+#include "RecordSetTesters.h"
+#include "TestBase.h"
+#include "TestRecord.h"
+#include "controllers/JsonRecordSetReader.h"
+#include "controllers/JsonRecordSetWriter.h"
+#include "core/Record.h"
+
+namespace org::apache::nifi::minifi::standard::test {
+
+constexpr std::string_view record_per_line_str = 
R"({"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"}
+{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem
 ipsum dolor sit amet, consectetur adipiscing 
elit.","when":"2022-11-01T19:52:11Z"}
+)";
+constexpr std::string_view array_compressed_str = 
R"([{"baz":3.14,"qux":[true,false,true],"is_test":true,"bar":123,"quux":{"Aprikose":"apricot","Birne":"pear","Apfel":"apple"},"foo":"asd","when":"2012-07-01T09:53:00Z"},{"baz":3.141592653589793,"qux":[false,false,true],"is_test":true,"bar":98402134,"quux":{"Aprikose":"abricot","Birne":"poire","Apfel":"pomme"},"foo":"Lorem
 ipsum dolor sit amet, consectetur adipiscing 
elit.","when":"2022-11-01T19:52:11Z"}])";
+constexpr std::string_view array_pretty_str = R"([
+    {
+        "baz": 3.14,
+        "qux": [
+            true,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 123,
+        "quux": {
+            "Aprikose": "apricot",
+            "Birne": "pear",
+            "Apfel": "apple"
+        },
+        "foo": "asd",
+        "when": "2012-07-01T09:53:00Z"
+    },
+    {
+        "baz": 3.141592653589793,
+        "qux": [
+            false,
+            false,
+            true
+        ],
+        "is_test": true,
+        "bar": 98402134,
+        "quux": {
+            "Aprikose": "abricot",
+            "Birne": "poire",
+            "Apfel": "pomme"
+        },
+        "foo": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
+        "when": "2022-11-01T19:52:11Z"
+    }
+])";
+
+bool test_json_equality(const std::string_view expected_str, const 
std::string_view actual_str) {
+  rapidjson::Document expected;
+  expected.Parse(expected_str.data());
+  rapidjson::Document actual;
+  actual.Parse(actual_str.data());
+  return actual == expected;
+}
+
+TEST_CASE("JsonRecordSetWriter test Record Per Line") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  
CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::OutputGrouping, 
"OneLinePerObject"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, 
[](auto serialized_record_set) -> bool {
+    return test_json_equality(record_per_line_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, 
[](auto serialized_record_set) -> bool {
+    return test_json_equality(array_compressed_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetWriter test pretty array") {
+  core::RecordSet record_set;
+  record_set.push_back(core::test::createSampleRecord());
+  record_set.push_back(core::test::createSampleRecord2());
+
+  JsonRecordSetWriter json_record_set_writer;
+  json_record_set_writer.initialize();
+  CHECK(json_record_set_writer.setProperty(JsonRecordSetWriter::PrettyPrint, 
"true"));
+  json_record_set_writer.onEnable();
+  CHECK(core::test::testRecordWriter(json_record_set_writer, record_set, 
[](auto serialized_record_set) -> bool {
+    return test_json_equality(array_pretty_str, serialized_record_set);
+  }));
+}
+
+TEST_CASE("JsonRecordSetReader per line") {

Review Comment:
   Good idea 👍 
https://github.com/apache/nifi-minifi-cpp/pull/1763/commits/c9aa16d7cd2ea2bd69e0345f365213f5a403cda2#diff-57d2adaddec9ace677119724e550df7ec037b8cad18b8cf32dca577d73787014R106



-- 
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