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 "ResourceContainer.h"
22 #include "BundleInfo.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 ResourceContainer *container = ResourceContainer::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<BundleInfo *> bundles = container->listBundles();
59 std::list<BundleInfo *>::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;
113 /*java bundle add test*/
114 cout << "\n++++++++++++++++++++++++++++" << endl;
115 cout << "+++ Test for JAVA Bundle +++" << endl;
116 cout << "++++++++++++++++++++++++++++" << endl;
117 cout << "Press enter to add java bundle " << endl;
119 bundleParams["libraryPath"] = ".";
120 bundleParams["activator"] = "org.iotivity.bundle.hue.HueBundleActivator";
121 container->addBundle("oic.bundle.hueJavaSample", "/hueJava",
122 "../../../../../../../../service/resource-manipulation/src/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-jar-with-dependencies.jar",
125 bundles = container->listBundles();
126 cout << "\t>>> bundle list size : " << bundles.size() << endl;
127 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
129 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
132 cout << "\nPress enter to start java bundle " << endl;
134 container->startBundle("oic.bundle.hueJavaSample");
136 cout << "Press enter to stop java Bundle " << endl;
138 container->stopBundle("oic.bundle.hueJavaSample");
140 cout << "Press enter to test remove java Bundle " << endl;
142 container->removeBundle("oic.bundle.hueJavaSample");
144 bundles = container->listBundles();
145 cout << "\t>>> bundle list size : " << bundles.size() << endl;
146 for (bundleIt = bundles.begin(); bundleIt != bundles.end(); bundleIt++)
148 cout << "\t>>> bundle Id : " << (*bundleIt)->getID().c_str() << endl;
151 cout << "\nPress enter to stop container " << endl;
153 container->stopContainer();
155 cout << "Container stopped. Bye" << endl;