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 std::string accessToken("AnyAccessToken");
136 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
137 EXPECT_TRUE(NULL != accountManager);
138 EXPECT_EQ(OC_STACK_OK, accountManager->signOut(accessToken, &accountHandler));
141 TEST(SignOutTest, SignOutWithNullCallback)
143 std::string host("coap://192.168.1.2:5000");
144 std::string accessToken("AnyAccessToken");
145 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
146 EXPECT_TRUE(NULL != accountManager);
147 EXPECT_ANY_THROW(accountManager->signOut(accessToken, nullptr));
150 // RefreshAccessToken Test
151 TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenForValid)
153 std::string host("coap://192.168.1.2:5000");
154 std::string userId("AnyUserId");
155 std::string refreshToken("AnyRefreshToken");
156 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
157 EXPECT_TRUE(NULL != accountManager);
158 EXPECT_EQ(OC_STACK_OK, accountManager->refreshAccessToken(userId, refreshToken,
162 TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
164 std::string host("coap://192.168.1.2:5000");
165 std::string userId("AnyUserId");
166 std::string refreshToken("AnyRefreshToken");
167 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
168 EXPECT_TRUE(NULL != accountManager);
169 EXPECT_ANY_THROW(accountManager->refreshAccessToken(userId, refreshToken, nullptr));
173 TEST(SearchUserTest, DISABLED_SearchUserForValid)
175 std::string host("coap://192.168.1.2:5000");
176 std::string key("AnyKey");
177 std::string value("AnyValue");
178 QueryParamsMap query = {};
179 query.insert(std::pair<std::string, std::string>(key, value));
180 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
181 EXPECT_TRUE(NULL != accountManager);
182 EXPECT_EQ(OC_STACK_OK, accountManager->searchUser(query, &accountHandler));
185 TEST(SearchUserTest, SearchUserWithNullCallback)
187 std::string host("coap://192.168.1.2:5000");
188 std::string key("AnyKey");
189 std::string value("AnyValue");
190 QueryParamsMap query = {};
191 query.insert(std::pair<std::string, std::string>(key, value));
192 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
193 EXPECT_TRUE(NULL != accountManager);
194 EXPECT_ANY_THROW(accountManager->searchUser(query, nullptr));
198 TEST(DeleteDeviceTest, DISABLED_DeleteDeviceForValid)
200 std::string host("coap://192.168.1.2:5000");
201 std::string accessToken("AnyAccessToken");
202 std::string deviceId("AnyDeviceId");
203 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
204 EXPECT_TRUE(NULL != accountManager);
205 EXPECT_EQ(OC_STACK_OK, accountManager->deleteDevice(accessToken, deviceId,
209 TEST(DeleteDeviceTest, DeleteDeviceWithNullCallback)
211 std::string host("coap://192.168.1.2:5000");
212 std::string accessToken("AnyAccessToken");
213 std::string deviceId("AnyDeviceId");
214 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
215 EXPECT_TRUE(NULL != accountManager);
216 EXPECT_ANY_THROW(accountManager->deleteDevice(accessToken, deviceId, nullptr));
220 TEST(CreateGroupTest, DISABLED_CreateGroupForValid)
222 std::string host("coap://192.168.1.2:5000");
223 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
224 EXPECT_TRUE(NULL != accountManager);
225 EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(&accountHandler));
228 TEST(CreateGroupTest, DISABLED_CreateGroupWithOptionForValid)
230 std::string host("coap://192.168.1.2:5000");
231 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
232 EXPECT_TRUE(NULL != accountManager);
233 std::string property("AnyProperty");
234 std::string value("AnyValue");
235 QueryParamsMap query = {};
236 query.insert(std::pair<std::string, std::string>(property, value));
237 EXPECT_EQ(OC_STACK_OK, accountManager->createGroup(query, &accountHandler));
240 TEST(CreateGroupTest, CreateGroupWithNullCallback)
242 std::string host("coap://192.168.1.2:5000");
243 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
244 EXPECT_TRUE(NULL != accountManager);
245 EXPECT_ANY_THROW(accountManager->createGroup(nullptr));
249 TEST(DeleteGroupTest, DISABLED_DeleteGroupForValid)
251 std::string host("coap://192.168.1.2:5000");
252 std::string groupId("AnyGroupId");
253 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
254 EXPECT_TRUE(NULL != accountManager);
255 EXPECT_EQ(OC_STACK_OK, accountManager->deleteGroup(groupId, &deleteHandler));
258 TEST(DeleteGroupTest, DeleteGroupWithNullCallback)
260 std::string host("coap://192.168.1.2:5000");
261 std::string groupId("AnyGroupId");
262 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
263 EXPECT_TRUE(NULL != accountManager);
264 EXPECT_ANY_THROW(accountManager->deleteGroup(groupId, nullptr));
267 // GetGroupInfoAll Test
268 TEST(GetGroupInfoAllTest, DISABLED_GetGroupInfoAllForValid)
270 std::string host("coap://192.168.1.2:5000");
271 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
272 EXPECT_TRUE(NULL != accountManager);
273 EXPECT_EQ(OC_STACK_OK, accountManager->getGroupInfoAll(&accountHandler));
276 TEST(GetGroupInfoAllTest, GetGroupInfoAllWithNullCallback)
278 std::string host("coap://192.168.1.2:5000");
279 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
280 EXPECT_TRUE(NULL != accountManager);
281 EXPECT_ANY_THROW(accountManager->getGroupInfoAll(nullptr));
285 TEST(GetGroupInfoTest, DISABLED_GetGroupInfoForValid)
287 std::string host("coap://192.168.1.2:5000");
288 std::string groupId("AnyGroupId");
289 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
290 EXPECT_TRUE(NULL != accountManager);
291 EXPECT_EQ(OC_STACK_OK, accountManager->getGroupInfo(groupId, &accountHandler));
294 TEST(GetGroupInfoTest, GetGroupInfoWithNullCallback)
296 std::string host("coap://192.168.1.2:5000");
297 std::string groupId("AnyGroupId");
298 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
299 EXPECT_TRUE(NULL != accountManager);
300 EXPECT_ANY_THROW(accountManager->getGroupInfo(groupId, nullptr));
303 // AddPropertyValueToGroup Test
304 TEST(AddPropertyValueToGroupTest, DISABLED_AddPropertyValueToGroupForValid)
306 std::string host("coap://192.168.1.2:5000");
307 std::string groupId("AnyGroupId");
308 OCRepresentation propertyValue;
309 propertyValue.setValue("AnyProperty", "AnyValue");
310 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
311 EXPECT_TRUE(NULL != accountManager);
312 EXPECT_EQ(OC_STACK_OK, accountManager->addPropertyValueToGroup(groupId, propertyValue,
316 TEST(AddPropertyValueToGroupTest, AddPropertyValueToGroupWithNullCallback)
318 std::string host("coap://192.168.1.2:5000");
319 std::string groupId("AnyGroupId");
320 OCRepresentation propertyValue;
321 propertyValue.setValue("AnyProperty", "AnyValue");
322 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
323 EXPECT_TRUE(NULL != accountManager);
324 EXPECT_ANY_THROW(accountManager->addPropertyValueToGroup(groupId, propertyValue,
328 // DeletePropertyValueFromGroup Test
329 TEST(DeletePropertyValueFromGroupTest, DISABLED_DeletePropertyValueFromGroupForValid)
331 std::string host("coap://192.168.1.2:5000");
332 std::string groupId("AnyGroupId");
333 OCRepresentation propertyValue;
334 propertyValue.setValue("AnyProperty", "AnyValue");
335 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
336 EXPECT_TRUE(NULL != accountManager);
337 EXPECT_EQ(OC_STACK_OK, accountManager->deletePropertyValueFromGroup(groupId, propertyValue,
341 TEST(DeletePropertyValueFromGroupTest, DeletePropertyValueFromGroupWithNullCallback)
343 std::string host("coap://192.168.1.2:5000");
344 std::string groupId("AnyGroupId");
345 OCRepresentation propertyValue;
346 propertyValue.setValue("AnyProperty", "AnyValue");
347 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
348 EXPECT_TRUE(NULL != accountManager);
349 EXPECT_ANY_THROW(accountManager->deletePropertyValueFromGroup(groupId, propertyValue,
353 // UpdatePropertyValueOnGroup Test
354 TEST(UpdatePropertyValueOnGroupTest, DISABLED_UpdatePropertyValueOnGroupForValid)
356 std::string host("coap://192.168.1.2:5000");
357 std::string groupId("AnyGroupId");
358 OCRepresentation propertyValue;
359 propertyValue.setValue("AnyProperty", "AnyValue");
360 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
361 EXPECT_TRUE(NULL != accountManager);
362 EXPECT_EQ(OC_STACK_OK, accountManager->updatePropertyValueOnGroup(groupId, propertyValue,
366 TEST(UpdatePropertyValueOnGroupTest, UpdatePropertyValueOnGroupWithNullCallback)
368 std::string host("coap://192.168.1.2:5000");
369 std::string groupId("AnyGroupId");
370 OCRepresentation propertyValue;
371 propertyValue.setValue("AnyProperty", "AnyValue");
372 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
373 EXPECT_TRUE(NULL != accountManager);
374 EXPECT_ANY_THROW(accountManager->updatePropertyValueOnGroup(groupId, propertyValue,
379 TEST(ObserveGroupTest, DISABLED_ObserveGroupForValid)
381 std::string host("coap://192.168.1.2:5000");
382 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
383 EXPECT_TRUE(NULL != accountManager);
384 EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(&onObserve));
387 TEST(ObserveGroupTest, ObserveGroupWithNullCallback)
389 std::string host("coap://192.168.1.2:5000");
390 std::string groupId("AnyGroupId");
391 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
392 EXPECT_TRUE(NULL != accountManager);
393 EXPECT_ANY_THROW(accountManager->observeGroup(nullptr));
396 // CancelObserveGroup Test
397 TEST(CancelObserveGroupTest, DISABLED_CancelObserveGroupForValid)
399 std::string host("coap://192.168.1.2:5000");
400 std::string groupId("AnyGroupId");
401 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
402 EXPECT_TRUE(NULL != accountManager);
403 EXPECT_EQ(OC_STACK_OK, accountManager->observeGroup(&onObserve));
404 EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveGroup());
407 TEST(CancelObserveGroupTest, CancelObserveGroupWithoutObserve)
409 std::string host("coap://192.168.1.2:5000");
410 std::string groupId("AnyGroupId");
411 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
412 EXPECT_TRUE(NULL != accountManager);
413 EXPECT_ANY_THROW(accountManager->cancelObserveGroup());
416 // ObserveInvitation Test
417 TEST(ObserveInvitationTest, DISABLED_ObserveInvitationForValid)
419 std::string host("coap://192.168.1.2:5000");
420 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
421 EXPECT_TRUE(NULL != accountManager);
422 EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve));
425 TEST(ObserveInvitationTest, ObserveInvitationWithNullCallback)
427 std::string host("coap://192.168.1.2:5000");
428 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
429 EXPECT_TRUE(NULL != accountManager);
430 EXPECT_ANY_THROW(accountManager->observeInvitation(nullptr));
433 // CancelObserveInvitation Test
434 TEST(CancelObserveInvitationTest, DISABLED_CancelObserveInvitationForValid)
436 std::string host("coap://192.168.1.2:5000");
437 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
438 EXPECT_TRUE(NULL != accountManager);
439 EXPECT_EQ(OC_STACK_OK, accountManager->observeInvitation(&onObserve));
440 EXPECT_EQ(OC_STACK_OK, accountManager->cancelObserveInvitation());
443 TEST(CancelObserveInvitationTest, CancelObserveInvitationWithoutObserve)
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->cancelObserveInvitation());
451 // SendInvitation Test
452 TEST(SendInvitationTest, DISABLED_SendInvitationForValid)
454 std::string host("coap://192.168.1.2:5000");
455 std::string groupId("AnyGroupId");
456 std::string userId("AnyUserId");
457 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
458 EXPECT_TRUE(NULL != accountManager);
459 EXPECT_EQ(OC_STACK_OK, accountManager->sendInvitation(groupId, userId, &accountHandler));
462 TEST(SendInvitationTest, SendInvitationWithNullCallback)
464 std::string host("coap://192.168.1.2:5000");
465 std::string groupId("AnyGroupId");
466 std::string userId("AnyUserId");
467 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
468 EXPECT_TRUE(NULL != accountManager);
469 EXPECT_ANY_THROW(accountManager->sendInvitation(groupId, userId, nullptr));
472 // CancelInvitation Test
473 TEST(CancelInvitationTest, DISABLED_CancelInvitationForValid)
475 std::string host("coap://192.168.1.2:5000");
476 std::string groupId("AnyGroupId");
477 std::string userId("AnyUserId");
478 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
479 EXPECT_TRUE(NULL != accountManager);
480 EXPECT_EQ(OC_STACK_OK, accountManager->cancelInvitation(groupId, userId, &deleteHandler));
483 TEST(CancelInvitationTest, CancelInvitationWithNullCallback)
485 std::string host("coap://192.168.1.2:5000");
486 std::string groupId("AnyGroupId");
487 std::string userId("AnyUserId");
488 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
489 EXPECT_TRUE(NULL != accountManager);
490 EXPECT_ANY_THROW(accountManager->cancelInvitation(groupId, userId, nullptr));
493 // ReplyToInvitation Test
494 TEST(ReplyToInvitationTest, DISABLED_ReplyToInvitationForValid)
496 std::string host("coap://192.168.1.2:5000");
497 std::string groupId("AnyGroupId");
498 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
499 EXPECT_TRUE(NULL != accountManager);
500 EXPECT_EQ(OC_STACK_OK, accountManager->replyToInvitation(groupId, true, &deleteHandler));
503 TEST(ReplyToInvitationTest, ReplyToInvitationWithNullCallback)
505 std::string host("coap://192.168.1.2:5000");
506 std::string groupId("AnyGroupId");
507 OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
508 EXPECT_TRUE(NULL != accountManager);
509 EXPECT_ANY_THROW(accountManager->replyToInvitation(groupId, true, nullptr));