regulators: Add remaining properties to Rail class

Enhance the C++ Rail class by adding the remaining properties from the
JSON config file:
* configuration
* sensor_monitoring

See rail.md for more information.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I9c2e46fe8bec39454b0ad3f703eee3b497efd82a
diff --git a/phosphor-regulators/test/rail_tests.cpp b/phosphor-regulators/test/rail_tests.cpp
index d5722fd..a12211d 100644
--- a/phosphor-regulators/test/rail_tests.cpp
+++ b/phosphor-regulators/test/rail_tests.cpp
@@ -13,7 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "action.hpp"
+#include "configuration.hpp"
+#include "mock_action.hpp"
 #include "rail.hpp"
+#include "sensor_monitoring.hpp"
+
+#include <memory>
+#include <optional>
+#include <utility>
+#include <vector>
 
 #include <gtest/gtest.h>
 
@@ -21,12 +30,98 @@
 
 TEST(RailTests, Constructor)
 {
-    Rail rail("vdd0");
-    EXPECT_EQ(rail.getID(), "vdd0");
+    // Test where only required parameters are specified
+    {
+        Rail rail{"vdd0"};
+        EXPECT_EQ(rail.getID(), "vdd0");
+        EXPECT_EQ(rail.getConfiguration(), nullptr);
+        EXPECT_EQ(rail.getSensorMonitoring(), nullptr);
+    }
+
+    // Test where all parameters are specified
+    {
+        // Create Configuration
+        std::optional<double> volts{1.3};
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+        actions.push_back(std::make_unique<MockAction>());
+        std::unique_ptr<Configuration> configuration =
+            std::make_unique<Configuration>(volts, std::move(actions));
+
+        // Create SensorMonitoring
+        actions.clear();
+        actions.push_back(std::make_unique<MockAction>());
+        std::unique_ptr<SensorMonitoring> sensorMonitoring =
+            std::make_unique<SensorMonitoring>(std::move(actions));
+
+        // Create Rail
+        Rail rail{"vddr1", std::move(configuration),
+                  std::move(sensorMonitoring)};
+        EXPECT_EQ(rail.getID(), "vddr1");
+        EXPECT_NE(rail.getConfiguration(), nullptr);
+        EXPECT_EQ(rail.getConfiguration()->getVolts().has_value(), true);
+        EXPECT_EQ(rail.getConfiguration()->getVolts().value(), 1.3);
+        EXPECT_EQ(rail.getConfiguration()->getActions().size(), 2);
+        EXPECT_NE(rail.getSensorMonitoring(), nullptr);
+        EXPECT_EQ(rail.getSensorMonitoring()->getActions().size(), 1);
+    }
+}
+
+TEST(RailTests, GetConfiguration)
+{
+    // Test where Configuration was not specified in constructor
+    {
+        Rail rail{"vdd0"};
+        EXPECT_EQ(rail.getConfiguration(), nullptr);
+    }
+
+    // Test where Configuration was specified in constructor
+    {
+        // Create Configuration
+        std::optional<double> volts{3.2};
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+        std::unique_ptr<Configuration> configuration =
+            std::make_unique<Configuration>(volts, std::move(actions));
+
+        // Create Rail
+        Rail rail{"vddr1", std::move(configuration)};
+        EXPECT_NE(rail.getConfiguration(), nullptr);
+        EXPECT_EQ(rail.getConfiguration()->getVolts().has_value(), true);
+        EXPECT_EQ(rail.getConfiguration()->getVolts().value(), 3.2);
+        EXPECT_EQ(rail.getConfiguration()->getActions().size(), 1);
+    }
 }
 
 TEST(RailTests, GetID)
 {
-    Rail rail("vio2");
+    Rail rail{"vio2"};
     EXPECT_EQ(rail.getID(), "vio2");
 }
+
+TEST(RailTests, GetSensorMonitoring)
+{
+    // Test where SensorMonitoring was not specified in constructor
+    {
+        Rail rail{"vdd0", nullptr, nullptr};
+        EXPECT_EQ(rail.getSensorMonitoring(), nullptr);
+    }
+
+    // Test where SensorMonitoring was specified in constructor
+    {
+        std::unique_ptr<Configuration> configuration{};
+
+        // Create SensorMonitoring
+        std::vector<std::unique_ptr<Action>> actions{};
+        actions.push_back(std::make_unique<MockAction>());
+        actions.push_back(std::make_unique<MockAction>());
+        std::unique_ptr<SensorMonitoring> sensorMonitoring =
+            std::make_unique<SensorMonitoring>(std::move(actions));
+
+        // Create Rail
+        Rail rail{"vddr1", std::move(configuration),
+                  std::move(sensorMonitoring)};
+        EXPECT_NE(rail.getSensorMonitoring(), nullptr);
+        EXPECT_EQ(rail.getSensorMonitoring()->getActions().size(), 2);
+    }
+}