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


##########
extension-framework/cpp-extension-lib/mocklib/include/MockProcessSession.h:
##########
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ */
+
+#pragma once
+#include <map>
+#include <ranges>
+
+#include "MockUtils.h"
+#include "api/core/ProcessSession.h"
+#include "range/v3/range/conversion.hpp"
+#include "range/v3/view/transform.hpp"
+
+struct MinifiFlowFile {
+  explicit MinifiFlowFile(std::string content_str) {
+    this->content = content_str
+           | ranges::views::transform([](char c) { return 
static_cast<std::byte>(c); })
+           | ranges::to<std::vector<std::byte>>();
+  }
+
+  ~MinifiFlowFile() = default;
+
+  MinifiFlowFile() = default;
+  MinifiFlowFile(const MinifiFlowFile&) = default;
+  MinifiFlowFile(MinifiFlowFile&&) = default;
+  MinifiFlowFile& operator=(const MinifiFlowFile&) = default;
+  MinifiFlowFile& operator=(MinifiFlowFile&&) = default;
+
+  std::map<std::string, std::string> attributes;
+  std::vector<std::byte> content;
+  bool is_penalized = false;
+  std::string id;
+};
+
+namespace org::apache::nifi::minifi::mock {
+
+class MockProcessSession : public api::core::ProcessSession {
+ public:
+  MockProcessSession() = default;
+  MockProcessSession(const MockProcessSession&) = delete;
+  MockProcessSession& operator=(const MockProcessSession&) = delete;
+  MockProcessSession(MockProcessSession&&) = delete;
+  MockProcessSession& operator=(MockProcessSession&&) = delete;
+
+  api::core::FlowFile create(const api::core::FlowFile* parent) override;
+  api::core::FlowFile get() override;
+  void penalize(api::core::FlowFile& ff) override;
+  void transfer(api::core::FlowFile ff, const minifi::core::Relationship& 
relationship) override;
+  void remove(api::core::FlowFile ff) override;
+  void write(api::core::FlowFile& ff, const io::OutputStreamCallback& 
callback) override;
+  void read(api::core::FlowFile& ff, const io::InputStreamCallback& callback) 
override;
+  void setAttribute(api::core::FlowFile& ff, std::string_view key, std::string 
value) override;
+  void removeAttribute(api::core::FlowFile& ff, std::string_view key) override;
+  std::optional<std::string> getAttribute(api::core::FlowFile& ff, 
std::string_view key) override;
+  [[nodiscard]] std::map<std::string, std::string> getAttributes(const 
api::core::FlowFile& ff) const override;
+  [[nodiscard]] std::string getFlowFileId(const api::core::FlowFile& ff) const 
override;
+  [[nodiscard]] uint64_t getFlowFileSize(const api::core::FlowFile& ff) const 
override;
+
+  void addInputFlowFile(std::unique_ptr<MinifiFlowFile> flow_file);
+
+ private:
+  std::vector<std::unique_ptr<MinifiFlowFile>> input_flow_files_;
+  std::map<std::string, std::vector<std::unique_ptr<MinifiFlowFile>>> 
transferred_flow_files_;

Review Comment:
   good idea, 
https://github.com/apache/nifi-minifi-cpp/pull/2170/changes/62fa423ff10fb91159958404c532cb4daccde878#diff-47d53d9e90b5146cb43fa62e059648d9f5f6386797cecb1d4b27fcacb47e3d26L76-L77
   
   i didnt want to replace it with the Relationship object since its not 
copyable afaik



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