1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include <OCPlatform.h>
23 #include <gtest/gtest.h>
25 namespace OCAccountManagerTest
30 void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
35 void deleteHandler(const HeaderOptions& /*headerOptions*/, const int /*eCode*/)
39 void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& /*rep*/,
40 const int& /*eCode*/, const int& /*sequenceNumber*/)
45 OCAccountManager::Ptr ConstructAccountManagerObject(std::string host)
47 auto ret = OCPlatform::constructAccountManagerObject(host, CT_DEFAULT);
51 ADD_FAILURE() << "ConstructAccountManagerObject result was null";
52 throw std::runtime_error("ConstructAccountManagerObject result was null");
61 std::string host("coap://192.168.1.2:5000");
62 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
63 EXPECT_TRUE(NULL != accountManager);
64 EXPECT_TRUE(accountManager->host() == host);
67 // ConnectivityType Test
68 TEST(ConnectivityTypeTest, ConnectivityType)
70 std::string host("coap://192.168.1.2:5000");
71 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
72 EXPECT_TRUE(NULL != accountManager);
73 EXPECT_TRUE(accountManager->connectivityType() == CT_DEFAULT);
77 TEST(SignUpTest, DISABLED_SignUpWithoutOptionForValid)
79 std::string host("coap://192.168.1.2:5000");
80 std::string authProvider("AnyAuthProvider");
81 std::string authCode("AnyAuthCode");
82 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
83 EXPECT_TRUE(NULL != accountManager);
84 EXPECT_EQ(OC_STACK_OK, accountManager->signUp(authProvider, authCode, &accountHandler));
87 TEST(SignUpTest, DISABLED_SignUpForValid)
89 std::string host("coap://192.168.1.2:5000");
90 std::string authProvider("AnyAuthProvider");
91 std::string authCode("AnyAuthCode");
92 QueryParamsMap options = {};
93 options.insert(std::pair<std::string, std::string>("AnyOptionKey", "AnyOptionValue"));
94 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
95 EXPECT_TRUE(NULL != accountManager);
96 EXPECT_EQ(OC_STACK_OK, accountManager->signUp(authProvider, authCode, options,
100 TEST(SignUpTest, SignUpWithNullCallback)
102 std::string host("coap://192.168.1.2:5000");
103 std::string authProvider("AnyAuthProvider");
104 std::string authCode("AnyAuthCode");
105 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
106 EXPECT_TRUE(NULL != accountManager);
107 EXPECT_ANY_THROW(accountManager->signUp(authProvider, authCode, nullptr));
111 TEST(SignInTest, DISABLED_SignInForValid)
113 std::string host("coap://192.168.1.2:5000");
114 std::string userId("AnyUserId");
115 std::string accessToken("AnyAccessToken");
116 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
117 EXPECT_TRUE(NULL != accountManager);
118 EXPECT_EQ(OC_STACK_OK, accountManager->signIn(userId, accessToken, &accountHandler));
121 TEST(SignInTest, SignInWithNullCallback)
123 std::string host("coap://192.168.1.2:5000");
124 std::string userId("AnyUserId");
125 std::string accessToken("AnyAccessToken");
126 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
127 EXPECT_TRUE(NULL != accountManager);
128 EXPECT_ANY_THROW(accountManager->signIn(userId, accessToken, nullptr));
132 TEST(SignOutTest, DISABLED_SignOutForValid)
134 std::string host("coap://192.168.1.2:5000");
135 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
136 EXPECT_TRUE(NULL != accountManager);
137 EXPECT_EQ(OC_STACK_OK, accountManager->signOut(&accountHandler));
140 TEST(SignOutTest, SignOutWithNullCallback)
142 std::string host("coap://192.168.1.2:5000");
143 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
144 EXPECT_TRUE(NULL != accountManager);
145 EXPECT_ANY_THROW(accountManager->signOut(nullptr));
148 // RefreshAccessToken Test
149 TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenForValid)
151 std::string host("coap://192.168.1.2:5000");
152 std::string userId("AnyUserId");
153 std::string refreshToken("AnyRefreshToken");
154 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
155 EXPECT_TRUE(NULL != accountManager);
156 EXPECT_EQ(OC_STACK_OK, accountManager->refreshAccessToken(userId, refreshToken,
160 TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
162 std::string host("coap://192.168.1.2:5000");
163 std::string userId("AnyUserId");
164 std::string refreshToken("AnyRefreshToken");
165 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
166 EXPECT_TRUE(NULL != accountManager);
167 EXPECT_ANY_THROW(accountManager->refreshAccessToken(userId, refreshToken, nullptr));
171 TEST(SearchUserTest, DISABLED_SearchUserWithUserUuidForValid)
173 std::string host("coap://192.168.1.2:5000");
174 std::string userId("AnyUserId");
175 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
176 EXPECT_TRUE(NULL != accountManager);
177 EXPECT_EQ(OC_STACK_OK, accountManager->searchUser(userId, &accountHandler));
180 TEST(SearchUserTest, DISABLED_SearchUserWithQueryForValid)
182 std::string host("coap://192.168.1.2:5000");
183 std::string key("AnyKey");
184 std::string value("AnyValue");
185 QueryParamsMap query = {};
186 query.insert(std::pair<std::string, std::string>(key, value));
187 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
188 EXPECT_TRUE(NULL != accountManager);
189 EXPECT_EQ(OC_STACK_OK, accountManager->searchUser(query, &accountHandler));
192 TEST(SearchUserTest, SearchUserWithNullCallback)
194 std::string host("coap://192.168.1.2:5000");
195 std::string userId("AnyUserId");
196 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
197 EXPECT_TRUE(NULL != accountManager);
198 EXPECT_ANY_THROW(accountManager->searchUser(userId, nullptr));
202 TEST(DeleteDeviceTest, DISABLED_DeleteDeviceForValid)
204 std::string host("coap://192.168.1.2:5000");
205 std::string deviceId("AnyDeviceId");
206 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
207 EXPECT_TRUE(NULL != accountManager);
208 EXPECT_EQ(OC_STACK_OK, accountManager->deleteDevice(deviceId, &deleteHandler));
211 TEST(DeleteDeviceTest, DeleteDeviceWithNullCallback)
213 std::string host("coap://192.168.1.2:5000");
214 std::string deviceId("AnyDeviceId");
215 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
216 EXPECT_TRUE(NULL != accountManager);
217 EXPECT_ANY_THROW(accountManager->deleteDevice(deviceId, nullptr));
221 TEST(CreateGroupTest, DISABLED_CreateGroupForValid)
223 std::string host("coap://192.168.1.2:5000");
224 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
225 EXPECT_TRUE(NULL != accountManager);
226 EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(AclGroupType::PUBLIC, &accountHandler));
229 TEST(CreateGroupTest, CreateGroupWithNullCallback)
231 std::string host("coap://192.168.1.2:5000");
232 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
233 EXPECT_TRUE(NULL != accountManager);
234 EXPECT_ANY_THROW(accountManager->createGroup(AclGroupType::PUBLIC, nullptr));
238 TEST(GetGroupListTest, DISABLED_GetGroupListForValid)
240 std::string host("coap://192.168.1.2:5000");
241 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
242 EXPECT_TRUE(NULL != accountManager);
243 EXPECT_EQ(OC_STACK_OK, accountManager->getGroupList(&accountHandler));
246 TEST(GetGroupListTest, GetGroupListWithNullCallback)
248 std::string host("coap://192.168.1.2:5000");
249 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
250 EXPECT_TRUE(NULL != accountManager);
251 EXPECT_ANY_THROW(accountManager->getGroupList(nullptr));
255 TEST(DeleteGroupTest, DISABLED_DeleteGroupForValid)
257 std::string host("coap://192.168.1.2:5000");
258 std::string groupId("AnyGroupId");
259 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
260 EXPECT_TRUE(NULL != accountManager);
261 EXPECT_EQ(OC_STACK_OK, accountManager->deleteGroup(groupId, &deleteHandler));
264 TEST(DeleteGroupTest, DeleteGroupWithNullCallback)
266 std::string host("coap://192.168.1.2:5000");
267 std::string groupId("AnyGroupId");
268 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
269 EXPECT_TRUE(NULL != accountManager);
270 EXPECT_ANY_THROW(accountManager->deleteGroup(groupId, nullptr));
274 TEST(JoinGroupTest, DISABLED_JoinGroupForValid)
276 std::string host("coap://192.168.1.2:5000");
277 std::string groupId("AnyGroupId");
278 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
279 EXPECT_TRUE(NULL != accountManager);
280 EXPECT_EQ(OC_STACK_OK, accountManager->joinGroup(groupId, &accountHandler));
283 TEST(JoinGroupTest, JoinGroupWithNullCallback)
285 std::string host("coap://192.168.1.2:5000");
286 std::string groupId("AnyGroupId");
287 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
288 EXPECT_TRUE(NULL != accountManager);
289 EXPECT_ANY_THROW(accountManager->joinGroup(groupId, nullptr));
292 // AddDeviceToGroup Test
293 TEST(AddDeviceToGroupTest, DISABLED_AddDeviceToGroupForValid)
295 std::string host("coap://192.168.1.2:5000");
296 std::string groupId("AnyGroupId");
297 std::vector<std::string> deviceId = {"AnyDevideId"};
298 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
299 EXPECT_TRUE(NULL != accountManager);
300 EXPECT_EQ(OC_STACK_OK, accountManager->addDeviceToGroup(groupId, deviceId,
304 TEST(AddDeviceToGroupTest, AddDeviceToGroupWithNullCallback)
306 std::string host("coap://192.168.1.2:5000");
307 std::string groupId("AnyGroupId");
308 std::vector<std::string> deviceId = {"AnyDevideId"};
309 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
310 EXPECT_TRUE(NULL != accountManager);
311 EXPECT_ANY_THROW(accountManager->addDeviceToGroup(groupId, deviceId, nullptr));
314 TEST(AddDeviceToGroupTest, AddDeviceToGroupWithEmptyDeviceID)
316 std::string host("coap://192.168.1.2:5000");
317 std::string groupId("AnyGroupId");
318 std::vector<std::string> deviceId = {};
319 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
320 EXPECT_TRUE(NULL != accountManager);
321 EXPECT_ANY_THROW(accountManager->addDeviceToGroup(groupId, deviceId, &accountHandler));
325 TEST(GetGroupInfoTest, DISABLED_GetGroupInfoForValid)
327 std::string host("coap://192.168.1.2:5000");
328 std::string groupId("AnyGroupId");
329 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
330 EXPECT_TRUE(NULL != accountManager);
331 EXPECT_EQ(OC_STACK_OK, accountManager->getGroupInfo(groupId, &accountHandler));
334 TEST(GetGroupInfoTest, GetGroupInfoWithNullCallback)
336 std::string host("coap://192.168.1.2:5000");
337 std::string groupId("AnyGroupId");
338 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
339 EXPECT_TRUE(NULL != accountManager);
340 EXPECT_ANY_THROW(accountManager->getGroupInfo(groupId, nullptr));
344 TEST(LeaveGroupTest, DISABLED_LeaveGroupForValid)
346 std::string host("coap://192.168.1.2:5000");
347 std::string groupId("AnyGroupId");
348 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
349 EXPECT_TRUE(NULL != accountManager);
350 EXPECT_EQ(OC_STACK_OK, accountManager->leaveGroup(groupId, &deleteHandler));
353 TEST(LeaveGroupTest, LeaveGroupWithNullCallback)
355 std::string host("coap://192.168.1.2:5000");
356 std::string groupId("AnyGroupId");
357 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
358 EXPECT_TRUE(NULL != accountManager);
359 EXPECT_ANY_THROW(accountManager->leaveGroup(groupId, nullptr));
362 // DeleteDeviceFromGroup Test
363 TEST(DeleteDeviceFromGroupTest, DISABLED_DeleteDeviceFromGroupForValid)
365 std::string host("coap://192.168.1.2:5000");
366 std::string groupId("AnyGroupId");
367 std::vector<std::string> deviceId = {"AnyDevideId"};
368 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
369 EXPECT_TRUE(NULL != accountManager);
370 EXPECT_EQ(OC_STACK_OK, accountManager->deleteDeviceFromGroup(groupId, deviceId,
374 TEST(DeleteDeviceFromGroupTest, DeleteDeviceFromGroupWithNullCallback)
376 std::string host("coap://192.168.1.2:5000");
377 std::string groupId("AnyGroupId");
378 std::vector<std::string> deviceId = {"AnyDevideId"};
379 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
380 EXPECT_TRUE(NULL != accountManager);
381 EXPECT_ANY_THROW(accountManager->deleteDeviceFromGroup(groupId, deviceId, nullptr));
384 TEST(DeleteDeviceFromGroupTest, DeleteDeviceFromGroupEmptyDeviceID)
386 std::string host("coap://192.168.1.2:5000");
387 std::string groupId("AnyGroupId");
388 std::vector<std::string> deviceId = {};
389 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
390 EXPECT_TRUE(NULL != accountManager);
391 EXPECT_ANY_THROW(accountManager->deleteDeviceFromGroup(groupId, deviceId,
396 TEST(ObserveGroupTest, DISABLED_ObserveGroupForValid)
398 std::string host("coap://192.168.1.2:5000");
399 std::string groupId("AnyGroupId");
400 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
401 EXPECT_TRUE(NULL != accountManager);
402 EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(groupId, &onObserve));
405 TEST(ObserveGroupTest, ObserveGroupWithNullCallback)
407 std::string host("coap://192.168.1.2:5000");
408 std::string groupId("AnyGroupId");
409 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
410 EXPECT_TRUE(NULL != accountManager);
411 EXPECT_ANY_THROW(accountManager->observeGroup(groupId, nullptr));
414 // CancelObserveGroup Test
415 TEST(CancelObserveGroupTest, DISABLED_CancelObserveGroupForValid)
417 std::string host("coap://192.168.1.2:5000");
418 std::string groupId("AnyGroupId");
419 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
420 EXPECT_TRUE(NULL != accountManager);
421 EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(groupId, &onObserve));
422 EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveGroup(groupId));
425 TEST(CancelObserveGroupTest, CancelObserveGroupWithoutObserve)
427 std::string host("coap://192.168.1.2:5000");
428 std::string groupId("AnyGroupId");
429 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
430 EXPECT_TRUE(NULL != accountManager);
431 EXPECT_ANY_THROW(accountManager->cancelObserveGroup(groupId));
434 // ObserveInvitation Test
435 TEST(ObserveInvitationTest, DISABLED_ObserveInvitationForValid)
437 std::string host("coap://192.168.1.2:5000");
438 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
439 EXPECT_TRUE(NULL != accountManager);
440 EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve));
443 TEST(ObserveInvitationTest, ObserveInvitationWithNullCallback)
445 std::string host("coap://192.168.1.2:5000");
446 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
447 EXPECT_TRUE(NULL != accountManager);
448 EXPECT_ANY_THROW(accountManager->observeInvitation(nullptr));
451 // CancelObserveInvitation Test
452 TEST(CancelObserveInvitationTest, DISABLED_CancelObserveInvitationForValid)
454 std::string host("coap://192.168.1.2:5000");
455 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
456 EXPECT_TRUE(NULL != accountManager);
457 EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve));
458 EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveInvitation());
461 TEST(CancelObserveInvitationTest, CancelObserveInvitationWithoutObserve)
463 std::string host("coap://192.168.1.2:5000");
464 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
465 EXPECT_TRUE(NULL != accountManager);
466 EXPECT_ANY_THROW(accountManager->cancelObserveInvitation());
469 // SendInvitation Test
470 TEST(SendInvitationTest, DISABLED_SendInvitationForValid)
472 std::string host("coap://192.168.1.2:5000");
473 std::string groupId("AnyGroupId");
474 std::string userId("AnyUserId");
475 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
476 EXPECT_TRUE(NULL != accountManager);
477 EXPECT_EQ(OC_STACK_OK, accountManager->sendInvitation(groupId, userId, &accountHandler));
480 TEST(SendInvitationTest, SendInvitationWithNullCallback)
482 std::string host("coap://192.168.1.2:5000");
483 std::string groupId("AnyGroupId");
484 std::string userId("AnyUserId");
485 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
486 EXPECT_TRUE(NULL != accountManager);
487 EXPECT_ANY_THROW(accountManager->sendInvitation(groupId, userId, nullptr));
490 // CancelInvitation Test
491 TEST(CancelInvitationTest, DISABLED_CancelInvitationForValid)
493 std::string host("coap://192.168.1.2:5000");
494 std::string groupId("AnyGroupId");
495 std::string userId("AnyUserId");
496 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
497 EXPECT_TRUE(NULL != accountManager);
498 EXPECT_EQ(OC_STACK_OK, accountManager->cancelInvitation(groupId, userId, &deleteHandler));
501 TEST(CancelInvitationTest, CancelInvitationWithNullCallback)
503 std::string host("coap://192.168.1.2:5000");
504 std::string groupId("AnyGroupId");
505 std::string userId("AnyUserId");
506 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
507 EXPECT_TRUE(NULL != accountManager);
508 EXPECT_ANY_THROW(accountManager->cancelInvitation(groupId, userId, nullptr));
511 // DeleteInvitation Test
512 TEST(DeleteInvitationTest, DISABLED_DeleteInvitationForValid)
514 std::string host("coap://192.168.1.2:5000");
515 std::string groupId("AnyGroupId");
516 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
517 EXPECT_TRUE(NULL != accountManager);
518 EXPECT_EQ(OC_STACK_OK, accountManager->deleteInvitation(groupId, &deleteHandler));
521 TEST(DeleteInvitationTest, DeleteInvitationWithNullCallback)
523 std::string host("coap://192.168.1.2:5000");
524 std::string groupId("AnyGroupId");
525 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
526 EXPECT_TRUE(NULL != accountManager);
527 EXPECT_ANY_THROW(accountManager->deleteInvitation(groupId, nullptr));