fgerlits commented on a change in pull request #1137: URL: https://github.com/apache/nifi-minifi-cpp/pull/1137#discussion_r686131553
########## File path: extensions/standard-processors/tests/unit/AttributesToJSONTests.cpp ########## @@ -0,0 +1,293 @@ +/** + * + * 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 <vector> + +#include "rapidjson/writer.h" +#include "rapidjson/stringbuffer.h" +#include "TestBase.h" +#include "utils/TestUtils.h" +#include "AttributesToJSON.h" +#include "GetFile.h" +#include "PutFile.h" +#include "UpdateAttribute.h" +#include "LogAttribute.h" + +namespace { + +class AttributesToJSONTestFixture { + public: + const std::string TEST_FILE_CONTENT = "test_content"; + const std::string TEST_FILE_NAME = "tstFile.ext"; + + AttributesToJSONTestFixture() { + LogTestController::getInstance().setTrace<TestPlan>(); + LogTestController::getInstance().setDebug<minifi::processors::AttributesToJSON>(); + LogTestController::getInstance().setDebug<minifi::processors::GetFile>(); + LogTestController::getInstance().setDebug<minifi::processors::PutFile>(); + LogTestController::getInstance().setDebug<minifi::processors::UpdateAttribute>(); + LogTestController::getInstance().setDebug<minifi::processors::LogAttribute>(); + + dir_ = test_controller_.createTempDirectory(); + + plan_ = test_controller_.createPlan(); + getfile_ = plan_->addProcessor("GetFile", "GetFile"); + update_attribute_ = plan_->addProcessor("UpdateAttribute", "UpdateAttribute", core::Relationship("success", "description"), true); + attribute_to_json_ = plan_->addProcessor("AttributesToJSON", "AttributesToJSON", core::Relationship("success", "description"), true); + logattribute_ = plan_->addProcessor("LogAttribute", "LogAttribute", core::Relationship("success", "description"), true); + putfile_ = plan_->addProcessor("PutFile", "PutFile", core::Relationship("success", "description"), true); + + plan_->setProperty(getfile_, org::apache::nifi::minifi::processors::GetFile::Directory.getName(), dir_); + plan_->setProperty(putfile_, org::apache::nifi::minifi::processors::PutFile::Directory.getName(), dir_); + + update_attribute_->setDynamicProperty("my_attribute", "my_value"); + update_attribute_->setDynamicProperty("other_attribute", "other_value"); + update_attribute_->setDynamicProperty("empty_attribute", ""); + + utils::putFileToDir(dir_, TEST_FILE_NAME, TEST_FILE_CONTENT); + } + + void assertJSONAttributesFromLog(const std::unordered_map<std::string, std::optional<std::string>>& expected_attributes) { + auto match = LogTestController::getInstance().matchesRegex("key:JSONAttributes value:(.*)").value(); + assertAttributes(expected_attributes, match[1].str()); Review comment: How clear is the exception thrown when the optional is null? I think an explicit REQUIRE might give a better diagnostic: ```suggestion auto match = LogTestController::getInstance().matchesRegex("key:JSONAttributes value:(.*)"); REQUIRE(match); assertAttributes(expected_attributes, (*match)[1].str()); ``` -- 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]
