From 2363a4fa72ed4596a07a4aaa5e08fe44979b3497 Mon Sep 17 00:00:00 2001 From: Jaewook Jung Date: Fri, 29 Jul 2016 17:34:31 +0900 Subject: [PATCH] added APIs related to group&invite on OCAccountManager According to the OCF cloud specification, I implemented new 15 APIs related to group and invite. : createGroup, getGroupList, deleteGroup, joinGroup, addDeviceToGroup, getGroupInfo, leaveGroup, deleteDeviceFromGroup, observeGroup, cancelObserveGroup, observeInvitation, cancelObserveInvitation, sendInvitation, cancelInvitation, deleteInvitation Change-Id: I29e4cb8839d254a58be48b04d0fef35e6fbb2867 Signed-off-by: Jaewook Jung Reviewed-on: https://gerrit.iotivity.org/gerrit/10149 Tested-by: jenkins-iotivity Reviewed-by: Jaehong Jo Reviewed-by: jihwan seo Reviewed-by: Ashok Babu Channa --- resource/csdk/stack/include/octypes.h | 42 ++++ resource/include/OCAccountManager.h | 171 +++++++++++++++ resource/src/OCAccountManager.cpp | 241 ++++++++++++++++++++- resource/unittests/OCAccountManagerTest.cpp | 315 ++++++++++++++++++++++++++++ 4 files changed, 768 insertions(+), 1 deletion(-) diff --git a/resource/csdk/stack/include/octypes.h b/resource/csdk/stack/include/octypes.h index 7432863..2c48c45 100644 --- a/resource/csdk/stack/include/octypes.h +++ b/resource/csdk/stack/include/octypes.h @@ -367,6 +367,12 @@ extern "C" { /** Account token refresh URI.*/ #define OC_RSRVD_ACCOUNT_TOKEN_REFRESH_URI "/ocf/account/tokenrefresh" +/** ACL group URI.*/ +#define OC_RSRVD_ACL_GROUP_URI "/ocf/acl/group" + +/** ACL invite URI.*/ +#define OC_RSRVD_ACL_INVITE_URI "/ocf/acl/invite" + /** Defines auth provider. */ #define OC_RSRVD_AUTHPROVIDER "authprovider" @@ -391,6 +397,33 @@ extern "C" { /** Defines user UUID. */ #define OC_RSRVD_USER_UUID "uid" +/** Defines user ID. */ +#define OC_RSRVD_USER_ID "userid" + +/** Defines group ID. */ +#define OC_RSRVD_GROUP_ID "gid" + +/** Defines group Master ID. */ +#define OC_RSRVD_GROUP_MASTER_ID "gmid" + +/** Defines group type. */ +#define OC_RSRVD_GROUP_TYPE "gtype" + +/** Defines member of group ID. */ +#define OC_RSRVD_MEMBER_ID "mid" + +/** Defines device ID list. */ +#define OC_RSRVD_DEVICE_ID_LIST "dilist" + +/** Defines public. */ +#define OC_RSRVD_PUBLIC "Public" + +/** Defines private. */ +#define OC_RSRVD_PRIVATE "Private" + +/** Defines options. */ +#define OC_RSRVD_INVITE "invite" + /** Defines options. */ #define OC_RSRVD_OPTIONS "options" @@ -1512,6 +1545,15 @@ typedef struct OCDPDev } OCDPDev_t; //#endif // DIRECT_PAIRING +/** + * Type of Group for ACL. + */ +typedef enum +{ + GT_PUBLIC = 0, + GT_PRIVATE, +} OCAclGroupType; + /* * ------------------------------------------------------------------------------------------- * Callback function definitions diff --git a/resource/include/OCAccountManager.h b/resource/include/OCAccountManager.h index a5d3f40..24868d6 100644 --- a/resource/include/OCAccountManager.h +++ b/resource/include/OCAccountManager.h @@ -21,6 +21,8 @@ #ifndef OC_ACCOUNT_MANAGER_H_ #define OC_ACCOUNT_MANAGER_H_ +#include + #include #include #include @@ -154,10 +156,179 @@ namespace OC OCStackResult deleteDevice(const std::string& deviceId, DeleteCallback cloudConnectHandler); + /** + * Function to create a group on account server + * + * @param groupType Group type that can be used for referencing default group ACL creation. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult createGroup(OCAclGroupType groupType, + PostCallback cloudConnectHandler); + + /** + * Function to get a list of groups joined from account server + * + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult getGroupList(GetCallback cloudConnectHandler); + + /** + * Function to delete the group from account server + * + * @param groupId Group ID to delete. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult deleteGroup(const std::string& groupId, + DeleteCallback cloudConnectHandler); + + /** + * Function to join the group on account server + * + * @param groupId Group ID to join + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult joinGroup(const std::string& groupId, + PostCallback cloudConnectHandler); + + /** + * Function to add devices to the group on account server + * + * @param groupId Group ID to add devices. + * @param deviceId List of devices to add. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult addDeviceToGroup(const std::string& groupId, + const std::vector& deviceId, + PostCallback cloudConnectHandler); + + /** + * Function to get information of the group from account server + * + * @param groupId Group ID to get information. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult getGroupInfo(const std::string& groupId, + GetCallback cloudConnectHandler); + + /** + * Function to leave the group joined on account server + * + * @param groupId Group ID to leave. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult leaveGroup(const std::string& groupId, + DeleteCallback cloudConnectHandler); + + /** + * Function to delete devices from the group on account server + * + * @param groupId Group ID to delete devices. + * @param deviceId List of devices to delete. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult deleteDeviceFromGroup(const std::string& groupId, + const std::vector& deviceId, + DeleteCallback cloudConnectHandler); + + /** + * Function to register observe to the group on account server + * User can receive a notify when the group get changed (eg. new user/device added) + * + * @param groupId Group ID to observe. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult observeGroup(const std::string& groupId, + ObserveCallback cloudConnectHandler); + + /** + * Function to cancel observe to the group on account server + * + * @param groupId Group ID to observe. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult cancelObserveGroup(const std::string& groupId); + + /** + * Function to register observe to invitation resource on account server + * User can receive a invitation which is including group ID to join + * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation + * on account server. + * + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult observeInvitation(ObserveCallback cloudConnectHandler); + + /** + * Function to cancel observe to invitation resource on account server + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult cancelObserveInvitation(); + + /** + * Function to send a invitation to invite a user into a group + * + * @param groupId Group ID for inviting. + * @param userUuid Identifier of the user to invite. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult sendInvitation(const std::string& groupId, + const std::string& userUuid, + PostCallback cloudConnectHandler); + + /** + * Function to cancel a invitation on account server that user has sent + * + * @param groupId Group ID to cancel a invitation. + * @param userUuid Identifier of the user to cancel a invitation. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult cancelInvitation(const std::string& groupId, + const std::string& userUuid, + DeleteCallback cloudConnectHandler); + + /** + * Function to delete a invitation on account server that user has received + * + * @param groupId Group ID to delete a invitation. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + OCStackResult deleteInvitation(const std::string& groupId, + DeleteCallback cloudConnectHandler); + private: std::weak_ptr m_clientWrapper; std::string m_deviceID; std::string m_host; + OCDoHandle m_invitationObserveHandle; + mutable std::map m_groupObserveHandles; OCConnectivityType m_connType; QualityOfService m_defaultQos; diff --git a/resource/src/OCAccountManager.cpp b/resource/src/OCAccountManager.cpp index 9ac03df..27bb247 100644 --- a/resource/src/OCAccountManager.cpp +++ b/resource/src/OCAccountManager.cpp @@ -31,7 +31,8 @@ using OC::checked_guard; OCAccountManager::OCAccountManager(std::weak_ptr clientWrapper, const std::string& host, OCConnectivityType connectivityType) - : m_clientWrapper(clientWrapper), m_host(host), m_connType(connectivityType) + : m_clientWrapper(clientWrapper), m_host(host), m_connType(connectivityType), + m_invitationObserveHandle(nullptr) { if (m_host.empty() || m_clientWrapper.expired()) { @@ -46,6 +47,7 @@ OCAccountManager::OCAccountManager(std::weak_ptr clientWrapper, } m_deviceID.append(di); + m_groupObserveHandles = {}; checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetDefaultQos, m_defaultQos); } @@ -199,4 +201,241 @@ OCStackResult OCAccountManager::deleteDevice(const std::string& deviceId, m_connType, cloudConnectHandler, m_defaultQos); } +OCStackResult OCAccountManager::createGroup(OCAclGroupType groupType, + PostCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI; + + std::string gtype; + switch (groupType) + { + case GT_PUBLIC: + gtype = OC_RSRVD_PUBLIC; + break; + case GT_PRIVATE: + gtype = OC_RSRVD_PRIVATE; + break; + default: + return result_guard(OC_STACK_INVALID_PARAM); + } + OCRepresentation rep; + rep.setValue(OC_RSRVD_GROUP_TYPE, gtype); + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation, + OCDevAddr(), uri, rep, QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::getGroupList(GetCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation, + OCDevAddr(), uri, QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::deleteGroup(const std::string& groupId, + DeleteCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + + "?" + OC_RSRVD_GROUP_ID + "=" + groupId; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource, + OCDevAddr(), uri, HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::joinGroup(const std::string& groupId, + PostCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation, + OCDevAddr(), uri, OCRepresentation(), QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::addDeviceToGroup(const std::string& groupId, + const std::vector& deviceId, + PostCallback cloudConnectHandler) +{ + if (deviceId.empty()) + { + return result_guard(OC_STACK_INVALID_PARAM); + } + + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + OCRepresentation rep; + rep.setValue>(std::string(OC_RSRVD_DEVICE_ID_LIST), deviceId); + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation, + OCDevAddr(), uri, rep, QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::getGroupInfo(const std::string& groupId, + GetCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::GetResourceRepresentation, + OCDevAddr(), uri, QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::leaveGroup(const std::string& groupId, + DeleteCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource, + OCDevAddr(), uri, HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::deleteDeviceFromGroup(const std::string& groupId, + const std::vector& deviceId, + DeleteCallback cloudConnectHandler) +{ + if (deviceId.empty()) + { + return result_guard(OC_STACK_INVALID_PARAM); + } + + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + + uri.append("?"); + for (auto iter : deviceId) + { + uri.append((std::string)OC_RSRVD_DEVICE_ID_LIST + "=" + iter + ";"); + } + uri.resize(uri.size() - 1); + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource, + OCDevAddr(), uri, HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::observeGroup(const std::string& groupId, + ObserveCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + OCDoHandle handle = nullptr; + + OCStackResult result = checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource, + ObserveType::Observe, &handle, OCDevAddr(), uri, + QueryParamsMap(), HeaderOptions(), cloudConnectHandler, + m_defaultQos); + + if (OC_STACK_OK == result) + { + m_groupObserveHandles.insert(std::pair(groupId, handle)); + } + + return result; + +} + +OCStackResult OCAccountManager::cancelObserveGroup(const std::string& groupId) +{ + auto found = m_groupObserveHandles.find(groupId); + if (m_groupObserveHandles.end() == found) + { + return result_guard(OC_STACK_INVALID_PARAM); + } + + OCDoHandle handle = found->second; + + std::string uri = m_host + OC_RSRVD_ACL_GROUP_URI + "/" + groupId; + + OCStackResult result = checked_guard(m_clientWrapper.lock(), + &IClientWrapper::CancelObserveResource, handle, + (const char*)"", uri, HeaderOptions(), m_defaultQos); + + if (OC_STACK_OK == result) + { + m_groupObserveHandles.erase(groupId); + handle = nullptr; + } + + return result; +} + +OCStackResult OCAccountManager::observeInvitation(ObserveCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource, + ObserveType::Observe, &m_invitationObserveHandle, OCDevAddr(), uri, + QueryParamsMap(), HeaderOptions(), cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::cancelObserveInvitation() +{ + if (nullptr == m_invitationObserveHandle) + { + return result_guard(OC_STACK_INVALID_PARAM); + } + + std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI; + + OCStackResult result = checked_guard(m_clientWrapper.lock(), + &IClientWrapper::CancelObserveResource, + m_invitationObserveHandle, + (const char*)"", uri, HeaderOptions(), m_defaultQos); + + if (OC_STACK_OK == result) + { + m_invitationObserveHandle = nullptr; + } + + return result; +} + +OCStackResult OCAccountManager::sendInvitation(const std::string& groupId, + const std::string& userUuid, + PostCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI; + + OCRepresentation invitation; + invitation.setValue(OC_RSRVD_GROUP_ID, groupId); + invitation.setValue(OC_RSRVD_MEMBER_ID, userUuid); + + std::vector invite{invitation}; + + OCRepresentation rep; + rep.setValue(OC_RSRVD_INVITE, invite); + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation, + OCDevAddr(), uri, rep, QueryParamsMap(), HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::cancelInvitation(const std::string& groupId, + const std::string& userUuid, + DeleteCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI + "?" + OC_RSRVD_GROUP_ID + "=" + groupId + + ";" + OC_RSRVD_MEMBER_ID + "=" + userUuid; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource, + OCDevAddr(), uri, HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + +OCStackResult OCAccountManager::deleteInvitation(const std::string& groupId, + DeleteCallback cloudConnectHandler) +{ + std::string uri = m_host + OC_RSRVD_ACL_INVITE_URI + "?" + OC_RSRVD_GROUP_ID + "=" + groupId; + + return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource, + OCDevAddr(), uri, HeaderOptions(), + m_connType, cloudConnectHandler, m_defaultQos); +} + } // namespace OC diff --git a/resource/unittests/OCAccountManagerTest.cpp b/resource/unittests/OCAccountManagerTest.cpp index 09a8bae..f183c95 100644 --- a/resource/unittests/OCAccountManagerTest.cpp +++ b/resource/unittests/OCAccountManagerTest.cpp @@ -36,6 +36,11 @@ namespace OCAccountManagerTest { } + void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& /*rep*/, + const int& /*eCode*/, const int& /*sequenceNumber*/) + { + } + // Helper method OCAccountManager::Ptr ConstructAccountManagerObject(std::string host) { @@ -211,4 +216,314 @@ namespace OCAccountManagerTest EXPECT_TRUE(NULL != accountManager); EXPECT_ANY_THROW(accountManager->deleteDevice(deviceId, nullptr)); } + + // CreateGroup Test + TEST(CreateGroupTest, DISABLED_CreateGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(GT_PUBLIC, &accountHandler)); + } + + TEST(CreateGroupTest, CreateGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->createGroup(GT_PUBLIC, nullptr)); + } + + // GetGroupList Test + TEST(GetGroupListTest, DISABLED_GetGroupListForValid) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->getGroupList(&accountHandler)); + } + + TEST(GetGroupListTest, GetGroupListWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->getGroupList(nullptr)); + } + + // DeleteGroup Test + TEST(DeleteGroupTest, DISABLED_DeleteGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->deleteGroup(groupId, &deleteHandler)); + } + + TEST(DeleteGroupTest, DeleteGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->deleteGroup(groupId, nullptr)); + } + + // JoinGroup Test + TEST(JoinGroupTest, DISABLED_JoinGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->joinGroup(groupId, &accountHandler)); + } + + TEST(JoinGroupTest, JoinGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->joinGroup(groupId, nullptr)); + } + + // AddDeviceToGroup Test + TEST(AddDeviceToGroupTest, DISABLED_AddDeviceToGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {"AnyDevideId"}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->addDeviceToGroup(groupId, deviceId, + &accountHandler)); + } + + TEST(AddDeviceToGroupTest, AddDeviceToGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {"AnyDevideId"}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->addDeviceToGroup(groupId, deviceId, nullptr)); + } + + TEST(AddDeviceToGroupTest, AddDeviceToGroupWithEmptyDeviceID) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->addDeviceToGroup(groupId, deviceId, &accountHandler)); + } + + // GetGroupInfo Test + TEST(GetGroupInfoTest, DISABLED_GetGroupInfoForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->getGroupInfo(groupId, &accountHandler)); + } + + TEST(GetGroupInfoTest, GetGroupInfoWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->getGroupInfo(groupId, nullptr)); + } + + // LeaveGroup Test + TEST(LeaveGroupTest, DISABLED_LeaveGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->leaveGroup(groupId, &deleteHandler)); + } + + TEST(LeaveGroupTest, LeaveGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->leaveGroup(groupId, nullptr)); + } + + // DeleteDeviceFromGroup Test + TEST(DeleteDeviceFromGroupTest, DISABLED_DeleteDeviceFromGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {"AnyDevideId"}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->deleteDeviceFromGroup(groupId, deviceId, + &deleteHandler)); + } + + TEST(DeleteDeviceFromGroupTest, DeleteDeviceFromGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {"AnyDevideId"}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->deleteDeviceFromGroup(groupId, deviceId, nullptr)); + } + + TEST(DeleteDeviceFromGroupTest, DeleteDeviceFromGroupEmptyDeviceID) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::vector deviceId = {}; + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->deleteDeviceFromGroup(groupId, deviceId, + &deleteHandler)); + } + + // ObserveGroup Test + TEST(ObserveGroupTest, DISABLED_ObserveGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(groupId, &onObserve)); + } + + TEST(ObserveGroupTest, ObserveGroupWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->observeGroup(groupId, nullptr)); + } + + // CancelObserveGroup Test + TEST(CancelObserveGroupTest, DISABLED_CancelObserveGroupForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(groupId, &onObserve)); + EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveGroup(groupId)); + } + + TEST(CancelObserveGroupTest, CancelObserveGroupWithoutObserve) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->cancelObserveGroup(groupId)); + } + + // ObserveInvitation Test + TEST(ObserveInvitationTest, DISABLED_ObserveInvitationForValid) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve)); + } + + TEST(ObserveInvitationTest, ObserveInvitationWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->observeInvitation(nullptr)); + } + + // CancelObserveInvitation Test + TEST(CancelObserveInvitationTest, DISABLED_CancelObserveInvitationForValid) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve)); + EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveInvitation()); + } + + TEST(CancelObserveInvitationTest, CancelObserveInvitationWithoutObserve) + { + std::string host("coap://192.168.1.2:5000"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->cancelObserveInvitation()); + } + + // SendInvitation Test + TEST(SendInvitationTest, DISABLED_SendInvitationForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::string userId("AnyUserId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->sendInvitation(groupId, userId, &accountHandler)); + } + + TEST(SendInvitationTest, SendInvitationWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::string userId("AnyUserId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->sendInvitation(groupId, userId, nullptr)); + } + + // CancelInvitation Test + TEST(CancelInvitationTest, DISABLED_CancelInvitationForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::string userId("AnyUserId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->cancelInvitation(groupId, userId, &deleteHandler)); + } + + TEST(CancelInvitationTest, CancelInvitationWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + std::string userId("AnyUserId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->cancelInvitation(groupId, userId, nullptr)); + } + + // DeleteInvitation Test + TEST(DeleteInvitationTest, DISABLED_DeleteInvitationForValid) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_EQ(OC_STACK_OK, accountManager->deleteInvitation(groupId, &deleteHandler)); + } + + TEST(DeleteInvitationTest, DeleteInvitationWithNullCallback) + { + std::string host("coap://192.168.1.2:5000"); + std::string groupId("AnyGroupId"); + OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host); + EXPECT_TRUE(NULL != accountManager); + EXPECT_ANY_THROW(accountManager->deleteInvitation(groupId, nullptr)); + } } -- 2.7.4