MINIFICPP-31 Added UpdateAttribute processor
[nifi-minifi-cpp.git] / libminifi / test / unit / DynamicPropertyTests.cpp
1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include <string>
20 #include "core/ConfigurableComponent.h"
21 #include "../TestBase.h"
22
23 namespace org {
24 namespace apache {
25 namespace nifi {
26 namespace minifi {
27 namespace core {
28
29 class TestConfigurableComponentSupportsDynamic : public ConfigurableComponent {
30 public:
31 virtual bool supportsDynamicProperties() {
32 return true;
33 }
34
35 virtual bool canEdit() {
36 return false;
37 }
38 };
39
40 class TestConfigurableComponentNotSupportsDynamic : public ConfigurableComponent {
41 public:
42 virtual bool supportsDynamicProperties() {
43 return false;
44 }
45
46 virtual bool canEdit() {
47 return false;
48 }
49 };
50
51 TEST_CASE("Test Set Dynamic Property", "[testSetDynamicProperty]") {
52 TestConfigurableComponentSupportsDynamic component;
53 component.setDynamicProperty("test", "value");
54 std::string value;
55 component.getDynamicProperty("test", value);
56 REQUIRE(value == "value");
57 }
58
59 TEST_CASE("Test Set Dynamic Property 2", "[testSetDynamicProperty2]") {
60 TestConfigurableComponentSupportsDynamic component;
61 component.setDynamicProperty("test", "value");
62 component.setDynamicProperty("test", "value2");
63 std::string value;
64 component.getDynamicProperty("test", value);
65 REQUIRE(value == "value2");
66 }
67
68 TEST_CASE("Test Set Dynamic Property Fail", "[testSetDynamicPropertyFail]") {
69 TestConfigurableComponentNotSupportsDynamic component;
70 REQUIRE(!component.setDynamicProperty("test", "value"));
71 std::string value;
72 component.getDynamicProperty("test", value);
73 REQUIRE(value == "");
74 }
75
76 TEST_CASE("Test Set Dynamic Property 3", "[testSetDynamicProperty2]") {
77 TestConfigurableComponentSupportsDynamic component;
78 component.setDynamicProperty("test", "value");
79 component.setDynamicProperty("test2", "value2");
80 std::string value;
81 auto propertyKeys = component.getDynamicPropertyKeys();
82 REQUIRE(2 == propertyKeys.size());
83 REQUIRE("test" == propertyKeys[0]);
84 REQUIRE("test2" == propertyKeys[1]);
85 }
86
87 } /* namespace core */
88 } /* namespace minifi */
89 } /* namespace nifi */
90 } /* namespace apache */
91 } /* namespace org */