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 "RCSResourceContainer.h"
22 #include "RCSBundleInfo.h"
23 #include "oc_logger.hpp"
27 using namespace OIC::Service;
28 using OC::oc_log_stream;
30 /* Annother way to create a context: */
31 auto info_logger = []() -> boost::iostreams::stream<OC::oc_log_stream> &
33 static OC::oc_log_stream ols(oc_make_ostream_logger);
34 static boost::iostreams::stream<OC::oc_log_stream> os(ols);
41 info_logger()->set_module("ContainerTest");
42 info_logger()->set_level(OC_LOG_INFO);
44 info_logger() << "Starting container test." << std::flush;
46 RCSResourceContainer *container = RCSResourceContainer::getInstance();
47 container->startContainer("examples/ResourceContainerConfig.xml");
49 /*so bundle add test*/
50 cout << "++++++++++++++++++++++++++" << endl;
51 cout << "+++ Test for SO Bundle +++" << endl;
52 cout << "++++++++++++++++++++++++++" << endl;
53 cout << "Press enter to add SO bundle " << endl;
55 std::map<string, string> bundleParams;
56 container->addBundle("oic.bundle.hueSample", "", "libHueBundle.so", bundleParams);
58 std::list<RCSBundleInfo *> bundles = container->listBundles();
59 std::list<RCSBundleInfo *>::iterator bundleIt;
61 cout << "\t>>> bundle list size : " << bundles.size() << endl;
62 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
64 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
67 cout << "\nPress enter to start SO bundle " << endl;
69 container->startBundle("oic.bundle.hueSample");
71 std::map<string, string> resourceParams;
72 cout << "Press enter to add SO bundle resource " << endl;
74 resourceParams["resourceType"] = "oic.light.control";
75 resourceParams["address"] = "http://192.168.0.2/api/newdeveloper/lights/1";
76 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
77 container->addResourceConfig("oic.bundle.hueSample", "", resourceParams);
79 std::list<string> resources = container->listBundleResources("oic.bundle.hueSample");
80 std::list<string>::iterator resourceIt;
81 cout << "\t>>> resource list size : " << resources.size() << endl;
82 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
84 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
87 cout << "\nPress enter to remove SO bundle resource " << endl;
89 container->removeResourceConfig("oic.bundle.hueSample", "/hue/light/1");
91 resources = container->listBundleResources("oic.bundle.hueSample");
92 cout << "\t>>> resource list size : " << resources.size() << endl;
93 for (resourceIt = resources.begin(); resourceIt != resources.end(); resourceIt++)
95 cout << "\t>>> resource uri : " << (*resourceIt).c_str() << endl;
98 cout << "\nPress enter to stop SO Bundle " << endl;
100 container->stopBundle("oic.bundle.hueSample");
102 cout << "Press enter to test remove SO Bundle " << endl;
104 container->removeBundle("oic.bundle.hueSample");
106 bundles = container->listBundles();
107 cout << "\t>>> bundle list size : " << bundles.size() << endl;
108 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
110 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
114 /*java bundle add test*/
115 cout << "\n++++++++++++++++++++++++++++" << endl;
116 cout << "+++ Test for JAVA Bundle +++" << endl;
117 cout << "++++++++++++++++++++++++++++" << endl;
118 cout << "Press enter to add java bundle " << endl;
120 bundleParams["libraryPath"] = ".";
121 bundleParams["activator"] = "org.iotivity.bundle.hue.HueBundleActivator";
122 container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
123 "../../../../../../../../service/resource-encapsulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
126 bundles = container->listBundles();
127 cout << "\t>>> bundle list size : " << bundles.size() << endl;
128 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
130 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
133 cout << "\nPress enter to start java bundle " << endl;
135 container->startBundle("oic.bundle.hueJavaSample");
137 cout << "Press enter to stop java Bundle " << endl;
139 container->stopBundle("oic.bundle.hueJavaSample");
141 cout << "Press enter to test remove java Bundle " << endl;
143 container->removeBundle("oic.bundle.hueJavaSample");
145 bundles = container->listBundles();
146 cout << "\t>>> bundle list size : " << bundles.size() << endl;
147 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
149 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
153 cout << "\nPress enter to stop container " << endl;
155 container->stopContainer();
157 cout << "Container stopped. Bye" << endl;