1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 "UnitTestHelper.h"
22 #include "MaintenanceCollection.h"
23 #include "ConfigurationCollection.h"
24 #include "FactorySetCollection.h"
27 #include "ActionSet.h"
28 #include "GroupManager.h"
29 #include "ThingsConfiguration.h"
30 #include "ThingsMaintenance.h"
32 #include "OCPlatform.h"
38 #include <condition_variable>
40 #define SUCCESS_RESPONSE 0
41 constexpr int DEFAULT_WAITING_TIME_IN_MILLIS = 3000;
46 namespace PH = std::placeholders;
49 bool isSlowResponse = false;
51 std::string defaultDeviceName = "Legacy Device";
52 std::string defaultLocation = "37.256616, 127.052806";
53 std::string defaultLocationName = "Living Room";
54 std::string defaultRegion = "Won";
55 std::string defaultCurrency = "Seoul, Korea";
57 OCResourceHandle resourceHandle;
58 OCResourceHandle foundResourceHandle;
60 std::shared_ptr< OCResource > g_resource;
61 std::shared_ptr< OCResource > g_room_resource;
62 std::shared_ptr< OCResource > g_light;
63 std::shared_ptr< OCResource > configurationResource;
64 std::vector< string > lights;
65 std::vector< OCResourceHandle > resourceHandleVector;
67 GroupManager *groupMgr = new GroupManager();
68 ConfigurationResource *myConfigurationResource;
69 MaintenanceResource *myMaintenanceResource;
70 FactorySetResource *myFactorySetResource;
72 std::condition_variable cv1;
73 std::condition_variable cv2;
74 std::condition_variable cv3;
75 std::condition_variable cv4;
76 std::condition_variable cv5;
78 bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request);
79 OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest);
80 OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request);
81 OCEntityHandlerResult entityHandlerBootstrap(std::shared_ptr< OCResourceRequest > request);
83 typedef std::function< void(OCRepresentation &) > putFunc;
84 typedef std::function< OCRepresentation(void) > getFunc;
86 void *ChangeLightRepresentation(void *param);
87 void *handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest);
89 /****** Light Resource [Required to gtestcases of GroupManager APIs] ******/
96 std::string m_lightUri;
97 OCResourceHandle m_resourceHandle;
98 OCRepresentation m_lightRep;
102 m_power("on"), m_lightUri("/a/light"), m_resourceHandle(0)
104 m_lightRep.setUri(m_lightUri);
105 m_lightRep.setValue("power", m_power);
108 void createResource()
110 std::string resourceURI = m_lightUri;
111 std::string resourceTypeName = "core.light";
112 std::string resourceInterface = DEFAULT_INTERFACE;
113 EntityHandler cb = std::bind(&LightResource::entityHandler, this, PH::_1);
115 OCStackResult result = OCPlatform::registerResource(m_resourceHandle, resourceURI,
116 resourceTypeName, resourceInterface, cb, OC_DISCOVERABLE | OC_OBSERVABLE);
118 if (OC_STACK_OK != result)
120 printf("\nLightResource : OC_STACK_OK != result...");
126 std::condition_variable cv;
127 std::unique_lock < std::mutex > lock(blocker);
132 OCResourceHandle getHandle()
134 return m_resourceHandle;
137 void put(OCRepresentation &rep)
142 if (rep.getValue < std::string > ("power", test))
144 cout << "\t\t\t\t" << "power: " << test << endl;
148 cout << "\t\t\t\t" << "power not found in the representation" << endl;
153 cout << e.what() << endl;
157 OCRepresentation post(OCRepresentation &rep)
163 OCRepresentation get()
165 m_lightRep.setValue("power", m_power);
170 void addType(const std::string &type) const
172 OCStackResult result = OCPlatform::bindTypeToResource(m_resourceHandle, type);
173 if (OC_STACK_OK != result)
175 cout << "Binding TypeName to Resource was unsuccessful\n";
179 void addInterface(const std::string &interface) const
181 OCStackResult result = OCPlatform::bindInterfaceToResource(m_resourceHandle, interface);
182 if (OC_STACK_OK != result)
184 cout << "Binding TypeName to Resource was unsuccessful\n";
189 OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request)
191 cout << "\tIn Server CPP entity handler:\n";
192 OCEntityHandlerResult ehResult = OC_EH_ERROR;
195 std::string requestType = request->getRequestType();
196 int requestFlag = request->getRequestHandlerFlag();
198 if (requestFlag & RequestHandlerFlag::RequestFlag)
200 cout << "\t\trequestFlag : Request\n";
201 auto pResponse = std::make_shared< OC::OCResourceResponse >();
202 pResponse->setRequestHandle(request->getRequestHandle());
203 pResponse->setResourceHandle(request->getResourceHandle());
205 if (requestType == "GET")
207 cout << "\t\t\trequestType : GET\n";
210 static int startedThread = 0;
213 std::thread t(handleSlowResponse, (void *) this, request);
217 ehResult = OC_EH_SLOW;
221 pResponse->setErrorCode(200);
222 pResponse->setResponseResult(OC_EH_OK);
223 pResponse->setResourceRepresentation(get());
224 if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
230 else if (requestType == "PUT")
232 cout << "\t\t\trequestType : PUT\n";
233 OCRepresentation rep = request->getResourceRepresentation();
235 pResponse->setErrorCode(200);
236 pResponse->setResponseResult(OC_EH_OK);
237 pResponse->setResourceRepresentation(rep);
238 if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
243 else if (requestType == "POST")
245 cout << "\t\t\trequestType : POST\n";
247 OCRepresentation rep = request->getResourceRepresentation();
248 OCRepresentation rep_post = post(rep);
250 pResponse->setResourceRepresentation(rep_post);
251 pResponse->setErrorCode(200);
252 if (rep_post.hasAttribute("createduri"))
254 pResponse->setResponseResult(OC_EH_RESOURCE_CREATED);
255 pResponse->setNewResourceUri(
256 rep_post.getValue < std::string > ("createduri"));
259 if (OC_STACK_OK == OCPlatform::sendResponse(pResponse))
264 else if (requestType == "DELETE")
271 std::cout << "Request invalid" << std::endl;
277 void *handleSlowResponse(void *param, std::shared_ptr< OCResourceRequest > pRequest)
279 LightResource *lightPtr = (LightResource *) param;
282 auto pResponse = std::make_shared< OC::OCResourceResponse >();
283 pResponse->setRequestHandle(pRequest->getRequestHandle());
284 pResponse->setResourceHandle(pRequest->getResourceHandle());
285 pResponse->setResourceRepresentation(lightPtr->get());
286 pResponse->setErrorCode(200);
287 pResponse->setResponseResult(OC_EH_OK);
289 isSlowResponse = false;
290 OCPlatform::sendResponse(pResponse);
294 /****** Configuration Resource ******/
296 void ConfigurationResource::createResources(ResourceEntityHandler callback)
298 using namespace OC::OCPlatform;
300 if (callback == NULL)
302 std::cout << "callback should be binded\t";
306 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
307 m_configurationTypes[0], m_configurationInterfaces[0], callback,
308 OC_DISCOVERABLE | OC_OBSERVABLE);
310 if (OC_STACK_OK != result)
312 std::cout << "Resource creation (configuration) was unsuccessful\n";
318 std::condition_variable cv;
319 std::unique_lock < std::mutex > lock(blocker);
324 void ConfigurationResource::setConfigurationRepresentation(OCRepresentation &rep)
327 if (rep.getValue("n", value))
329 m_deviceName = value;
330 std::cout << "\t\t\t\t" << "m_deviceName: " << m_deviceName << std::endl;
333 if (rep.getValue("loc", value))
336 std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl;
339 if (rep.getValue("locn", value))
341 m_locationName = value;
342 std::cout << "\t\t\t\t" << "m_locationName: " << m_locationName << std::endl;
345 if (rep.getValue("c", value))
348 std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl;
351 if (rep.getValue("r", value))
354 std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl;
358 OCRepresentation ConfigurationResource::getConfigurationRepresentation()
360 m_configurationRep.setValue("n", m_deviceName);
361 m_configurationRep.setValue("loc", m_location);
362 m_configurationRep.setValue("locn", m_locationName);
363 m_configurationRep.setValue("c", m_currency);
364 m_configurationRep.setValue("r", m_region);
366 return m_configurationRep;
369 std::string ConfigurationResource::getUri()
371 return m_configurationUri;
374 void ConfigurationResource::factoryReset()
376 m_deviceName = defaultDeviceName;
377 m_location = defaultLocation;
378 m_locationName = defaultLocationName;
379 m_currency = defaultCurrency;
380 m_region = defaultRegion;
383 /****** FactorySet Resource ******/
385 FactorySetResource::FactorySetResource()
387 m_configurationUri = "/factoryset"; // URI of the resource
388 m_configurationTypes.clear();
389 m_configurationTypes.push_back("factoryset"); // resource type name.
390 m_configurationRep.setUri(m_configurationUri);
391 m_configurationRep.setResourceTypes(m_configurationTypes);
394 FactorySetResource::~FactorySetResource()
398 void FactorySetResource::createResources(ResourceEntityHandler callback)
400 using namespace OC::OCPlatform;
402 if (callback == NULL)
404 std::cout << "callback should be binded\t";
408 OCStackResult result = registerResource(m_configurationHandle, m_configurationUri,
409 m_configurationTypes[0], m_configurationInterfaces[0], callback,
410 OC_DISCOVERABLE | OC_OBSERVABLE);
412 if (OC_STACK_OK != result)
414 std::cout << "Resource creation (configuration) was unsuccessful\n";
421 std::condition_variable cv;
422 std::unique_lock < std::mutex > lock(blocker);
427 void FactorySetResource::setFactorySetRepresentation(OCRepresentation &rep)
431 if (rep.getValue("n", value))
433 m_deviceName = value;
434 std::cout << "\t\t\t\t" << "m_deviceName: " << m_deviceName << std::endl;
437 if (rep.getValue("loc", value))
440 std::cout << "\t\t\t\t" << "m_location: " << m_location << std::endl;
443 if (rep.getValue("locn", value))
445 m_locationName = value;
446 std::cout << "\t\t\t\t" << "m_locationName: " << m_locationName << std::endl;
449 if (rep.getValue("c", value))
452 std::cout << "\t\t\t\t" << "m_currency: " << m_currency << std::endl;
455 if (rep.getValue("r", value))
458 std::cout << "\t\t\t\t" << "m_region: " << m_region << std::endl;
462 OCRepresentation FactorySetResource::getFactorySetRepresentation()
464 m_configurationRep.setValue("n", m_deviceName);
465 m_configurationRep.setValue("loc", m_location);
466 m_configurationRep.setValue("locn", m_locationName);
467 m_configurationRep.setValue("c", m_currency);
468 m_configurationRep.setValue("r", m_region);
470 return m_configurationRep;
473 std::string FactorySetResource::getUri()
475 return m_configurationUri;
478 /****** Maintenance Resource ********/
480 void MaintenanceResource::createResources(ResourceEntityHandler callback)
482 using namespace OC::OCPlatform;
484 if (callback == NULL)
486 std::cout << "callback should be binded\t";
490 OCStackResult result = registerResource(m_maintenanceHandle, m_maintenanceUri,
491 m_maintenanceTypes[0], m_maintenanceInterfaces[0], callback,
492 OC_DISCOVERABLE | OC_OBSERVABLE);
494 if (OC_STACK_OK != result)
496 std::cout << "Resource creation (maintenance) was unsuccessful\n";
500 std::function< void(int second) >(
501 std::bind(&MaintenanceResource::maintenanceMonitor, this,
502 std::placeholders::_1)), 10);
506 std::condition_variable cv;
507 std::unique_lock < std::mutex > lock(blocker);
510 std::cout << "maintenance Resource is Created!\n";
513 void MaintenanceResource::setMaintenanceRepresentation(OCRepresentation &rep)
517 if (rep.getValue("fr", value))
519 m_factoryReset = value;
520 std::cout << "\t\t\t\t" << "m_factoryReset: " << m_factoryReset << std::endl;
523 if (rep.getValue("rb", value))
526 std::cout << "\t\t\t\t" << "m_reboot: " << m_reboot << std::endl;
529 if (rep.getValue("ssc", value))
531 m_startStatCollection = value;
532 std::cout << "\t\t\t\t" << "m_startStatCollection: " << m_startStatCollection << std::endl;
536 OCRepresentation MaintenanceResource::getMaintenanceRepresentation()
538 m_maintenanceRep.setValue("fr", m_factoryReset);
539 m_maintenanceRep.setValue("rb", m_reboot);
540 m_maintenanceRep.setValue("ssc", m_startStatCollection);
542 return m_maintenanceRep;
545 std::string MaintenanceResource::getUri()
547 return m_maintenanceUri;
550 void MaintenanceResource::maintenanceMonitor(int second)
556 if (m_reboot == "true")
559 std::cout << "Reboot will be soon..." << std::endl;
560 m_reboot = defaultReboot;
561 res = system("/usr/bin/sudo /etc/init.d/reboot");
563 std::cout << "return: " << res << std::endl;
566 else if (m_factoryReset == "true")
568 std::cout << "Factory Reset will be soon..." << std::endl;
569 m_factoryReset = defaultFactoryReset;
575 getFunc getGetFunction(std::string uri)
579 if (uri == myConfigurationResource->getUri())
581 res = std::bind(&ConfigurationResource::getConfigurationRepresentation,
582 myConfigurationResource);
584 else if (uri == myMaintenanceResource->getUri())
586 res = std::bind(&MaintenanceResource::getMaintenanceRepresentation, myMaintenanceResource);
591 putFunc getPutFunction(std::string uri)
595 if (uri == myConfigurationResource->getUri())
597 res = std::bind(&ConfigurationResource::setConfigurationRepresentation,
598 myConfigurationResource, std::placeholders::_1);
600 else if (uri == myMaintenanceResource->getUri())
602 res = std::bind(&MaintenanceResource::setMaintenanceRepresentation, myMaintenanceResource,
603 std::placeholders::_1);
608 bool prepareResponseForResource(std::shared_ptr< OCResourceRequest > request)
610 std::cout << "\tIn Server CPP prepareResponseForResource:\n";
614 std::string requestType = request->getRequestType();
615 int requestFlag = request->getRequestHandlerFlag();
617 if (requestFlag == RequestHandlerFlag::RequestFlag)
619 std::cout << "\t\trequestFlag : Request\n";
620 if (requestType == "GET")
622 std::cout << "\t\t\trequestType : GET\n";
625 else if (requestType == "PUT")
627 std::cout << "\t\t\trequestType : PUT\n";
629 OCRepresentation rep = request->getResourceRepresentation();
631 putFunction = getPutFunction(request->getResourceUri());
635 else if (requestType == "POST")
638 else if (requestType == "DELETE")
642 else if (requestFlag == RequestHandlerFlag::ObserverFlag)
644 std::cout << "\t\trequestFlag : Observer\n";
649 std::cout << "Request invalid" << std::endl;
655 OCStackResult sendResponseForResource(std::shared_ptr< OCResourceRequest > pRequest)
657 auto pResponse = std::make_shared< OC::OCResourceResponse >();
658 QueryParamsMap queryParamsMap = pRequest->getQueryParameters();
660 pResponse->setRequestHandle(pRequest->getRequestHandle());
661 pResponse->setResourceHandle(pRequest->getResourceHandle());
664 getFunction = getGetFunction(pRequest->getResourceUri());
666 OCRepresentation rep;
669 auto findRes = queryParamsMap.find("if");
671 if (findRes != queryParamsMap.end())
673 pResponse->setResourceRepresentation(rep, findRes->second);
677 pResponse->setResourceRepresentation(rep, DEFAULT_INTERFACE);
680 pResponse->setErrorCode(200);
681 pResponse->setResponseResult(OC_EH_OK);
683 return OCPlatform::sendResponse(pResponse);
686 OCEntityHandlerResult entityHandlerForResource(std::shared_ptr< OCResourceRequest > request)
688 std::cout << "\tIn Server CPP (entityHandlerForResource) entity handler:\n";
689 OCEntityHandlerResult ehResult = OC_EH_ERROR;
691 QueryParamsMap test = request->getQueryParameters();
693 if (prepareResponseForResource(request))
695 if (OC_STACK_OK == sendResponseForResource(request))
701 std::cout << "sendResponse failed." << std::endl;
706 std::cout << "PrepareResponse failed." << std::endl;
711 /****** BootStrap Resource [Required for doBootstrap API of ThingsConfiguration class] ******/
713 class BootstrapResource
716 std::string m_bootstrapUri;
717 std::vector< std::string > m_bootstrapTypes;
718 std::vector< std::string > m_bootstrapInterfaces;
719 OCResourceHandle m_bootstrapHandle;
720 OCRepresentation m_bootstrapRep;
725 m_bootstrapUri = "/bootstrap";
726 m_bootstrapTypes.push_back("bootstrap");
727 m_bootstrapInterfaces.push_back(DEFAULT_INTERFACE);
728 m_bootstrapRep.setUri(m_bootstrapUri);
729 m_bootstrapRep.setResourceTypes(m_bootstrapTypes);
730 m_bootstrapRep.setResourceInterfaces(m_bootstrapInterfaces);
731 m_bootstrapHandle = NULL;
733 void createResources()
735 using namespace OC::OCPlatform;
736 OCStackResult result = registerResource(m_bootstrapHandle, m_bootstrapUri,
737 m_bootstrapTypes[0], m_bootstrapInterfaces[0], entityHandlerBootstrap,
738 OC_DISCOVERABLE | OC_OBSERVABLE);
740 if (OC_STACK_OK != result)
742 cout << "Resource creation (room) was unsuccessful\n";
747 std::condition_variable cv;
748 std::unique_lock < std::mutex > lock(blocker);
752 void setBootstrapRepresentation(OCRepresentation& /*rep*/)
756 OCRepresentation getBootstrapRepresentation()
758 m_bootstrapRep.setValue < std::string > ("n", defaultDeviceName);
759 m_bootstrapRep.setValue < std::string > ("loc", defaultLocation);
760 m_bootstrapRep.setValue < std::string > ("locn", defaultLocationName);
761 m_bootstrapRep.setValue < std::string > ("c", defaultCurrency);
762 m_bootstrapRep.setValue < std::string > ("r", defaultRegion);
764 return m_bootstrapRep;
768 BootstrapResource myBootstrapResource;
770 bool prepareResponse(std::shared_ptr< OCResourceRequest > request)
772 cout << "\tIn Server CPP prepareResponse:\n";
776 std::string requestType = request->getRequestType();
777 int requestFlag = request->getRequestHandlerFlag();
779 if (requestFlag == RequestHandlerFlag::RequestFlag)
781 cout << "\t\trequestFlag : Request\n";
782 if (requestType == "GET")
784 cout << "\t\t\trequestType : GET\n";
787 else if (requestType == "PUT")
789 cout << "\t\t\trequestType : PUT\n";
791 OCRepresentation rep = request->getResourceRepresentation();
792 myBootstrapResource.setBootstrapRepresentation(rep);
795 else if (requestType == "POST")
798 else if (requestType == "DELETE")
802 else if (requestFlag == RequestHandlerFlag::ObserverFlag)
804 cout << "\t\trequestFlag : Observer\n";
809 std::cout << "Request invalid" << std::endl;
815 OCStackResult sendResponse(std::shared_ptr< OCResourceRequest > pRequest)
817 auto pResponse = std::make_shared< OC::OCResourceResponse >();
818 pResponse->setRequestHandle(pRequest->getRequestHandle());
819 pResponse->setResourceHandle(pRequest->getResourceHandle());
820 pResponse->setResourceRepresentation(myBootstrapResource.getBootstrapRepresentation());
821 pResponse->setErrorCode(200);
822 pResponse->setResponseResult(OC_EH_OK);
824 return OCPlatform::sendResponse(pResponse);
827 OCEntityHandlerResult entityHandlerBootstrap(std::shared_ptr< OCResourceRequest > request)
829 cout << "\tIn Server CPP (entityHandlerBootstrap) entity handler:\n";
830 OCEntityHandlerResult ehResult = OC_EH_ERROR;
832 if (prepareResponse(request))
834 if (OC_STACK_OK == sendResponse(request))
840 std::cout << "sendResponse failed." << std::endl;
845 std::cout << "PrepareResponse failed." << std::endl;
850 /****** gtest class ******/
852 class ThingsManagerTest: public TestWithMock
860 void Wait(int waitingTime = DEFAULT_WAITING_TIME_IN_MILLIS)
862 std::unique_lock < std::mutex > lock
864 cond.wait_for(lock, std::chrono::milliseconds
871 TestWithMock::SetUp();
876 TestWithMock::TearDown();
880 std::condition_variable cond;
885 void onUpdate(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
890 void onGetBootstrapInformation(const HeaderOptions& /*headerOptions*/,
891 const OCRepresentation& /*rep*/, const int /*eCode*/)
895 void onReboot(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
900 void onFactoryReset(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
905 void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
910 void onPut(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
915 void onPost(const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
920 void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
922 for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
924 if(((*rsrc)->connectivityType() & CT_ADAPTER_TCP) == CT_ADAPTER_TCP)
929 std::string resourceURI = (*rsrc)->uri();
930 std::string hostAddress = (*rsrc)->host();
932 if (resourceURI == "/a/light")
934 result = OCPlatform::registerResource(foundResourceHandle, (*rsrc));
935 if (result == OC_STACK_OK)
937 OCPlatform::bindResource(resourceHandle, foundResourceHandle);
938 resourceHandleVector.push_back(foundResourceHandle);
942 cout << "\tresource Error!" << endl;
944 lights.push_back((hostAddress + resourceURI));
950 configurationResource = (*rsrc);
956 void foundGroupResource(std::shared_ptr< OCResource > resource)
958 if((resource->connectivityType() & CT_ADAPTER_TCP) == CT_ADAPTER_TCP)
963 std::string resourceURI;
964 resourceURI = resource->uri();
965 if (resourceURI == "/core/a/collection")
967 g_resource = resource;
971 g_room_resource = resource;
976 //This test case is to create the lightserver , BootstrapServer & configuration sever
977 TEST_F(ThingsManagerTest, testCreateResources)
980 { OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos};
981 OCPlatform::Configure(cfg);
983 LightResource myLight;
984 std::thread t1(&LightResource::createResource, &myLight);
987 std::unique_lock < std::mutex > lock1(blocker1);
990 std::thread t2(&BootstrapResource::createResources, &myBootstrapResource);
993 std::unique_lock < std::mutex > lock2(blocker2);
996 myConfigurationResource = new ConfigurationResource();
997 std::thread t3(&ConfigurationResource::createResources, myConfigurationResource,
998 &entityHandlerForResource);
1001 std::mutex blocker3;
1002 std::unique_lock < std::mutex > lock3(blocker3);
1005 myMaintenanceResource = new MaintenanceResource();
1006 std::thread t4(&MaintenanceResource::createResources, myMaintenanceResource,
1007 &entityHandlerForResource);
1010 std::mutex blocker4;
1011 std::unique_lock < std::mutex > lock4(blocker4);
1014 myFactorySetResource = new FactorySetResource();
1015 std::thread t5(&FactorySetResource::createResources, myFactorySetResource,
1016 &entityHandlerForResource);
1019 std::mutex blocker5;
1020 std::unique_lock < std::mutex > lock5(blocker5);
1023 myMaintenanceResource->factoryReset = std::function < void()
1024 > (std::bind(&ConfigurationResource::factoryReset,
1025 myConfigurationResource));
1028 //Check findCandidateResources
1029 TEST_F(ThingsManagerTest, testFindCandidateResources)
1032 string resourceURI = "/core/a/collection";
1033 string resourceTypeName = "a.collection";
1034 string resourceInterface = BATCH_INTERFACE;
1036 OCStackResult res = OCPlatform::registerResource(resourceHandle, resourceURI,
1037 resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE);
1039 if ( res != OC_STACK_OK )
1041 cout << "Resource registeration failed." << endl;
1044 OCPlatform::bindInterfaceToResource(resourceHandle, GROUP_INTERFACE);
1045 OCPlatform::bindInterfaceToResource(resourceHandle, DEFAULT_INTERFACE);
1047 std::string query = OC_RSRVD_WELL_KNOWN_URI;
1048 query.append("?rt=");
1049 query.append(resourceTypeName);
1051 OCPlatform::findResource("", query, CT_DEFAULT, &foundGroupResource);
1053 std::mutex blocker1;
1054 std::unique_lock < std::mutex > lock1(blocker1);
1057 GroupManager *instance = new GroupManager();
1058 vector<string> types;
1059 types.push_back("core.light");
1061 result = instance->findCandidateResources(types, &foundResources);
1063 std::mutex blocker2;
1064 std::unique_lock < std::mutex > lock2(blocker2);
1068 //Find Candidate Resource when no resources are specified
1069 TEST_F(ThingsManagerTest, testFindCandidateResourcesEmptyResourceType)
1071 GroupManager *instance = new GroupManager();
1072 vector<string> types;
1073 result = instance->findCandidateResources(types, &foundResources);
1074 EXPECT_TRUE(result == OC_STACK_ERROR);
1078 //Find Candidate Resource when Callback is null
1079 TEST_F(ThingsManagerTest, testFindCandidateResourcesNullCallback)
1081 GroupManager *instance = new GroupManager();
1082 vector<string> types;
1083 types.push_back("core.light");
1084 result = instance->findCandidateResources(types, NULL);
1085 EXPECT_TRUE(result == OC_STACK_ERROR);
1089 //test bind resource to group
1090 TEST_F(ThingsManagerTest, testBindResourceToGroup)
1092 GroupManager *instance = new GroupManager();
1093 OCResourceHandle rHandle = NULL;
1095 string resourceURI = "/core/room-large";
1096 string resourceTypeName = "core.room-large";
1097 string resourceInterface = BATCH_INTERFACE;
1099 OCStackResult res = OCPlatform::registerResource(rHandle, resourceURI,
1100 resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE);
1102 if ( res != OC_STACK_OK )
1104 cout << "Resource registeration failed." << endl;
1107 OCPlatform::bindInterfaceToResource(rHandle, GROUP_INTERFACE);
1108 OCPlatform::bindInterfaceToResource(rHandle, DEFAULT_INTERFACE);
1110 std::string query = OC_RSRVD_WELL_KNOWN_URI;
1111 query.append("?rt=");
1112 query.append(resourceTypeName);
1114 OCPlatform::findResource("", query, CT_DEFAULT, &foundGroupResource);
1116 std::mutex blocker1;
1117 std::unique_lock < std::mutex > lock1(blocker1);
1120 result = instance->bindResourceToGroup (resourceHandle, g_room_resource, rHandle);
1122 EXPECT_TRUE(result == OC_STACK_OK);
1127 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOff)
1129 string actionsetDesc;
1130 ActionSet *allBulbOff = new ActionSet();
1131 allBulbOff->actionsetName = "AllBulbOff";
1133 mocks.ExpectCallFunc(onPut).
1134 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1135 const int /*eCode*/) { Proceed();});
1137 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1139 Action *action = new Action();
1140 action->target = (*iter);
1142 Capability *capa = new Capability();
1143 capa->capability = "power";
1144 capa->status = "off";
1146 action->listOfCapability.push_back(capa);
1147 allBulbOff->listOfAction.push_back(action);
1151 result = groupMgr->addActionSet(g_resource, allBulbOff, &onPut);
1153 EXPECT_TRUE(result == OC_STACK_OK);
1159 //Add actionset with NULL resource
1160 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOffResourceNull)
1162 string actionsetDesc;
1163 ActionSet *allBulbOff = new ActionSet();
1164 allBulbOff->actionsetName = "AllBulbOff";
1166 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1168 Action *action = new Action();
1169 action->target = (*iter);
1171 Capability *capa = new Capability();
1172 capa->capability = "power";
1173 capa->status = "off";
1175 action->listOfCapability.push_back(capa);
1176 allBulbOff->listOfAction.push_back(action);
1179 result = groupMgr->addActionSet(NULL, allBulbOff, &onPut);
1181 EXPECT_TRUE(result == OC_STACK_ERROR);
1187 //Add actionset with NULL ActionSet
1188 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOffActionsetNull)
1192 result = groupMgr->addActionSet(g_resource, NULL, &onPut);
1194 EXPECT_TRUE(result == OC_STACK_ERROR);
1200 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOn)
1202 string actionsetDesc;
1203 ActionSet *allBulbON = new ActionSet();
1204 allBulbON->actionsetName = "AllBulbOn";
1206 mocks.ExpectCallFunc(onPut).
1207 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1208 const int /*eCode*/) { Proceed();});
1210 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1212 Action *action = new Action();
1213 action->target = (*iter);
1215 Capability *capa = new Capability();
1216 capa->capability = "power";
1217 capa->status = "on";
1219 action->listOfCapability.push_back(capa);
1220 allBulbON->listOfAction.push_back(action);
1224 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1226 EXPECT_TRUE(result == OC_STACK_OK);
1232 //Add actionset with NULL Resource
1233 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOnResourceNull)
1235 string actionsetDesc;
1236 ActionSet *allBulbON = new ActionSet();
1237 allBulbON->actionsetName = "AllBulbOn";
1239 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1241 Action *action = new Action();
1242 action->target = (*iter);
1244 Capability *capa = new Capability();
1245 capa->capability = "power";
1246 capa->status = "on";
1248 action->listOfCapability.push_back(capa);
1249 allBulbON->listOfAction.push_back(action);
1252 result = groupMgr->addActionSet(NULL, allBulbON, onPut);
1254 EXPECT_TRUE(result == OC_STACK_ERROR);
1260 //Add actionset with NULL ActionSet
1261 TEST_F(ThingsManagerTest, testAddActionSetAllBulbOnActionSetNull)
1265 result = groupMgr->addActionSet(g_resource, NULL, onPut);
1267 EXPECT_TRUE(result == OC_STACK_ERROR);
1273 TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOn)
1275 string actionsetDesc;
1276 ActionSet *allBulbON = new ActionSet();
1277 allBulbON->actionsetName = "AllBulbOn1";
1279 mocks.ExpectCallFunc(onPut).
1280 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1281 const int /*eCode*/) { Proceed();});
1283 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1285 Action *action = new Action();
1286 action->target = (*iter);
1288 Capability *capa = new Capability();
1289 capa->capability = "power";
1290 capa->status = "on";
1292 action->listOfCapability.push_back(capa);
1293 allBulbON->listOfAction.push_back(action);
1297 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1299 EXPECT_TRUE(result == OC_STACK_OK);
1303 mocks.ExpectCallFunc(onPost).
1304 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1305 const int /*eCode*/) { Proceed();});
1309 result = groupMgr->executeActionSet(g_resource, "AllBulbOn", &onPost);
1311 EXPECT_TRUE(result == OC_STACK_OK);
1317 //Execute actionset with NULL Resource
1318 TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOnResourceNull)
1320 result = groupMgr->executeActionSet(NULL, "AllBulbOn", &onPost);
1322 EXPECT_TRUE(result == OC_STACK_ERROR);
1327 TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOff)
1329 mocks.ExpectCallFunc(onPost).
1330 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1331 const int /*eCode*/) { Proceed();});
1335 result = groupMgr->executeActionSet(g_resource, "AllBulbOff", &onPost);
1337 EXPECT_TRUE(result == OC_STACK_OK);
1342 //Execute actionset with NULL resource
1343 TEST_F(ThingsManagerTest, testExecuteActionSetAllBulbOffResourceNull)
1345 result = groupMgr->executeActionSet(NULL, "AllBulbOff", &onPost);
1347 EXPECT_TRUE(result == OC_STACK_ERROR);
1351 //Execute actionset with Delay
1352 TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelay)
1354 string actionsetDesc;
1355 ActionSet *allBulbON = new ActionSet();
1356 allBulbON->actionsetName = "AllBulbOnDelay";
1357 allBulbON->setDelay(1);
1359 mocks.ExpectCallFunc(onPut).
1360 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1361 const int /*eCode*/) { Proceed();});
1363 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1365 Action *action = new Action();
1366 action->target = (*iter);
1368 Capability *capa = new Capability();
1369 capa->capability = "power";
1370 capa->status = "off";
1372 action->listOfCapability.push_back(capa);
1373 allBulbON->listOfAction.push_back(action);
1377 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1381 mocks.ExpectCallFunc(onPost).
1382 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1383 const int /*eCode*/) { Proceed();});
1387 result = groupMgr->executeActionSet(g_resource, "AllBulbOnDelay", &onPost);
1389 EXPECT_TRUE(result == OC_STACK_OK);
1396 //Execute actionset with Delay = 0
1397 TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelayEqulasZero)
1399 string actionsetDesc;
1400 ActionSet *allBulbON = new ActionSet();
1401 allBulbON->actionsetName = "AllBulbOnDelay";
1403 mocks.ExpectCallFunc(onPut).
1404 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1405 const int /*eCode*/) { Proceed();});
1407 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1409 Action *action = new Action();
1410 action->target = (*iter);
1412 Capability *capa = new Capability();
1413 capa->capability = "power";
1414 capa->status = "off";
1416 action->listOfCapability.push_back(capa);
1417 allBulbON->listOfAction.push_back(action);
1421 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1427 result = groupMgr->executeActionSet(g_resource, "AllBulbOnDelay", 0, &onPost);
1429 EXPECT_TRUE(result == OC_STACK_INVALID_PARAM);
1436 //Execute actionset with invalid Delay
1437 TEST_F(ThingsManagerTest, testExcecuteActionSetWithInvalidDelay)
1439 string actionsetDesc;
1440 ActionSet *allBulbON = new ActionSet();
1441 allBulbON->actionsetName = "AllBulbOnDelay";
1443 mocks.ExpectCallFunc(onPut).
1444 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1445 const int /*eCode*/) { Proceed();});
1447 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1449 Action *action = new Action();
1450 action->target = (*iter);
1452 Capability *capa = new Capability();
1453 capa->capability = "power";
1454 capa->status = "off";
1456 action->listOfCapability.push_back(capa);
1457 allBulbON->listOfAction.push_back(action);
1461 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1467 result = groupMgr->executeActionSet(g_resource, "AllBulbOnDelay", -10, &onPost);
1469 EXPECT_TRUE(result == OC_STACK_INVALID_PARAM);
1476 //Execute actionset with delay on NULL Resource
1477 TEST_F(ThingsManagerTest, testExcecuteActionSetWithDelayWithResourceNull)
1479 string actionsetDesc;
1480 ActionSet *allBulbON = new ActionSet();
1481 allBulbON->actionsetName = "AllBulbOnDelay";
1482 allBulbON->setDelay(5);
1484 mocks.ExpectCallFunc(onPut).
1485 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1486 const int /*eCode*/) { Proceed();});
1488 for (auto iter = lights.begin(); iter != lights.end(); ++iter)
1490 Action *action = new Action();
1491 action->target = (*iter);
1493 Capability *capa = new Capability();
1494 capa->capability = "power";
1495 capa->status = "off";
1497 action->listOfCapability.push_back(capa);
1498 allBulbON->listOfAction.push_back(action);
1502 result = groupMgr->addActionSet(g_resource, allBulbON, onPut);
1505 result = groupMgr->executeActionSet(NULL, "AllBulbOnDelay", &onPost);
1506 EXPECT_TRUE(result == OC_STACK_ERROR);
1513 TEST_F(ThingsManagerTest, testCancelActionSet)
1515 mocks.ExpectCallFunc(onPost).
1516 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1517 const int /*eCode*/) { Proceed();});
1521 result = groupMgr->cancelActionSet(g_resource, "AllBulbOff", &onPost);
1523 EXPECT_TRUE(result == OC_STACK_OK);
1528 //Cancel ActionSet on NULL Resource
1529 TEST_F(ThingsManagerTest, testCancelActionSetResourceNull)
1531 result = groupMgr->cancelActionSet(NULL, "AllBulbOff", &onPost);
1533 EXPECT_TRUE(result == OC_STACK_ERROR);
1538 TEST_F(ThingsManagerTest, testDeleteActionSet)
1540 mocks.ExpectCallFunc(onPut).
1541 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1542 const int /*eCode*/) { Proceed();});
1546 result = groupMgr->deleteActionSet(g_resource, "AllBulbOff", &onPut);
1548 EXPECT_TRUE(result == OC_STACK_OK);
1553 //Delete ActionSet on NULL Resource
1554 TEST_F(ThingsManagerTest, testDeleteActionSetResourceNull)
1556 result = groupMgr->deleteActionSet(NULL, "AllBulbOff", &onPut);
1558 EXPECT_TRUE(result == OC_STACK_ERROR);
1563 TEST_F(ThingsManagerTest, testGetActionSet)
1565 mocks.ExpectCallFunc(onPost).
1566 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1567 const int /*eCode*/) { Proceed();});
1571 result = groupMgr->getActionSet(g_resource, "AllBulbOn", &onPost);
1573 EXPECT_TRUE(result == OC_STACK_OK);
1578 //Get ActionSet on NULL Resource
1579 TEST_F(ThingsManagerTest, testGetActionSetResourceNull)
1581 result = groupMgr->getActionSet(NULL, "AllBulbOn", &onPost);
1583 EXPECT_TRUE(result == OC_STACK_ERROR);
1587 //Get Configurations
1588 TEST_F(ThingsManagerTest, testGetConfigurations)
1590 ConfigurationName name = "all";
1592 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1593 std::vector< ConfigurationName > configurations;
1595 configurations.push_back(name);
1597 mocks.ExpectCallFunc(onGet).
1598 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1599 const int /*eCode*/) { Proceed();});
1601 vector<string> types;
1602 types.push_back("oic.wk.con");
1604 result = groupMgr->findCandidateResources(types, &foundResources);
1607 std::unique_lock < std::mutex > lock(blocker);
1610 if (result == OC_STACK_OK)
1612 result = g_thingsConf->getConfigurations(configurationResource, configurations, &onGet);
1614 EXPECT_TRUE(result == OC_STACK_OK);
1619 //Get Configurations with empty Configuration
1620 TEST_F(ThingsManagerTest, testGetConfigurationsEmptyConfiguration)
1622 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1623 std::vector< ConfigurationName > configurations;
1625 vector<string> types;
1626 types.push_back("oic.wk.con");
1628 result = groupMgr->findCandidateResources(types, &foundResources);
1631 std::unique_lock < std::mutex > lock(blocker);
1634 if (result == OC_STACK_OK)
1636 result = g_thingsConf->getConfigurations(configurationResource, configurations, &onGet);
1638 EXPECT_TRUE(result == OC_STACK_ERROR);
1643 //Get Configurations on NULL Resource
1644 TEST_F(ThingsManagerTest, testGetConfigurationsResourceNull)
1646 ConfigurationName name = "all";
1647 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1648 std::vector< ConfigurationName > configurations;
1650 configurations.push_back(name);
1652 result = g_thingsConf->getConfigurations(NULL, configurations, &onGet);
1654 EXPECT_TRUE(result == OC_STACK_ERROR);
1658 //Get all supported Configurations
1659 TEST_F(ThingsManagerTest, testGetallSupportedCOnfigurations)
1661 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1662 string retVal = g_thingsConf->getListOfSupportedConfigurationUnits();
1663 EXPECT_FALSE(retVal.size() == 0);
1667 TEST_F(ThingsManagerTest, testDoBootstrap)
1669 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1671 mocks.ExpectCallFunc(onGetBootstrapInformation).
1672 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1673 const int /*eCode*/) { Proceed();});
1674 result = g_thingsConf->doBootstrap(&onGetBootstrapInformation);
1676 EXPECT_TRUE(result == OC_STACK_OK);
1680 //DoBootstrap with NULL callback
1681 TEST_F(ThingsManagerTest, testDoBootstrapCallBackNull)
1683 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1685 result = g_thingsConf->doBootstrap(NULL);
1687 EXPECT_TRUE(result == OC_STACK_ERROR);
1691 //Update Configuration
1692 TEST_F(ThingsManagerTest, testUpdateConfiguration)
1694 ConfigurationName name = "r";
1695 ConfigurationValue value = "INDIA";
1697 std::map< ConfigurationName, ConfigurationValue > configurations;
1698 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1699 configurations.insert(std::make_pair(name, value));
1701 mocks.ExpectCallFunc(onUpdate).
1702 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1703 const int /*eCode*/) { Proceed();});
1705 vector<string> types;
1706 types.push_back("oic.wk.con");
1707 result = groupMgr->findCandidateResources(types, &foundResources);
1709 std::mutex blocker2;
1710 std::unique_lock < std::mutex > lock2(blocker2);
1713 if (result == OC_STACK_OK)
1715 result = g_thingsConf->updateConfigurations(configurationResource, configurations,
1718 EXPECT_TRUE(result == OC_STACK_OK);
1723 //Update Configuration with Empty Configuration
1724 TEST_F(ThingsManagerTest, testUpdateConfigurationEmptyConfiguration)
1726 std::map< ConfigurationName, ConfigurationValue > configurations;
1727 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1729 vector<string> types;
1730 types.push_back("oic.wk.con");
1731 result = groupMgr->findCandidateResources(types, &foundResources);
1733 std::mutex blocker2;
1734 std::unique_lock < std::mutex > lock2(blocker2);
1737 if (result == OC_STACK_OK)
1739 result = g_thingsConf->updateConfigurations(configurationResource, configurations,
1742 EXPECT_TRUE(result == OC_STACK_ERROR);
1747 //Update Configuration on NULL Resource
1748 TEST_F(ThingsManagerTest, testUpdateConfigurationResourceNull)
1750 ConfigurationName name = "r";
1751 ConfigurationValue value = "INDIA";
1753 std::map< ConfigurationName, ConfigurationValue > configurations;
1754 ThingsConfiguration *g_thingsConf = ThingsConfiguration::getInstance();
1756 configurations.insert(std::make_pair(name, value));
1758 result = g_thingsConf->updateConfigurations(NULL, configurations, &onUpdate);
1760 EXPECT_TRUE(result == OC_STACK_ERROR);
1765 TEST_F(ThingsManagerTest, testReboot)
1767 ThingsMaintenance *g_thingsMnt = ThingsMaintenance::getInstance();
1769 mocks.ExpectCallFunc(onReboot).
1770 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1771 const int /*eCode*/) { Proceed();});
1773 vector<string> types;
1774 types.push_back("oic.wk.mnt");
1775 result = groupMgr->findCandidateResources(types, &foundResources);
1778 std::unique_lock < std::mutex > lock(blocker);
1781 if (result == OC_STACK_OK)
1783 result = g_thingsMnt->reboot(configurationResource, &onReboot);
1785 EXPECT_TRUE(result == OC_STACK_OK);
1790 //Reboot on NULL Resource
1791 TEST_F(ThingsManagerTest, testRebootResourceNull)
1793 ThingsMaintenance *g_thingsMnt = ThingsMaintenance::getInstance();
1795 result = g_thingsMnt->reboot(NULL, &onReboot);
1797 EXPECT_TRUE(result == OC_STACK_ERROR);
1802 TEST_F(ThingsManagerTest, testFactoryReset)
1804 ThingsMaintenance *g_thingsMnt = ThingsMaintenance::getInstance();
1806 mocks.ExpectCallFunc(onFactoryReset).
1807 Do([this](const HeaderOptions& /*headerOptions*/, const OCRepresentation& /*rep*/,
1808 const int /*eCode*/) { Proceed();});
1810 vector<string> types;
1811 types.push_back("oic.wk.mnt");
1812 result = groupMgr->findCandidateResources(types, &foundResources);
1815 std::unique_lock < std::mutex > lock(blocker);
1818 if (result == OC_STACK_OK)
1820 result = g_thingsMnt->factoryReset(configurationResource, &onFactoryReset);
1822 EXPECT_TRUE(result == OC_STACK_OK);
1827 //Factory Reset on NULL Resource
1828 TEST_F(ThingsManagerTest, testFactoryResetResourceNull)
1830 ThingsMaintenance *g_thingsMnt = ThingsMaintenance::getInstance();
1832 result = g_thingsMnt->factoryReset(NULL, &onFactoryReset);
1834 EXPECT_TRUE(result == OC_STACK_ERROR);