szaszm commented on a change in pull request #1188:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1188#discussion_r739225061



##########
File path: extensions/standard-processors/tests/unit/DefragmentTextTests.cpp
##########
@@ -0,0 +1,273 @@
+/**
+ *
+ * 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 "TestBase.h"
+#include "WriteToFlowFileTestProcessor.h"
+#include "ReadFromFlowFileTestProcessor.h"
+#include "UpdateAttribute.h"
+#include "DefragmentText.h"
+#include "TextFragmentUtils.h"
+#include "utils/TestUtils.h"
+#include "serialization/PayloadSerializer.h"
+#include "serialization/FlowFileSerializer.h"
+#include "unit/ContentRepositoryDependentTests.h"
+
+using WriteToFlowFileTestProcessor = 
org::apache::nifi::minifi::processors::WriteToFlowFileTestProcessor;
+using ReadFromFlowFileTestProcessor = 
org::apache::nifi::minifi::processors::ReadFromFlowFileTestProcessor;
+using UpdateAttribute = org::apache::nifi::minifi::processors::UpdateAttribute;
+using DefragmentText = org::apache::nifi::minifi::processors::DefragmentText;
+
+TEST_CASE("DefragTextFlowFilesNoMultilinePatternAtStartTest", 
"[defragmenttextnomultilinepatternatstarttest]") {
+  TestController testController;
+  std::shared_ptr<TestPlan> plan = testController.createPlan();
+  std::shared_ptr<WriteToFlowFileTestProcessor> write_to_flow_file = 
std::dynamic_pointer_cast<WriteToFlowFileTestProcessor>(
+      plan->addProcessor("WriteToFlowFileTestProcessor", 
"write_to_flow_file"));
+  std::shared_ptr<DefragmentText> defrag_text_flow_files =  
std::dynamic_pointer_cast<DefragmentText>(
+      plan->addProcessor("DefragmentText", "defrag_text_flow_files", 
core::Relationship("success", "description"), true));
+  std::shared_ptr<ReadFromFlowFileTestProcessor> read_from_flow_file = 
std::dynamic_pointer_cast<ReadFromFlowFileTestProcessor>(
+      plan->addProcessor("ReadFromFlowFileTestProcessor", 
"read_from_flow_file", DefragmentText::Success, true));
+  plan->setProperty(defrag_text_flow_files, DefragmentText::Pattern.getName(), 
"<[0-9]+>");
+
+
+  write_to_flow_file->setContent("<1> Foo");
+  testController.runSession(plan);
+  CHECK(read_from_flow_file->numberOfFlowFilesRead() == 0);
+  write_to_flow_file->setContent("<2> Bar");
+  plan->reset();
+  testController.runSession(plan);
+  CHECK(read_from_flow_file->readFlowFileWithContent("<1> Foo"));
+  write_to_flow_file->setContent("<3> Baz");
+  plan->reset();
+  testController.runSession(plan);
+  CHECK(read_from_flow_file->readFlowFileWithContent("<2> Bar"));
+}
+
+TEST_CASE("DefragmentTextEmptyPattern", "[defragmenttextemptypattern]") {
+  TestController testController;
+  std::shared_ptr<TestPlan> plan = testController.createPlan();
+  std::shared_ptr<WriteToFlowFileTestProcessor> write_to_flow_file = 
std::dynamic_pointer_cast<WriteToFlowFileTestProcessor>(
+      plan->addProcessor("WriteToFlowFileTestProcessor", 
"write_to_flow_file"));
+  std::shared_ptr<DefragmentText> defrag_text_flow_files =  
std::dynamic_pointer_cast<DefragmentText>(
+      plan->addProcessor("DefragmentText", "defrag_text_flow_files", 
core::Relationship("success", "description"), true));
+  std::shared_ptr<ReadFromFlowFileTestProcessor> read_from_flow_file = 
std::dynamic_pointer_cast<ReadFromFlowFileTestProcessor>(
+      plan->addProcessor("ReadFromFlowFileTestProcessor", 
"read_from_flow_file", DefragmentText::Success, true));
+  plan->setProperty(defrag_text_flow_files, DefragmentText::Pattern.getName(), 
"");
+  plan->setProperty(defrag_text_flow_files, 
DefragmentText::PatternLoc.getName(), 
toString(DefragmentText::PatternLocation::END_OF_MESSAGE));
+
+  REQUIRE_THROWS_WITH(testController.runSession(plan), "Process Schedule 
Operation: Pattern property missing or invalid");
+}
+
+TEST_CASE("DefragmentTextNoMultilinePatternAtEndTest", 
"[defragmenttextnomultilinepatternatendtest]") {
+  TestController testController;
+  std::shared_ptr<TestPlan> plan = testController.createPlan();
+  std::shared_ptr<WriteToFlowFileTestProcessor> write_to_flow_file = 
std::dynamic_pointer_cast<WriteToFlowFileTestProcessor>(
+      plan->addProcessor("WriteToFlowFileTestProcessor", 
"write_to_flow_file"));
+  std::shared_ptr<DefragmentText> defrag_text_flow_files =  
std::dynamic_pointer_cast<DefragmentText>(
+      plan->addProcessor("DefragmentText", "defrag_text_flow_files", 
core::Relationship("success", "description"), true));
+  std::shared_ptr<ReadFromFlowFileTestProcessor> read_from_flow_file = 
std::dynamic_pointer_cast<ReadFromFlowFileTestProcessor>(
+      plan->addProcessor("ReadFromFlowFileTestProcessor", 
"read_from_flow_file", DefragmentText::Success, true));

Review comment:
       What do you think about 
[SECTIONs](https://github.com/catchorg/Catch2/blob/devel/docs/tutorial.md#test-cases-and-sections)
 instead of fixtures? 
   Use `auto` to avoid repeating the type name after a cast.




-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to