Added java bundle test. Allowing container test sample app and unit tests to be build in parallel.
Configureable library path for Java bundles. Set bundle-api version number to 0.1
Change-Id: I8660787613b38d7acc4296c9c6c701397e18dee2
Signed-off-by: Markus Jung <markus.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1597
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
##
import os
Import('env')
+import os.path
+
+def filtered_glob(env, pattern, omit=[],
+ ondisk=True, source=False, strings=False):
+ return filter(
+ lambda f: os.path.basename(f.path) not in omit,
+ env.Glob(pattern))
+
+env.AddMethod(filtered_glob, "FilteredGlob");
# Add third party libraries
lib_env = env.Clone()
######################################################################
# Source files and Targets
######################################################################
-res_container_src = env.Glob('src/*.cpp')
+res_container_src = ['src/BaseActivator.cpp','src/BundleActivator.cpp','src/BundleInfo.cpp',
+ 'src/BundleInfoInternal.cpp', 'src/BundleResource.cpp', 'src/Configuration.cpp', 'src/JavaBundleResource.cpp', 'src/ProtocolBridgeResource.cpp',
+ 'src/ProtocolBridgeConnector.cpp', 'src/ResourceContainer.cpp', 'src/ResourceContainerBundleAPI.cpp', 'src/ResourceContainerImpl.cpp',
+ 'src/SoftSensorResource.cpp']
res_container_static = resource_container_env.StaticLibrary('ResContainerLib', res_container_src)
res_container_shared = resource_container_env.SharedLibrary('ResContainerLib', res_container_src)
Command("examples/ResourceContainerConfig.xml","examples/ResourceContainerConfig.xml", Copy("$TARGET", "$SOURCE"))
Ignore("examples/ResourceContainerConfig.xml", "examples/ResourceContainerConfig.xml")
-containertestapp = containertest_env.Program('ContainerTest', res_container_src)
-Alias("containertest", containertestapp)
-env.AppendTarget('containertest')
+
+containersampleapp_src = [res_container_src , 'src/ContainerSample.cpp']
+containersampleapp = containertest_env.Program('ContainerSample',containersampleapp_src)
+Alias("containersample", containersampleapp)
+env.AppendTarget('containersample')
<groupId>org.iotivity.resourcecontainer</groupId>
<artifactId>bundle-api</artifactId>
<packaging>jar</packaging>
- <version>1.0</version>
+ <version>0.1</version>
<name>resource-container-api</name>
<url>http://maven.apache.org</url>
<dependencies>
* Unregisters a resource from the resource container.
*/
public void unregisterResource(BundleResource resource) {
+ bundleResources.remove(resource);
unregisterJavaResource(resource, resource.getURI());
}
<groupId>org.iotivity.bundles</groupId>
<artifactId>hue</artifactId>
<packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
+ <version>0.1</version>
<name>hue</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.iotivity.resourcecontainer</groupId>
<artifactId>bundle-api</artifactId>
- <version>1.0</version>
+ <version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
for (ResourceConfig config : resourceConfig) {
HueLightResource hueLightResource = new HueLightResource(connector,
- config.getM_name(), config.getM_uri(),
- config.getM_resourceType(), config.getM_address());
+ config.getName(), config.getURI(),
+ config.getResourceType(), config.getAddress());
registerResource(hueLightResource);
}
}
<name>DiscomfortIndexSensor1</name>
<resourceType>oic.softsensor</resourceType>
<attributes>
- <attribute>
+ <attribute>
<name>version</name>
<type>string</type>
<value>1.0</value>
</bundle>
<bundle>
<id>oic.bundle.hueJavaSample</id>
- <path>../../../../../../../../service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-1.0-SNAPSHOT-jar-with-dependencies.jar </path>
+ <path>../../../../../../../../service/resource-manipulation/modules/resourceContainer/examples/HueJavaSampleBundle/hue/target/hue-0.1-SNAPSHOT-jar-with-dependencies.jar </path>
+ <libraryPath>.</libraryPath>
<uri>/hueJava</uri>
<activator>org.iotivity.bundle.hue.HueBundleActivator</activator>
<version>1.0.0</version>
virtual string getID() = 0;
virtual void setPath(string path) = 0;
virtual string getPath() = 0;
+ virtual void setActivatorName(string activator) = 0;
+ virtual string getActivatorName() = 0;
+ virtual void setLibraryPath(string libpath) = 0;
+ virtual string getLibraryPath() = 0;
virtual void setVersion(string version) = 0;
virtual string getVersion() = 0;
static BundleInfo* build();
void setActivated(bool activated);
bool isActivated();
+ virtual void setLibraryPath(string libpath);
+ virtual string getLibraryPath();
+
void setActivatorName(string activatorName);
string getActivatorName();
string m_activator_name;
jmethodID m_java_activator, m_java_deactivator;
jobject m_java_activator_object;
+ string m_library_path;
};
}
}
void deactivateBundle(string bundleId);
void registerBundle(BundleInfo *bundleinfo);
void unregisterBundle(BundleInfo *bundleinfo);
- void unregisterBundle(string id);
+ void unregisterBundleSo(string id);
+ void unregisterBundleJava(string id);
// methods from ResourceContainerBundleAPI
void registerResource(BundleResource *resource);
javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
container->registerResource(javaBundleResource);
- cout << "JavaBundles: " << &java_resources << endl;
- cout << "Bundle resource: " << &java_resources[str_uri] << endl;
- cout << "Uri: " << str_uri << endl;
+
java_resources[str_uri] = javaBundleResource;
}
JNIEXPORT void JNICALL Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
(JNIEnv *env, jobject obj, jobject bundleResource, jstring uri){
const char *str_uri = env->GetStringUTFChars(uri, 0);
- cout << "unregister java resource " << endl;
- cout << "JavaBundles: " << &java_resources << endl;
- cout << "Bundle resource: " << &java_resources[str_uri] << endl;
- cout << "Uri: " << str_uri << endl;
+
if(java_resources[str_uri] != NULL){
ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
container->unregisterResource(java_resources[str_uri]);
return m_activator_name;
}
+ void BundleInfoInternal::setLibraryPath(string libpath){
+ m_library_path = libpath;
+ }
+
+ string BundleInfoInternal::getLibraryPath(){
+ return m_library_path;
+ }
+
void BundleInfoInternal::setJavaBundleActivatorMethod(jmethodID javaBundleActivator)
{
m_java_activator = javaBundleActivator;
#include <iostream>
#include <fstream>
#include <jni.h>
+#include <iostream>
+#include <fstream>
+#include <stdio.h>
#include "ResourceContainerImpl.h"
#include "BundleActivator.h"
bool has_suffix(const std::string &str, const std::string &suffix)
{
return str.size() >= suffix.size()
- && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
+ && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
void ResourceContainerImpl::startContainer(string configFile)
string activatorName = bundles[i]["activator"];
std::replace(activatorName.begin(), activatorName.end(), '.', '/');
((BundleInfoInternal *) bundleInfo)->setActivatorName(activatorName);
+ ((BundleInfoInternal *) bundleInfo)->setLibraryPath(bundles[i]["libraryPath"]);
}
info_logger() << "Init Bundle:" << bundles[i]["id"] << ";" << bundles[i]["path"]
void ResourceContainerImpl::stopContainer()
{
info_logger() << "Stopping resource container.";
- for (std::map<std::string, BundleInfoInternal *>::iterator it = m_bundles.begin();
- it != m_bundles.end(); ++it)
+ for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
+ it != m_bundles.end(); ++it)
{
BundleInfoInternal *bundleInfo = it->second;
deactivateBundle(bundleInfo);
void ResourceContainerImpl::activateBundle(BundleInfo *bundleInfo)
{
- BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *)bundleInfo;
+ BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
if (bundleInfoInternal->isLoaded())
{
void ResourceContainerImpl::deactivateBundle(BundleInfo *bundleInfo)
{
- if (((BundleInfoInternal *)bundleInfo)->isActivated())
+ if (((BundleInfoInternal *) bundleInfo)->isActivated())
{
deactivateBundle(bundleInfo->getID());
}
{
info_logger() << "Registering bundle: " << bundleInfo->getPath() << endl;
- m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *)bundleInfo);
+ m_bundles[bundleInfo->getID()] = ((BundleInfoInternal *) bundleInfo);
if (has_suffix(bundleInfo->getPath(), ".jar"))
{
- ((BundleInfoInternal *)bundleInfo)->setJavaBundle(true);
+ ((BundleInfoInternal *) bundleInfo)->setJavaBundle(true);
registerJavaBundle(bundleInfo);
}
else
{
- ((BundleInfoInternal *)bundleInfo)->setJavaBundle(false);
+ ((BundleInfoInternal *) bundleInfo)->setJavaBundle(false);
registerSoBundle(bundleInfo);
}
}
void ResourceContainerImpl::unregisterBundle(BundleInfo *bundleInfo)
{
- if (((BundleInfoInternal *)bundleInfo)->isLoaded()
- && !((BundleInfoInternal *)bundleInfo)->isActivated())
+ BundleInfoInternal* bundleInfoInternal = (BundleInfoInternal*) bundleInfo;
+ if (bundleInfoInternal->isLoaded() && !bundleInfoInternal->isActivated())
{
- unregisterBundle(bundleInfo->getID());
+ if (!bundleInfoInternal->getJavaBundle())
+ {
+ unregisterBundleSo(bundleInfo->getID());
+ }
+ else
+ {
+ unregisterBundleJava(bundleInfo->getID());
+ }
}
}
- void ResourceContainerImpl::unregisterBundle(string id)
+ void ResourceContainerImpl::unregisterBundleSo(string id)
{
void *bundleHandle = m_bundles[id]->getBundleHandle();
info_logger() << "Unregister bundle: " << m_bundles[id]->getID() << ", "
- << m_bundles[id]->getID() << endl;
+ << m_bundles[id]->getID() << endl;
char *error;
dlclose(bundleHandle);
if ((error = dlerror()) != NULL)
}
}
+ void ResourceContainerImpl::unregisterBundleJava(string id)
+ {
+ info_logger() << "Unregister Java bundle: " << m_bundles[id]->getID() << ", "
+ << m_bundles[id]->getID() << endl;
+
+ info_logger() << "Destroying JVM" << endl;
+ m_bundleVM[id]->DestroyJavaVM();
+ }
+
void ResourceContainerImpl::registerResource(BundleResource *resource)
{
ResourceObject::Ptr server = nullptr;
info_logger() << "Registration of resource " << strUri << "," << strResourceType
- << endl;
+ << endl;
server = buildResourceObject(strUri, strResourceType);
resource->registerObserver(this);
server->setGetRequestHandler(
- std::bind(&ResourceContainerImpl::getRequestHandler, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::bind(&ResourceContainerImpl::getRequestHandler, this,
+ std::placeholders::_1, std::placeholders::_2));
server->setSetRequestHandler(
- std::bind(&ResourceContainerImpl::setRequestHandler, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::bind(&ResourceContainerImpl::setRequestHandler, this,
+ std::placeholders::_1, std::placeholders::_2));
- info_logger() << "Registration finished " << strUri << "," << strResourceType << endl;
+ info_logger() << "Registration finished " << strUri << "," << strResourceType
+ << endl;
}
}
{
string strUri = resource->m_uri;
string strResourceType = resource->m_resourceType;
- cout << "Resource container unregisterResource called. " << strUri << endl;
if (m_mapServers.find(strUri) != m_mapServers.end())
{
m_mapServers[strUri].reset();
+
m_mapResources.erase(m_mapResources.find(strUri));
m_mapBundleResources[resource->m_bundleId].remove(strUri);
}
void ResourceContainerImpl::getBundleConfiguration(std::string bundleId,
configInfo *configOutput)
{
- m_config->getBundleConfiguration(bundleId, (configInfo *)configOutput);
+ m_config->getBundleConfiguration(bundleId, (configInfo *) configOutput);
}
void ResourceContainerImpl::getResourceConfiguration(std::string bundleId,
}
PrimitiveGetResponse ResourceContainerImpl::getRequestHandler(
- const PrimitiveRequest &request, const ResourceAttributes &attributes)
+ const PrimitiveRequest &request, const ResourceAttributes &attributes)
{
ResourceAttributes attr;
if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
{
for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
{
attr[attrName] = m_mapResources[request.getResourceUri()]->getAttribute(
- attrName);
+ attrName);
}
}
}
PrimitiveSetResponse ResourceContainerImpl::setRequestHandler(
- const PrimitiveRequest &request, const ResourceAttributes &attributes)
+ const PrimitiveRequest &request, const ResourceAttributes &attributes)
{
ResourceAttributes attr = attributes;
if (m_mapServers.find(request.getResourceUri()) != m_mapServers.end()
- && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
+ && m_mapResources.find(request.getResourceUri()) != m_mapResources.end())
{
for (string attrName : m_mapResources[request.getResourceUri()]->getAttributeNames())
{
void ResourceContainerImpl::onNotificationReceived(std::string strResourceUri)
{
info_logger() << "ResourceContainerImpl::onNotificationReceived\n\tnotification from "
- << strResourceUri << ".\n";
+ << strResourceUri << ".\n";
if (m_mapServers.find(strResourceUri) != m_mapServers.end())
{
ResourceObject::Ptr ResourceContainerImpl::buildResourceObject(string strUri,
string strResourceType)
{
- return ResourceObject::Builder(strUri, strResourceType,
- "DEFAULT_INTERFACE").setObservable(true).setDiscoverable(true).build();
+ return ResourceObject::Builder(strUri, strResourceType, "DEFAULT_INTERFACE").setObservable(
+ true).setDiscoverable(true).build();
}
void ResourceContainerImpl::startBundle(string bundleId)
}
void ResourceContainerImpl::addBundle(string bundleId, string bundleUri, string bundlePath,
- std::map< string, string > params)
+ std::map< string, string > params)
{
// To be implemented
}
std::list< BundleInfo * > ResourceContainerImpl::listBundles()
{
std::list< BundleInfo * > ret;
- for (std::map<std::string, BundleInfoInternal *>::iterator it = m_bundles.begin();
- it != m_bundles.end(); ++it)
+ for (std::map< std::string, BundleInfoInternal * >::iterator it = m_bundles.begin();
+ it != m_bundles.end(); ++it)
{
{
BundleInfo *bundleInfo = BundleInfo::build();
- ((BundleInfoInternal *)bundleInfo)->setBundleInfo((BundleInfo *)it->second);
+ ((BundleInfoInternal *) bundleInfo)->setBundleInfo((BundleInfo *) it->second);
ret.push_back(it->second);
}
}
{
std::list< string > ret;
- if (m_mapBundleResources.find(bundleId) != m_mapBundleResources.end())
+ if (m_mapBundleResources.find(bundleId) != m_mapBundleResources.end())
{
ret = m_mapBundleResources[bundleId];
}
-
+
return ret;
+
}
JavaVM *ResourceContainerImpl::getJavaVM(string bundleId)
void ResourceContainerImpl::registerJavaBundle(BundleInfo *bundleInfo)
{
info_logger() << "Registering Java bundle " << bundleInfo->getID() << endl;
- JavaVM *jvm;
- JNIEnv *env;
+ JavaVM * jvm;
+ JNIEnv * env;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) bundleInfo;
+ if(FILE *file = fopen(bundleInfo->getPath().c_str(), "r")){
+ fclose(file);
+ info_logger() << "Resource bundle " << bundleInfo->getPath() << " available." << endl;
+ //return true;
+ }
+ else{
+ error_logger() << "Resource bundle " << bundleInfo->getPath() << " not available" << endl;
+ return;
+ }
+
options[0].optionString = "-Djava.compiler=NONE";
char classpath[1000];
strcpy(classpath, "-Djava.class.path=");
strcat(classpath, bundleInfo->getPath().c_str());
+
+ info_logger() << "Configured classpath: " << classpath << "|" << endl;
+
options[1].optionString = classpath;
- options[2].optionString = "-Djava.library.path=.";
+ char libraryPath[1000];
+ strcpy(libraryPath, "-Djava.library.path=");
+ strcat(libraryPath, bundleInfo->getLibraryPath().c_str());
+ options[2].optionString = libraryPath;
+
+ info_logger() << "Configured library path: " << libraryPath << "|" << endl;
vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 3;
vm_args.ignoreUnrecognized = 1;
- JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+ int res;
+ res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
+
+ if(res < 0){
+ error_logger() << " cannot create JavaVM." << endl;
+ return;
+ }
+ else{
+ info_logger() << "JVM successfully created " << endl;
+ }
m_bundleVM.insert(std::pair< string, JavaVM * >(bundleInfo->getID(), jvm));
const char *className = bundleInfoInternal->getActivatorName().c_str();
+ info_logger() << "Looking up class: " << bundleInfoInternal->getActivatorName() << "|" << endl;
+
jclass bundleActivatorClass = env->FindClass(className);
if (bundleActivatorClass == NULL)
{
error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " bundle activator(" << bundleInfoInternal->getActivatorName()
- << ") not found " << endl;
+ << " bundle activator(" << bundleInfoInternal->getActivatorName()
+ << ") not found " << endl;
return;
}
jmethodID activateMethod = env->GetMethodID(bundleActivatorClass, "activateBundle",
- "()V");
+ "()V");
if (activateMethod == NULL)
{
error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " activate bundle method not found " << endl;
+ << " activate bundle method not found " << endl;
return;
}
bundleInfoInternal->setJavaBundleActivatorMethod(activateMethod);
jmethodID deactivateMethod = env->GetMethodID(bundleActivatorClass, "deactivateBundle",
- "()V");
+ "()V");
if (deactivateMethod == NULL)
{
error_logger() << "Cannot register bundle " << bundleInfoInternal->getID()
- << " deactivate bundle method not found " << endl;
+ << " deactivate bundle method not found " << endl;
return;
}
{
bundleActivator = (activator_t *) dlsym(bundleHandle, "externalActivateBundle");
bundleDeactivator = (deactivator_t *) dlsym(bundleHandle,
- "externalDeactivateBundle");
+ "externalDeactivateBundle");
if ((error = dlerror()) != NULL)
{
error_logger() << error << endl;
info_logger() << "Activating java bundle" << endl;
JavaVM *vm = getJavaVM(bundleId);
BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
- JNIEnv *env;
+ JNIEnv * env;
int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
if (envStat == JNI_EDETACHED)
}
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
- bundleInfoInternal->getJavaBundleActivatorMethod());
+ bundleInfoInternal->getJavaBundleActivatorMethod());
m_bundles[bundleId]->setActivated(true);
}
info_logger() << "Deactivating java bundle" << endl;
JavaVM *vm = getJavaVM(bundleId);
BundleInfoInternal *bundleInfoInternal = (BundleInfoInternal *) m_bundles[bundleId];
- JNIEnv *env;
+ JNIEnv * env;
int envStat = vm->GetEnv((void **) &env, JNI_VERSION_1_4);
if (envStat == JNI_EDETACHED)
}
env->CallVoidMethod(bundleInfoInternal->getJavaBundleActivatorObject(),
- bundleInfoInternal->getJavaBundleDeactivatorMethod());
+ bundleInfoInternal->getJavaBundleDeactivatorMethod());
m_bundles[bundleId]->setActivated(false);
}
string CONFIG_FILE = "ResourceContainerTestConfig.xml";
-
/*Fake bundle resource class for testing*/
-class TestBundleResource : public BundleResource
-{
- public:
- string getAttribute(string attributeName)
- {
- return "test";
- };
- void setAttribute(string attributeName, string value)
- {};
- void initAttributes()
- {
- BundleResource::setAttribute("attri", "test");
- };
+class TestBundleResource: public BundleResource
+{
+public:
+ string getAttribute(string attributeName)
+ {
+ return "test";
+ }
+ ;
+ void setAttribute(string attributeName, string value)
+ {
+ }
+ ;
+ void initAttributes()
+ {
+ BundleResource::setAttribute("attri", "test");
+ }
+ ;
};
-class ResourceContainerTest : public Test
+class ResourceContainerTest: public Test
{
- public:
- ResourceContainer *m_pResourceContainer;
-
- protected:
- void SetUp() override
- {
- m_pResourceContainer = ResourceContainer::getInstance();
- }
+public:
+ ResourceContainer *m_pResourceContainer;
+
+protected:
+ void SetUp() override
+ {
+ m_pResourceContainer = ResourceContainer::getInstance();
+ }
};
TEST_F(ResourceContainerTest, BundleRegisteredWhenContainerStartedWithValidConfigFile)
m_pResourceContainer->startContainer(CONFIG_FILE);
EXPECT_GT(m_pResourceContainer->listBundles().size(), 0);
- EXPECT_STREQ("oic.bundle.test", (*m_pResourceContainer->listBundles().begin())->getID().c_str());
- EXPECT_STREQ("libTestBundle.so", (*m_pResourceContainer->listBundles().begin())->getPath().c_str());
+ EXPECT_STREQ("oic.bundle.test",
+ (*m_pResourceContainer->listBundles().begin())->getID().c_str());
+ EXPECT_STREQ("libTestBundle.so",
+ (*m_pResourceContainer->listBundles().begin())->getPath().c_str());
EXPECT_STREQ("1.0.0", (*m_pResourceContainer->listBundles().begin())->getVersion().c_str());
m_pResourceContainer->stopContainer();
EXPECT_GT(m_pResourceContainer->listBundles().size(), 0);
EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isLoaded());
- EXPECT_NE(nullptr, ((BundleInfoInternal *)(
- *m_pResourceContainer->listBundles().begin()))->getBundleHandle());
+ EXPECT_NE(nullptr,
+ ((BundleInfoInternal *)( *m_pResourceContainer->listBundles().begin()))->getBundleHandle());
m_pResourceContainer->stopContainer();
}
m_pResourceContainer->startContainer(CONFIG_FILE);
EXPECT_GT(m_pResourceContainer->listBundles().size(), 0);
- EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
- EXPECT_NE(nullptr, ((BundleInfoInternal *)(
- *m_pResourceContainer->listBundles().begin()))->getBundleActivator());
+ EXPECT_TRUE(
+ ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
+ EXPECT_NE(nullptr,
+ ((BundleInfoInternal *)( *m_pResourceContainer->listBundles().begin()))->getBundleActivator());
m_pResourceContainer->stopContainer();
}
m_pResourceContainer->startContainer(CONFIG_FILE);
m_pResourceContainer->stopBundle("oic.bundle.test");
- EXPECT_FALSE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
+ EXPECT_FALSE(
+ ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
}
TEST_F(ResourceContainerTest, BundleStartedWithStartBundleAPI)
m_pResourceContainer->stopBundle("oic.bundle.test");
m_pResourceContainer->startBundle("oic.bundle.test");
- EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
+ EXPECT_TRUE(
+ ((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isActivated());
}
-
-class ResourceContainerBundleAPITest : public Test
+class ResourceContainerBundleAPITest: public Test
{
- public:
- MockRepository mocks;
- ResourceObject *m_pResourceObject;
- ResourceContainerBundleAPI *m_pResourceContainer;
- TestBundleResource *m_pBundleResource;
-
- protected:
- void SetUp() override
- {
- m_pResourceObject = mocks.Mock<ResourceObject>();
- m_pResourceContainer = ResourceContainerBundleAPI::getInstance();
-
- m_pBundleResource = new TestBundleResource();
- m_pBundleResource->m_bundleId = "oic.bundle.test";
- m_pBundleResource->m_uri = "/test_resource";
- m_pBundleResource->m_resourceType = "oic.test";
- }
+public:
+ MockRepository mocks;
+ ResourceObject *m_pResourceObject;
+ ResourceContainerBundleAPI *m_pResourceContainer;
+ TestBundleResource *m_pBundleResource;
+
+protected:
+ void SetUp() override
+ {
+ m_pResourceObject = mocks.Mock<ResourceObject>();
+ m_pResourceContainer = ResourceContainerBundleAPI::getInstance();
+
+ m_pBundleResource = new TestBundleResource();
+ m_pBundleResource->m_bundleId = "oic.bundle.test";
+ m_pBundleResource->m_uri = "/test_resource";
+ m_pBundleResource->m_resourceType = "oic.test";
+ }
};
TEST_F(ResourceContainerBundleAPITest, ResourceServerCreatedWhenRegisterResourceCalled)
TEST_F(ResourceContainerBundleAPITest, RequestHandlerForResourceServerSetWhenRegisterResourceCalled)
{
- mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(ResourceObject::Ptr(
- m_pResourceObject, [](ResourceObject *) {}));
+ mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
+ ResourceObject::Ptr(m_pResourceObject, [](ResourceObject *)
+ {}));
mocks.ExpectCall(m_pResourceObject, ResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, ResourceObject::setSetRequestHandler);
TEST_F(ResourceContainerBundleAPITest, BundleResourceUnregisteredWhenUnregisterResourceCalled)
{
- mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(ResourceObject::Ptr(
- m_pResourceObject, [](ResourceObject *) {}));
+ mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
+ ResourceObject::Ptr(m_pResourceObject, [](ResourceObject *)
+ {}));
mocks.ExpectCall(m_pResourceObject, ResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, ResourceObject::setSetRequestHandler);
m_pResourceContainer->registerResource(m_pBundleResource);
m_pResourceContainer->unregisterResource(m_pBundleResource);
- EXPECT_EQ(0, ((ResourceContainerImpl *)m_pResourceContainer)->listBundleResources(
- m_pBundleResource->m_bundleId).size());
+ EXPECT_EQ(0,
+ ((ResourceContainerImpl *)m_pResourceContainer)->listBundleResources( m_pBundleResource->m_bundleId).size());
}
TEST_F(ResourceContainerBundleAPITest,
- ServerNotifiesToObserversWhenNotificationReceivedFromResource)
+ ServerNotifiesToObserversWhenNotificationReceivedFromResource)
{
- mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(ResourceObject::Ptr(
- m_pResourceObject, [](ResourceObject *) {}));
+ mocks.OnCallFunc(ResourceContainerImpl::buildResourceObject).Return(
+ ResourceObject::Ptr(m_pResourceObject, [](ResourceObject *)
+ {}));
mocks.ExpectCall(m_pResourceObject, ResourceObject::setGetRequestHandler);
mocks.ExpectCall(m_pResourceObject, ResourceObject::setSetRequestHandler);
TEST_F(ResourceContainerBundleAPITest, BundleConfigurationParsedWithValidBundleId)
{
configInfo bundle;
- map<string, string> results;
+ map< string, string > results;
m_pResourceContainer->getBundleConfiguration("oic.bundle.test", &bundle);
TEST_F(ResourceContainerBundleAPITest, BundleResourceConfigurationListParsed)
{
- vector<resourceInfo> resourceConfig;
+ vector< resourceInfo > resourceConfig;
resourceInfo result;
m_pResourceContainer->getResourceConfiguration("oic.bundle.test", &resourceConfig);
EXPECT_STREQ("oic.test", result.resourceType.c_str());
}
-
-class ResourceContainerImplTest : public Test
+class ResourceContainerImplTest: public Test
{
- public:
- MockRepository mocks;
- ResourceContainerImpl *m_pResourceContainer;
- BundleInfo *m_pBundleInfo;
-
- protected:
- void SetUp() override
- {
- m_pResourceContainer = ResourceContainerImpl::getImplInstance();
- m_pBundleInfo = BundleInfo::build();
- }
+public:
+ MockRepository mocks;
+ ResourceContainerImpl *m_pResourceContainer;
+ BundleInfo *m_pBundleInfo;
+
+protected:
+ void SetUp() override
+ {
+ m_pResourceContainer = ResourceContainerImpl::getImplInstance();
+ m_pBundleInfo = BundleInfo::build();
+ }
};
TEST_F(ResourceContainerImplTest, SoBundleLoadedWhenRegisteredWithRegisterBundleAPI)
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath(".");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle());
}
-//TEST_F(ResourceContainerImplTest, JavaBundleLoadedWhenRegisteredWithRegisterBundleAPI)
-//{
-//}
+TEST_F(ResourceContainerImplTest, JavaBundleLoadedWhenRegisteredWithRegisterBundleAPIWrongPath)
+{
+ m_pBundleInfo->setPath("wrong_path.jar");
+ m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
+ m_pBundleInfo->setLibraryPath("../.");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.java.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+ EXPECT_FALSE(((BundleInfoInternal *)m_pBundleInfo)->isLoaded());
+}
+
+TEST_F(ResourceContainerImplTest, JavaBundleTest)
+{
+ m_pBundleInfo->setPath("TestBundleJava/hue-0.1-jar-with-dependencies.jar");
+ m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
+ m_pBundleInfo->setLibraryPath("../.");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.java.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+ EXPECT_TRUE(((BundleInfoInternal *)m_pBundleInfo)->isLoaded());
+
+ m_pResourceContainer->activateBundle(m_pBundleInfo);
+ EXPECT_TRUE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
+
+ m_pResourceContainer->deactivateBundle(m_pBundleInfo);
+ EXPECT_FALSE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
+}
TEST_F(ResourceContainerImplTest, BundleNotRegisteredIfBundlePathIsInvalid)
{
m_pBundleInfo->setPath("");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
EXPECT_EQ(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle());
+
}
TEST_F(ResourceContainerImplTest, SoBundleActivatedWithValidBundleInfo)
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
EXPECT_NE(nullptr, ((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator());
}
-//TEST_F(ResourceContainerImplTest, JavaBundleActivatedWithValidBundleInfo)
-//{
-//}
+/*TEST_F(ResourceContainerImplTest, JavaBundleActivatedWithValidBundleInfo)
+{
+ m_pBundleInfo->setPath("TestBundleJava/hue-0.1-jar-with-dependencies.jar");
+ m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
+ m_pBundleInfo->setLibraryPath("../.");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.java.test2");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+ m_pResourceContainer->activateBundle(m_pBundleInfo);
+ EXPECT_TRUE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
+
+}*/
TEST_F(ResourceContainerImplTest, BundleNotActivatedWhenNotRegistered)
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->activateBundle(m_pBundleInfo);
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
EXPECT_TRUE(((BundleInfoInternal *)m_pBundleInfo)->isActivated());
}
-//TEST_F(ResourceContainerImplTest, JavaBundleActivatedWithBundleID)
-//{
-//}
-
TEST_F(ResourceContainerImplTest, BundleDeactivatedWithBundleInfo)
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
EXPECT_FALSE(((BundleInfoInternal *)m_pBundleInfo)->isActivated());
}
-//TEST_F(ResourceContainerImplTest, DeactivateBundleNotWorkingIfBundleNotDeactivated)
-//{
-//}
+TEST_F(ResourceContainerImplTest, BundleDeactivatedWithBundleInfoJava)
+{
+ m_pBundleInfo->setPath("TestBundle/hue-0.1-jar-with-dependencies.jar");
+ m_pBundleInfo->setActivatorName("org/iotivity/bundle/hue/HueBundleActivator");
+ m_pBundleInfo->setLibraryPath("../.");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.java.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+ m_pResourceContainer->activateBundle(m_pBundleInfo);
+ m_pResourceContainer->deactivateBundle(m_pBundleInfo);
+ EXPECT_FALSE(((BundleInfoInternal *) m_pBundleInfo)->isActivated());
+}
TEST_F(ResourceContainerImplTest, SoBundleDeactivatedWithBundleID)
{
m_pBundleInfo->setPath("libTestBundle.so");
m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setLibraryPath("../.");
m_pBundleInfo->setID("oic.bundle.test");
m_pResourceContainer->registerBundle(m_pBundleInfo);
//{
//}
-
-/* Test for Configuration */
-TEST(ConfigurationTest, ConfigFileLoadedWithValidPath)
+/* Test for Configuration */TEST(ConfigurationTest, ConfigFileLoadedWithValidPath)
{
Configuration *config = new Configuration(CONFIG_FILE);
Configuration *config = new Configuration(CONFIG_FILE);
configInfo bundles;
- map<string, string> results;
+ map< string, string > results;
config->getConfiguredBundles(&bundles);
Configuration *config = new Configuration(CONFIG_FILE);
configInfo bundle;
- map<string, string> results;
+ map< string, string > results;
config->getBundleConfiguration("oic.bundle.test", &bundle);
{
Configuration *config = new Configuration(CONFIG_FILE);
- vector<resourceInfo> resourceConfig;
+ vector< resourceInfo > resourceConfig;
resourceInfo result;
config->getResourceConfiguration("oic.bundle.test", &resourceConfig);
Configuration *config = new Configuration(CONFIG_FILE);
configInfo bundles;
- vector<resourceInfo> resourceConfig;
+ vector< resourceInfo > resourceConfig;
config->getResourceConfiguration("test", &resourceConfig);
EXPECT_TRUE(bundles.empty());
-}
\ No newline at end of file
+}
<bundle>
<id>oic.bundle.test</id>
<path>libTestBundle.so</path>
+ <libraryPath>.</libraryPath>
<version>1.0.0</version>
<resources>
<resourceInfo>
import os
Import('env')
+import os.path
+
+def filtered_glob(env, pattern, omit=[],
+ ondisk=True, source=False, strings=False):
+ return filter(
+ lambda f: os.path.basename(f.path) not in omit,
+ env.Glob(pattern))
+
+env.AddMethod(filtered_glob, "FilteredGlob");
+
try:
print 'Java Home: ', os.environ['JAVA_HOME']
print 'Java Lib: ', os.environ['JAVA_LIB']
Command("./ResourceContainerTestConfig.xml","./ResourceContainerTestConfig.xml", Copy("$TARGET", "$SOURCE"))
Ignore("./ResourceContainerTestConfig.xml", "./ResourceContainerTestConfig.xml")
Command("./ResourceContainerInvalidConfig.xml","./ResourceContainerInvalidConfig.xml", Copy("$TARGET", "$SOURCE"))
-Ignore("./ResourceContainerInvalidConfig.xml", "./ResourceContainerInvalidConfig.xml")
\ No newline at end of file
+Ignore("./ResourceContainerInvalidConfig.xml", "./ResourceContainerInvalidConfig.xml")
+Command("./TestBundleJava/hue-0.1-jar-with-dependencies.jar","./TestBundleJava/hue-0.1-jar-with-dependencies.jar", Copy("$TARGET", "$SOURCE"))
+Ignore("./TestBundleJava/hue-0.1-jar-with-dependencies.jar", "./TestBundleJava/hue-0.1-jar-with-dependencies.jar")
\ No newline at end of file