Bundle isolation - use separate threads for activation
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceContainer / unittests / ResourceContainerTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 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 #if defined(__linux__)
22 #include <unistd.h>
23 #endif
24
25 #include <string>
26 #include <map>
27 #include <vector>
28
29 #include <UnitTestHelper.h>
30
31 #include <gtest/gtest.h>
32 #include <HippoMocks/hippomocks.h>
33
34 #include "Configuration.h"
35 #include "BundleActivator.h"
36 #include "BundleResource.h"
37 #include "RCSResourceContainer.h"
38 #include "ResourceContainerBundleAPI.h"
39 #include "ResourceContainerImpl.h"
40
41 #include "RCSResourceObject.h"
42
43 using namespace std;
44 using namespace testing;
45 using namespace OIC::Service;
46
47 #define MAX_PATH 2048
48
49 string CONFIG_FILE = "ResourceContainerTestConfig.xml";
50
51 void getCurrentPath(std::string *pPath)
52 {
53     char buffer[MAX_PATH];
54
55 #if defined(__linux__)
56     char *strPath = NULL;
57     int length = readlink("/proc/self/exe", buffer, MAX_PATH - 1);
58
59     if (length != -1)
60     {
61         buffer[length] = '\0';
62         strPath = strrchr(buffer, '/');
63
64         if (strPath != NULL)
65             *strPath = '\0';
66     }
67 #endif
68     pPath->append(buffer);
69 }
70
71 /*Fake bundle resource class for testing*/
72 class TestBundleResource: public BundleResource
73 {
74     public:
75         string getAttribute(string attributeName)
76         {
77             (void)attributeName;
78             return "test";
79         }
80         ;
81         void setAttribute(string attributeName, string value)
82         {
83             (void)attributeName;
84             (void)value;
85         }
86         ;
87         void initAttributes()
88         {
89             BundleResource::setAttribute("attri", "test");
90         }
91         ;
92 };
93
94 class ResourceContainerTest: public TestWithMock
95 {
96
97     public:
98         RCSResourceContainer *m_pResourceContainer;
99         std::string m_strConfigPath;
100
101     protected:
102         void SetUp()
103         {
104             TestWithMock::SetUp();
105             m_pResourceContainer = RCSResourceContainer::getInstance();
106             getCurrentPath(&m_strConfigPath);
107             m_strConfigPath.append("/");
108             m_strConfigPath.append(CONFIG_FILE);
109         }
110 };
111
112 TEST_F(ResourceContainerTest, BundleRegisteredWhenContainerStartedWithValidConfigFile)
113 {
114     m_pResourceContainer->startContainer(m_strConfigPath);
115     EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
116     EXPECT_STREQ("oic.bundle.test",
117                  (*m_pResourceContainer->listBundles().begin())->getID().c_str());
118     EXPECT_STREQ("libTestBundle.so",
119                  (*m_pResourceContainer->listBundles().begin())->getPath().c_str());
120     EXPECT_STREQ("1.0.0", (*m_pResourceContainer->listBundles().begin())->getVersion().c_str());
121
122     m_pResourceContainer->stopContainer();
123 }
124
125 TEST_F(ResourceContainerTest, BundleLoadedWhenContainerStartedWithValidConfigFile)
126 {
127     m_pResourceContainer->startContainer(m_strConfigPath);
128
129     EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
130     EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isLoaded());
131     EXPECT_NE(nullptr,
132               ((BundleInfoInternal *)( *m_pResourceContainer->listBundles().begin()))->getBundleHandle());
133
134     m_pResourceContainer->stopContainer();
135 }
136
137 TEST_F(ResourceContainerTest, BundleActivatedWhenContainerStartedWithValidConfigFile)
138 {
139     m_pResourceContainer->startContainer(m_strConfigPath);
140
141     EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
142     EXPECT_TRUE(
143         ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
144     EXPECT_NE(nullptr,
145               ((BundleInfoInternal *)( *m_pResourceContainer->listBundles().begin()))->getBundleActivator());
146
147     m_pResourceContainer->stopContainer();
148 }
149
150 TEST_F(ResourceContainerTest, BundleNotRegisteredWhenContainerStartedWithInvalidConfigFile)
151 {
152     m_pResourceContainer->startContainer("invalidConfig");
153
154     EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
155 }
156
157 TEST_F(ResourceContainerTest, BundleNotRegisteredWhenContainerStartedWithEmptyConfigFile)
158 {
159     m_pResourceContainer->startContainer("");
160
161     EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
162 }
163
164 TEST_F(ResourceContainerTest, BundleUnregisteredWhenContainerStopped)
165 {
166     m_pResourceContainer->startContainer(m_strConfigPath);
167     m_pResourceContainer->stopContainer();
168
169     EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
170 }
171
172 TEST_F(ResourceContainerTest, BundleStoppedWithStartBundleAPI)
173 {
174     m_pResourceContainer->startContainer(m_strConfigPath);
175     m_pResourceContainer->stopBundle("oic.bundle.test");
176
177     EXPECT_FALSE(
178         ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
179
180     m_pResourceContainer->stopContainer();
181 }
182
183 TEST_F(ResourceContainerTest, BundleStartedWithStartBundleAPI)
184 {
185     m_pResourceContainer->startContainer(m_strConfigPath);
186     m_pResourceContainer->stopBundle("oic.bundle.test");
187     m_pResourceContainer->startBundle("oic.bundle.test");
188
189     EXPECT_TRUE(
190         ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
191
192     m_pResourceContainer->stopContainer();
193 }
194
195 TEST_F(ResourceContainerTest, AddNewSoBundleToContainer)
196 {
197     std::map<string, string> bundleParams;
198     std::list<RCSBundleInfo *> bundles;
199
200     bundles = m_pResourceContainer->listBundles();
201     m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
202
203     EXPECT_EQ(bundles.size() + 1, m_pResourceContainer->listBundles().size());
204     EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isLoaded());
205 }
206
207 TEST_F(ResourceContainerTest, RemoveSoBundleFromContainer)
208 {
209     std::map<string, string> bundleParams;
210     std::list<RCSBundleInfo *> bundles;
211
212     bundles = m_pResourceContainer->listBundles();
213     m_pResourceContainer->removeBundle("oic.bundle.test");
214
215     EXPECT_EQ(bundles.size() - 1, m_pResourceContainer->listBundles().size());
216 }
217
218 TEST_F(ResourceContainerTest, AddBundleAlreadyRegistered)
219 {
220     std::map<string, string> bundleParams;
221     std::list<RCSBundleInfo *> bundles;
222
223     m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
224     bundles = m_pResourceContainer->listBundles();
225     m_pResourceContainer->addBundle("oic.bundle.test", "", "libTestBundle.so", bundleParams);
226
227     EXPECT_EQ(bundles.size(), m_pResourceContainer->listBundles().size());
228 }
229
230 TEST_F(ResourceContainerTest, AddAndRemoveSoBundleResource)
231 {
232     std::list<string> resources;
233     std::map<string, string> resourceParams;
234     resourceParams["resourceType"] = "oic.test";
235
236     m_pResourceContainer->startContainer(m_strConfigPath);
237     resources = m_pResourceContainer->listBundleResources("oic.bundle.test");
238
239     m_pResourceContainer->addResourceConfig("oic.bundle.test", "/test_resource", resourceParams);
240
241     EXPECT_EQ(resources.size() + 1,
242               m_pResourceContainer->listBundleResources("oic.bundle.test").size());
243
244     m_pResourceContainer->removeResourceConfig("oic.bundle.test", "/test_resource");
245
246     EXPECT_EQ(resources.size(), m_pResourceContainer->listBundleResources("oic.bundle.test").size());
247
248     m_pResourceContainer->stopContainer();
249 }
250
251 TEST_F(ResourceContainerTest, TryAddingSoBundleResourceToNotRegisteredBundle)
252 {
253     std::map<string, string> resourceParams;
254
255     mocks.NeverCallFunc(ResourceContainerImpl::buildResourceObject);
256
257     m_pResourceContainer->addResourceConfig("unvalidBundleId", "", resourceParams);
258 }
259
260 class ResourceContainerBundleAPITest: public TestWithMock
261 {
262
263     public:
264         RCSResourceObject *m_pResourceObject;
265         ResourceContainerBundleAPI *m_pResourceContainer;
266         TestBundleResource *m_pBundleResource;
267         std::string m_strConfigPath;
268
269     protected:
270         void SetUp()
271         {
272             TestWithMock::SetUp();
273             m_pResourceObject = mocks.Mock<RCSResourceObject>();
274             m_pResourceContainer = ResourceContainerBundleAPI::getInstance();
275
276             getCurrentPath(&m_strConfigPath);
277             m_strConfigPath.append("/");
278             m_strConfigPath.append(CONFIG_FILE);
279
280             m_pBundleResource = new TestBundleResource();
281             m_pBundleResource->m_bundleId = "oic.bundle.test";
282             m_pBundleResource->m_uri = "/test_resource";
283             m_pBundleResource->m_resourceType = "oic.test";
284         }
285 };
286
287 TEST_F(ResourceContainerBundleAPITest, ResourceServerCreatedWhenRegisterResourceCalled)
288 {
289     m_pBundleResource = new TestBundleResource();
290     m_pBundleResource->m_bundleId = "oic.bundle.test";
291     m_pBundleResource->m_uri = "/test_resource/test";
292     m_pBundleResource->m_resourceType = "oic.test";
293
294     mocks.ExpectCallFunc(ResourceContainerImpl::buildResourceObject).With(m_pBundleResource->m_uri,
295             m_pBundleResource->m_resourceType).Return(nullptr);
296
297     m_pResourceContainer->registerResource(m_pBundleResource);
298 }
299
300 TEST_F(ResourceContainerBundleAPITest, RequestHandlerForResourceServerSetWhenRegisterResourceCalled)
301 {
302     mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
303         RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
304     {}));
305
306     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
307     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
308
309     m_pResourceContainer->registerResource(m_pBundleResource);
310
311     m_pResourceContainer->unregisterResource(m_pBundleResource);
312 }
313
314 TEST_F(ResourceContainerBundleAPITest, BundleResourceUnregisteredWhenUnregisterResourceCalled)
315 {
316     mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
317         RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
318     {}));
319
320     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
321     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
322
323     m_pResourceContainer->registerResource(m_pBundleResource);
324     m_pResourceContainer->unregisterResource(m_pBundleResource);
325
326     EXPECT_EQ((unsigned int) 0,
327               ((ResourceContainerImpl *)m_pResourceContainer)->listBundleResources(
328                   m_pBundleResource->m_bundleId).size());
329 }
330
331 TEST_F(ResourceContainerBundleAPITest,
332        ServerNotifiesToObserversWhenNotificationReceivedFromResource)
333 {
334     mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
335         RCSResourceObject::Ptr(m_pResourceObject, [](RCSResourceObject *)
336     {}));
337
338     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setGetRequestHandler);
339     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::setSetRequestHandler);
340
341     m_pResourceContainer->registerResource(m_pBundleResource);
342
343     mocks.ExpectCall(m_pResourceObject, RCSResourceObject::notify);
344
345     m_pResourceContainer->onNotificationReceived(m_pBundleResource->m_uri);
346
347     m_pResourceContainer->unregisterResource(m_pBundleResource);
348 }
349
350 TEST_F(ResourceContainerBundleAPITest, BundleConfigurationParsedWithValidBundleId)
351 {
352     configInfo bundle;
353     map< string, string > results;
354
355     ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(m_strConfigPath);
356     m_pResourceContainer->getBundleConfiguration("oic.bundle.test", &bundle);
357
358     results = *bundle.begin();
359
360     EXPECT_STREQ("oic.bundle.test", results["id"].c_str());
361     EXPECT_STREQ("libTestBundle.so", results["path"].c_str());
362     EXPECT_STREQ("1.0.0", results["version"].c_str());
363
364     ((ResourceContainerImpl *)m_pResourceContainer)->stopContainer();
365 }
366
367 TEST_F(ResourceContainerBundleAPITest, BundleResourceConfigurationListParsed)
368 {
369     vector< resourceInfo > resourceConfig;
370     resourceInfo result;
371
372     ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(m_strConfigPath);
373     m_pResourceContainer->getResourceConfiguration("oic.bundle.test", &resourceConfig);
374
375     result = *resourceConfig.begin();
376
377     EXPECT_STREQ("test_resource", result.name.c_str());
378     EXPECT_STREQ("oic.test", result.resourceType.c_str());
379
380     ((ResourceContainerImpl *)m_pResourceContainer)->stopContainer();
381 }
382
383 class ResourceContainerImplTest: public TestWithMock
384 {
385
386     public:
387         ResourceContainerImpl *m_pResourceContainer;
388         RCSBundleInfo *m_pBundleInfo;
389
390     protected:
391         void SetUp()
392         {
393             TestWithMock::SetUp();
394             m_pResourceContainer = ResourceContainerImpl::getImplInstance();
395             m_pBundleInfo = RCSBundleInfo::build();
396         }
397 };
398
399 TEST_F(ResourceContainerImplTest, SoBundleLoadedWhenRegisteredWithRegisterBundleAPI)
400 {
401     m_pBundleInfo->setPath("libTestBundle.so");
402     m_pBundleInfo->setVersion("1.0");
403     m_pBundleInfo->setLibraryPath(".");
404     m_pBundleInfo->setID("oic.bundle.test");
405
406     m_pResourceContainer->registerBundle(m_pBundleInfo);
407
408     EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle());
409 }
410
411 #if (JAVA_SUPPORT_TEST)
412 TEST_F(ResourceContainerImplTest, JavaBundleLoadedWhenRegisteredWithRegisterBundleAPIWrongPath)
413 {
414     m_pBundleInfo->setPath("wrong_path.jar");
415     m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
416     m_pBundleInfo->setLibraryPath("../.");
417     m_pBundleInfo->setVersion("1.0");
418     m_pBundleInfo->setID("oic.bundle.java.test");
419
420     m_pResourceContainer->registerBundle(m_pBundleInfo);
421     EXPECT_FALSE(((BundleInfoInternal *)m_pBundleInfo)->isLoaded());
422 }
423
424 TEST_F(ResourceContainerImplTest, JavaBundleTest)
425 {
426     m_pBundleInfo->setPath("TestBundleJava/hue-0.1-jar-with-dependencies.jar");
427     m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
428     m_pBundleInfo->setLibraryPath("../.");
429     m_pBundleInfo->setVersion("1.0");
430     m_pBundleInfo->setID("oic.bundle.java.test");
431
432     m_pResourceContainer->registerBundle(m_pBundleInfo);
433     EXPECT_TRUE(((BundleInfoInternal *)m_pBundleInfo)->isLoaded());
434
435     m_pResourceContainer->activateBundle(m_pBundleInfo);
436     EXPECT_TRUE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
437
438     m_pResourceContainer->deactivateBundle(m_pBundleInfo);
439     EXPECT_FALSE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
440 }
441 #endif
442
443 TEST_F(ResourceContainerImplTest, BundleNotRegisteredIfBundlePathIsInvalid)
444 {
445     m_pBundleInfo->setPath("");
446     m_pBundleInfo->setVersion("1.0");
447     m_pBundleInfo->setLibraryPath("../.");
448     m_pBundleInfo->setID("oic.bundle.test");
449
450     m_pResourceContainer->registerBundle(m_pBundleInfo);
451
452     EXPECT_EQ(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle());
453
454 }
455
456 TEST_F(ResourceContainerImplTest, SoBundleActivatedWithValidBundleInfo)
457 {
458     m_pBundleInfo->setPath("libTestBundle.so");
459     m_pBundleInfo->setVersion("1.0");
460     m_pBundleInfo->setLibraryPath("../.");
461     m_pBundleInfo->setID("oic.bundle.test");
462
463     m_pResourceContainer->registerBundle(m_pBundleInfo);
464     m_pResourceContainer->activateBundle(m_pBundleInfo);
465
466     EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator());
467 }
468
469 TEST_F(ResourceContainerImplTest, BundleNotActivatedWhenNotRegistered)
470 {
471     m_pBundleInfo->setPath("libTestBundle.so");
472     m_pBundleInfo->setVersion("1.0");
473     m_pBundleInfo->setLibraryPath("../.");
474     m_pBundleInfo->setID("oic.bundle.test");
475
476     m_pResourceContainer->activateBundle(m_pBundleInfo);
477
478     EXPECT_EQ(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator());
479 }
480
481 TEST_F(ResourceContainerImplTest, SoBundleActivatedWithBundleID)
482 {
483     m_pBundleInfo->setPath("libTestBundle.so");
484     m_pBundleInfo->setVersion("1.0");
485     m_pBundleInfo->setLibraryPath("../.");
486     m_pBundleInfo->setID("oic.bundle.test");
487
488     m_pResourceContainer->registerBundle(m_pBundleInfo);
489     m_pResourceContainer->activateBundle(m_pBundleInfo->getID());
490
491     EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator());
492     EXPECT_TRUE(((BundleInfoInternal *)m_pBundleInfo)->isActivated());
493 }
494
495 TEST_F(ResourceContainerImplTest, BundleDeactivatedWithBundleInfo)
496 {
497     m_pBundleInfo->setPath("libTestBundle.so");
498     m_pBundleInfo->setVersion("1.0");
499     m_pBundleInfo->setLibraryPath("../.");
500     m_pBundleInfo->setID("oic.bundle.test");
501
502     m_pResourceContainer->registerBundle(m_pBundleInfo);
503     m_pResourceContainer->activateBundle(m_pBundleInfo);
504     m_pResourceContainer->deactivateBundle(m_pBundleInfo);
505
506     EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleDeactivator());
507     EXPECT_FALSE(((BundleInfoInternal *)m_pBundleInfo)->isActivated());
508 }
509
510 TEST_F(ResourceContainerImplTest, BundleDeactivatedWithBundleInfoJava)
511 {
512     m_pBundleInfo->setPath("TestBundle/hue-0.1-jar-with-dependencies.jar");
513     m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
514     m_pBundleInfo->setLibraryPath("../.");
515     m_pBundleInfo->setVersion("1.0");
516     m_pBundleInfo->setID("oic.bundle.java.test");
517
518     m_pResourceContainer->registerBundle(m_pBundleInfo);
519     m_pResourceContainer->activateBundle(m_pBundleInfo);
520     m_pResourceContainer->deactivateBundle(m_pBundleInfo);
521     EXPECT_FALSE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
522 }
523
524 TEST_F(ResourceContainerImplTest, SoBundleDeactivatedWithBundleID)
525 {
526     m_pBundleInfo->setPath("libTestBundle.so");
527     m_pBundleInfo->setVersion("1.0");
528     m_pBundleInfo->setLibraryPath("../.");
529     m_pBundleInfo->setID("oic.bundle.test");
530
531     m_pResourceContainer->registerBundle(m_pBundleInfo);
532     m_pResourceContainer->activateBundle(m_pBundleInfo);
533
534     m_pResourceContainer->deactivateBundle(m_pBundleInfo->getID());
535
536     EXPECT_FALSE(((BundleInfoInternal *)m_pBundleInfo)->isActivated());
537 }
538
539 /* Test for Configuration */
540 TEST(ConfigurationTest, ConfigFileLoadedWithValidPath)
541 {
542     std::string strConfigPath;
543     getCurrentPath(&strConfigPath);
544     strConfigPath.append("/");
545     strConfigPath.append(CONFIG_FILE);
546
547     Configuration *config = new Configuration(strConfigPath);
548
549     EXPECT_TRUE(config->isLoaded());
550 }
551
552 TEST(ConfigurationTest, ConfigFileNotLoadedWithInvalidPath)
553 {
554     Configuration *config = new Configuration("InvalidPath");
555
556     EXPECT_FALSE(config->isLoaded());
557 }
558
559 TEST(ConfigurationTest, BundleConfigurationListParsed)
560 {
561     std::string strConfigPath;
562     getCurrentPath(&strConfigPath);
563     strConfigPath.append("/");
564     strConfigPath.append(CONFIG_FILE);
565
566     Configuration *config = new Configuration(strConfigPath);
567
568     configInfo bundles;
569     map< string, string > results;
570
571     config->getConfiguredBundles(&bundles);
572
573     results = *bundles.begin();
574
575     EXPECT_STREQ("oic.bundle.test", results["id"].c_str());
576     EXPECT_STREQ("libTestBundle.so", results["path"].c_str());
577     EXPECT_STREQ("1.0.0", results["version"].c_str());
578 }
579
580 TEST(ConfigurationTest, BundleConfigurationParsedWithValidBundleId)
581 {
582     std::string strConfigPath;
583     getCurrentPath(&strConfigPath);
584     strConfigPath.append("/");
585     strConfigPath.append(CONFIG_FILE);
586
587     Configuration *config = new Configuration(strConfigPath);
588
589     configInfo bundle;
590     map< string, string > results;
591
592     config->getBundleConfiguration("oic.bundle.test", &bundle);
593
594     results = *bundle.begin();
595
596     EXPECT_STREQ("oic.bundle.test", results["id"].c_str());
597     EXPECT_STREQ("libTestBundle.so", results["path"].c_str());
598     EXPECT_STREQ("1.0.0", results["version"].c_str());
599 }
600
601 TEST(ConfigurationTest, BundleConfigurationNotParsedWithInvalidBundleId)
602 {
603     std::string strConfigPath;
604     getCurrentPath(&strConfigPath);
605     strConfigPath.append("/");
606     strConfigPath.append(CONFIG_FILE);
607
608     Configuration *config = new Configuration(strConfigPath);
609
610     configInfo bundles;
611     config->getBundleConfiguration("test", &bundles);
612
613     EXPECT_TRUE(bundles.empty());
614 }
615
616 TEST(ConfigurationTest, BundleResourceConfigurationListParsed)
617 {
618     std::string strConfigPath;
619     getCurrentPath(&strConfigPath);
620     strConfigPath.append("/");
621     strConfigPath.append(CONFIG_FILE);
622
623     Configuration *config = new Configuration(strConfigPath);
624
625     vector< resourceInfo > resourceConfig;
626     resourceInfo result;
627
628     config->getResourceConfiguration("oic.bundle.test", &resourceConfig);
629
630     result = *resourceConfig.begin();
631
632     EXPECT_STREQ("test_resource", result.name.c_str());
633     EXPECT_STREQ("oic.test", result.resourceType.c_str());
634 }
635
636 TEST(ConfigurationTest, BundleResourceConfigurationNotParsedWithInvalidBundleId)
637 {
638     std::string strConfigPath;
639     getCurrentPath(&strConfigPath);
640     strConfigPath.append("/");
641     strConfigPath.append(CONFIG_FILE);
642
643     Configuration *config = new Configuration(strConfigPath);
644
645     configInfo bundles;
646     vector< resourceInfo > resourceConfig;
647     config->getResourceConfiguration("test", &resourceConfig);
648
649     EXPECT_TRUE(bundles.empty());
650 }