Update Snapshot(2018-12-12)
[platform/upstream/iotivity.git] / resource / unittests / OCAccountManagerTest.cpp
1 /* ****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #include <OCPlatform.h>
22 #include <OCApi.h>
23 #include <gtest/gtest.h>
24
25 namespace OCAccountManagerTest
26 {
27     using namespace OC;
28
29     // Callbacks
30     void accountHandler(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
31             const int /*eCode*/)
32     {
33     }
34
35     void deleteHandler(const HeaderOptions& /*headerOptions*/, const int /*eCode*/)
36     {
37     }
38
39     void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& /*rep*/,
40                         const int& /*eCode*/, const int& /*sequenceNumber*/)
41     {
42     }
43
44     // Helper method
45     OCAccountManager::Ptr ConstructAccountManagerObject(std::string host)
46     {
47         auto ret = OCPlatform::constructAccountManagerObject(host, CT_DEFAULT);
48
49         if (!ret)
50         {
51             ADD_FAILURE() << "ConstructAccountManagerObject result was null";
52             throw std::runtime_error("ConstructAccountManagerObject result was null");
53         }
54
55         return ret;
56     }
57
58     // Host Test
59     TEST(HostTest, Host)
60     {
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);
65     }
66
67     // ConnectivityType Test
68     TEST(ConnectivityTypeTest, ConnectivityType)
69     {
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);
74     }
75
76     // SignUp Test
77     TEST(SignUpTest, DISABLED_SignUpWithoutOptionForValid)
78     {
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));
85     }
86
87     TEST(SignUpTest, DISABLED_SignUpForValid)
88     {
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,
97                                                       &accountHandler));
98     }
99
100     TEST(SignUpTest, SignUpWithNullCallback)
101     {
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));
108     }
109
110     // SignIn Test
111     TEST(SignInTest, DISABLED_SignInForValid)
112     {
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));
119     }
120
121     TEST(SignInTest, SignInWithNullCallback)
122     {
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));
129     }
130
131     // SignOut Test
132     TEST(SignOutTest, DISABLED_SignOutForValid)
133     {
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));
139     }
140
141     TEST(SignOutTest, SignOutWithNullCallback)
142     {
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));
148     }
149
150     // RefreshAccessToken Test
151     TEST(RefreshAccessTokenTest, DISABLED_RefreshAccessTokenForValid)
152     {
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,
159                                                                   &accountHandler));
160     }
161
162     TEST(RefreshAccessTokenTest, RefreshAccessTokenWithNullCallback)
163     {
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));
170     }
171
172     // SearchUser Test
173     TEST(SearchUserTest, DISABLED_SearchUserForValid)
174     {
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));
183     }
184
185     TEST(SearchUserTest, SearchUserWithNullCallback)
186     {
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));
195     }
196
197     // DeleteDevice Test
198     TEST(DeleteDeviceTest, DISABLED_DeleteDeviceForValid)
199     {
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,
206                                                             &deleteHandler));
207     }
208
209     TEST(DeleteDeviceTest, DeleteDeviceWithNullCallback)
210     {
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));
217     }
218
219     // CreateGroup Test
220     TEST(CreateGroupTest, DISABLED_CreateGroupForValid)
221     {
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));
226     }
227
228     TEST(CreateGroupTest, DISABLED_CreateGroupWithOptionForValid)
229     {
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));
238     }
239
240     TEST(CreateGroupTest, CreateGroupWithNullCallback)
241     {
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));
246     }
247
248     // DeleteGroup Test
249     TEST(DeleteGroupTest, DISABLED_DeleteGroupForValid)
250     {
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));
256     }
257
258     TEST(DeleteGroupTest, DeleteGroupWithNullCallback)
259     {
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));
265     }
266
267     // GetGroupInfoAll Test
268     TEST(GetGroupInfoAllTest, DISABLED_GetGroupInfoAllForValid)
269     {
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));
274     }
275
276     TEST(GetGroupInfoAllTest, GetGroupInfoAllWithNullCallback)
277     {
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));
282     }
283
284     // GetGroupInfo Test
285     TEST(GetGroupInfoTest, DISABLED_GetGroupInfoForValid)
286     {
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));
292     }
293
294     TEST(GetGroupInfoTest, GetGroupInfoWithNullCallback)
295     {
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));
301     }
302
303     // AddPropertyValueToGroup Test
304     TEST(AddPropertyValueToGroupTest, DISABLED_AddPropertyValueToGroupForValid)
305     {
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,
313                                                                        &accountHandler));
314     }
315
316     TEST(AddPropertyValueToGroupTest, AddPropertyValueToGroupWithNullCallback)
317     {
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,
325                                                                  nullptr));
326     }
327
328     // DeletePropertyValueFromGroup Test
329     TEST(DeletePropertyValueFromGroupTest, DISABLED_DeletePropertyValueFromGroupForValid)
330     {
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,
338                                                                             &accountHandler));
339     }
340
341     TEST(DeletePropertyValueFromGroupTest, DeletePropertyValueFromGroupWithNullCallback)
342     {
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,
350                                                                       nullptr));
351     }
352
353     // UpdatePropertyValueOnGroup Test
354     TEST(UpdatePropertyValueOnGroupTest, DISABLED_UpdatePropertyValueOnGroupForValid)
355     {
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,
363                                                                        &accountHandler));
364     }
365
366     TEST(UpdatePropertyValueOnGroupTest, UpdatePropertyValueOnGroupWithNullCallback)
367     {
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,
375                                                                  nullptr));
376     }
377
378     // ObserveGroup Test
379     TEST(ObserveGroupTest, DISABLED_ObserveGroupForValid)
380     {
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));
385     }
386
387     TEST(ObserveGroupTest, ObserveGroupWithNullCallback)
388     {
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));
394     }
395
396     // CancelObserveGroup Test
397     TEST(CancelObserveGroupTest, DISABLED_CancelObserveGroupForValid)
398     {
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());
405     }
406
407     TEST(CancelObserveGroupTest, CancelObserveGroupWithoutObserve)
408     {
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());
414     }
415
416     // ObserveInvitation Test
417     TEST(ObserveInvitationTest, DISABLED_ObserveInvitationForValid)
418     {
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));
423     }
424
425     TEST(ObserveInvitationTest, ObserveInvitationWithNullCallback)
426     {
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));
431     }
432
433     // CancelObserveInvitation Test
434     TEST(CancelObserveInvitationTest, DISABLED_CancelObserveInvitationForValid)
435     {
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());
441     }
442
443     TEST(CancelObserveInvitationTest, CancelObserveInvitationWithoutObserve)
444     {
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());
449     }
450
451     // SendInvitation Test
452     TEST(SendInvitationTest, DISABLED_SendInvitationForValid)
453     {
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));
460     }
461
462     TEST(SendInvitationTest, SendInvitationWithNullCallback)
463     {
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));
470     }
471
472     // CancelInvitation Test
473     TEST(CancelInvitationTest, DISABLED_CancelInvitationForValid)
474     {
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));
481     }
482
483     TEST(CancelInvitationTest, CancelInvitationWithNullCallback)
484     {
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));
491     }
492
493     // ReplyToInvitation Test
494     TEST(ReplyToInvitationTest, DISABLED_ReplyToInvitationForValid)
495     {
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));
501     }
502
503     TEST(ReplyToInvitationTest, ReplyToInvitationWithNullCallback)
504     {
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));
510     }
511 }