Activation: create associations

Create activation, functional, activate associations during PSU update.

Tested: With dummy psu update service, verify the assocations are
        created when the PSU update is completed, and not created
        when PSU update fails.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I3d457e65b55066b93f7fc9a3311093dcec05d020
diff --git a/test/test_activation.cpp b/test/test_activation.cpp
index 338dc60..891cdb6 100644
--- a/test/test_activation.cpp
+++ b/test/test_activation.cpp
@@ -1,4 +1,5 @@
 #include "activation.hpp"
+#include "mocked_association_interface.hpp"
 #include "mocked_utils.hpp"
 
 #include <sdbusplus/test/sdbus_mock.hpp>
@@ -37,13 +38,14 @@
     {
         return activation->activationProgress->progress();
     }
-    static constexpr auto dBusPath = SOFTWARE_OBJPATH;
     sdbusplus::SdBusMock sdbusMock;
     sdbusplus::bus::bus mockedBus = sdbusplus::get_mocked_new(&sdbusMock);
     const utils::MockedUtils& mockedUtils;
+    MockedAssociationInterface mockedAssociationInterface;
     std::unique_ptr<Activation> activation;
     std::string versionId = "abcdefgh";
     std::string extVersion = "Some Ext Version";
+    std::string dBusPath = std::string(SOFTWARE_OBJPATH) + "/" + versionId;
     Status status = Status::Ready;
     AssociationList associations;
 };
@@ -51,7 +53,8 @@
 TEST_F(TestActivation, ctordtor)
 {
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
 }
 
 namespace phosphor::software::updater::internal
@@ -75,12 +78,17 @@
 TEST_F(TestActivation, doUpdateWhenNoPSU)
 {
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
     ON_CALL(mockedUtils, getPSUInventoryPath(_))
         .WillByDefault(
             Return(std::vector<std::string>({}))); // No PSU inventory
     activation->requestedActivation(RequestedStatus::Active);
 
+    EXPECT_CALL(mockedAssociationInterface, createActiveAssociation(dBusPath))
+        .Times(0);
+    EXPECT_CALL(mockedAssociationInterface, addFunctionalAssociation(dBusPath))
+        .Times(0);
     EXPECT_EQ(Status::Failed, activation->activation());
 }
 
@@ -88,7 +96,8 @@
 {
     constexpr auto psu0 = "/com/example/inventory/psu0";
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
     ON_CALL(mockedUtils, getPSUInventoryPath(_))
         .WillByDefault(
             Return(std::vector<std::string>({psu0}))); // One PSU inventory
@@ -96,6 +105,10 @@
 
     EXPECT_EQ(Status::Activating, activation->activation());
 
+    EXPECT_CALL(mockedAssociationInterface, createActiveAssociation(dBusPath))
+        .Times(1);
+    EXPECT_CALL(mockedAssociationInterface, addFunctionalAssociation(dBusPath))
+        .Times(1);
     onUpdateDone();
     EXPECT_EQ(Status::Active, activation->activation());
 }
@@ -107,7 +120,8 @@
     constexpr auto psu2 = "/com/example/inventory/psu2";
     constexpr auto psu3 = "/com/example/inventory/psu3";
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
     ON_CALL(mockedUtils, getPSUInventoryPath(_))
         .WillByDefault(Return(
             std::vector<std::string>({psu0, psu1, psu2, psu3}))); // 4 PSUs
@@ -128,6 +142,11 @@
     EXPECT_EQ(Status::Activating, activation->activation());
     EXPECT_EQ(70, getProgress());
 
+    EXPECT_CALL(mockedAssociationInterface, createActiveAssociation(dBusPath))
+        .Times(1);
+    EXPECT_CALL(mockedAssociationInterface, addFunctionalAssociation(dBusPath))
+        .Times(1);
+
     onUpdateDone();
     EXPECT_EQ(Status::Active, activation->activation());
 }
@@ -139,7 +158,8 @@
     constexpr auto psu2 = "/com/example/inventory/psu2";
     constexpr auto psu3 = "/com/example/inventory/psu3";
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
     ON_CALL(mockedUtils, getPSUInventoryPath(_))
         .WillByDefault(Return(
             std::vector<std::string>({psu0, psu1, psu2, psu3}))); // 4 PSUs
@@ -152,6 +172,10 @@
     EXPECT_EQ(Status::Activating, activation->activation());
     EXPECT_EQ(30, getProgress());
 
+    EXPECT_CALL(mockedAssociationInterface, createActiveAssociation(dBusPath))
+        .Times(0);
+    EXPECT_CALL(mockedAssociationInterface, addFunctionalAssociation(dBusPath))
+        .Times(0);
     onUpdateFailed();
     EXPECT_EQ(Status::Failed, activation->activation());
 }
@@ -160,7 +184,8 @@
 {
     constexpr auto psu0 = "/com/example/inventory/psu0";
     activation = std::make_unique<Activation>(mockedBus, dBusPath, versionId,
-                                              extVersion, status, associations);
+                                              extVersion, status, associations,
+                                              &mockedAssociationInterface);
     ON_CALL(mockedUtils, getPSUInventoryPath(_))
         .WillByDefault(
             Return(std::vector<std::string>({psu0}))); // One PSU inventory