HueBundle = hue_resource_bundle_env.SharedLibrary('HueBundle', hue_resource_bundle_src)
hue_resource_bundle_env.InstallTarget(HueBundle, 'libHueBundle')
+######################################################################
+# build resource container unit tests
+######################################################################
+SConscript('unittests/SConscript')
######################################################################
# Build Container Test
<container>
<bundle>
<id>oic.bundle.discomfortIndexSensor</id>
- <path>libSampleBundle.so</path>
+ <path>libSoftSensorBundle.so</path>
<version>1.0.0</version>
<resources>
<resourceInfo>
<name>DiscomfortIndexSensor1</name>
- <resourceType>core.softsensor</resourceType>
+ <resourceType>oic.softsensor</resourceType>
<attributes>
<attribute>
<name>version</name>
namespace Service
{
typedef vector< map< string, string > > configInfo;
+
struct resourceInfo
{
string name;
string address;
map< string, vector< map< string, string > > > resourceProperty;
};
+
class Configuration
{
public:
-
-
-
Configuration();
Configuration(string configFile);
~Configuration();
+ bool isLoaded();
void getConfiguredBundles(configInfo *configOutput);
void getBundleConfiguration(string bundleId, configInfo *configOutput);
void getResourceConfiguration(string bundleId, vector< resourceInfo > *configOutput);
void getConfigDocument(string pathConfigFile);
void getCurrentPath(string *pPath);
+ bool m_loaded;
string m_pathConfigFile;
string m_strConfigData;
rapidxml::xml_document< char > m_xmlDoc;
BundleInfoInternal::BundleInfoInternal()
{
-
+ m_activator = nullptr;
+ m_deactivator = nullptr;
+ m_bundleHandle = nullptr;
}
BundleInfoInternal::~BundleInfoInternal()
{
-
+ m_activator = nullptr;
+ m_deactivator = nullptr;
+ m_bundleHandle = nullptr;
}
void BundleInfoInternal::setID(string id)
m_bundleHandle = handle;
}
- void* BundleInfoInternal::getBundleHandle()
+ void *BundleInfoInternal::getBundleHandle()
{
return m_bundleHandle;
}
return m_java_activator_class;
}*/
- void BundleInfoInternal::setJavaBundleActivatorObject(jobject activator_object){
+ void BundleInfoInternal::setJavaBundleActivatorObject(jobject activator_object)
+ {
m_java_activator_object = activator_object;
}
- jobject BundleInfoInternal::getJavaBundleActivatorObject(){
+ jobject BundleInfoInternal::getJavaBundleActivatorObject()
+ {
return m_java_activator_object;
}
Configuration::Configuration()
{
+ m_loaded = false;
}
Configuration::Configuration(string configFile)
{
+ m_loaded = false;
getCurrentPath(&m_pathConfigFile);
m_pathConfigFile.append("/");
{
}
+ bool Configuration::isLoaded()
+ {
+ return m_loaded;
+ }
+
void Configuration::getConfiguredBundles(configInfo *configOutput)
{
rapidxml::xml_node< char > *bundle;
try
{
- //cout << "Name of first node is: " << xmlDoc.first_node()->name() << endl;
+ //cout << "Name of first node is: " << m_xmlDoc.first_node()->name() << endl;
for (bundle = m_xmlDoc.first_node()->first_node("bundle"); bundle; bundle = bundle->next_sibling())
{
{
// <id>
strBundleId = bundle->first_node("id")->value();
- bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
if (!strBundleId.compare(bundleId))
{
+ bundleConfigMap.insert(std::make_pair("id", trim_both(strBundleId)));
+
// <path>
strPath = bundle->first_node("path")->value();
- bundleConfigMap.insert(std::make_pair("id", trim_both(strPath)));
+ bundleConfigMap.insert(std::make_pair("path", trim_both(strPath)));
// <version>
strVersion = bundle->first_node("version")->value();
- bundleConfigMap.insert(std::make_pair("id", trim_both(strVersion)));
+ bundleConfigMap.insert(std::make_pair("version", trim_both(strVersion)));
+
+ configOutput->push_back(bundleConfigMap);
break;
}
}
-
- configOutput->push_back(bundleConfigMap);
}
catch (rapidxml::parse_error &e)
{
std::cout << "xml parsing failed !!" << std::endl;
std::cout << e.what() << std::endl;
}
-
}
void Configuration::getConfigDocument(std::string pathConfigFile)
try
{
m_xmlDoc.parse< 0 >((char *)m_strConfigData.c_str());
-
+ m_loaded = true;
}
catch (rapidxml::parse_error &e)
{
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "ResourceContainerBundleAPI.h"
+#include "ResourceContainerImpl.h"
using namespace OIC::Service;
-namespace OIC{
- namespace Service{
+namespace OIC
+{
+ namespace Service
+ {
ResourceContainerBundleAPI::ResourceContainerBundleAPI()
{
}
+ ResourceContainerBundleAPI *ResourceContainerBundleAPI::getInstance()
+ {
+ return (ResourceContainerBundleAPI *)ResourceContainerImpl::getImplInstance();
+ }
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<container>
+ <bundle>
+ <id>oic.bundle.test</id>
+ <path>libTestBundle.so</path>
+ <version>1.0.0</version>
+ <!--</bundle>-->
+</container>
\ No newline at end of file
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <string>
+#include <map>
+#include <vector>
+
+#include <gtest/gtest.h>
+#include <HippoMocks/hippomocks.h>
+
+#include "Configuration.h"
+#include "BundleResource.h"
+#include "ResourceContainer.h"
+#include "ResourceContainerBundleAPI.h"
+#include "ResourceContainerImpl.h"
+
+#include "ResourceObject.h"
+
+using namespace std;
+using namespace testing;
+using namespace OIC::Service;
+
+
+string CONFIG_FILE = "ResourceContainerTestConfig.xml";
+
+typedef ResourceObject::Ptr(*resourceObjectBuild)();
+
+class TestBundleResource : public BundleResource
+{
+ public:
+ string getAttribute(string attributeName)
+ {
+ return "test";
+ };
+ void setAttribute(string attributeName, string value)
+ {};
+ void initAttributes()
+ {};
+};
+
+class ResourceContainerTest : public Test
+{
+ public:
+ ResourceContainer *m_pResourceContainer;
+
+ protected:
+ void SetUp() override
+ {
+ m_pResourceContainer = ResourceContainer::getInstance();
+ }
+};
+
+
+class ResourceContainerBundleAPITest : public Test
+{
+ public:
+ MockRepository mocks;
+ ResourceContainerBundleAPI *m_pResourceContainer;
+
+ protected:
+ void SetUp() override
+ {
+ m_pResourceContainer = ResourceContainerBundleAPI::getInstance();
+ }
+};
+
+// TC for registering resource should be implemented
+//TEST_F(ResourceContainerBundleAPITest, registerResourceTest)
+//{
+// ResourceObject::Builder *builder = new ResourceObject::Builder("/test_resource", "oic.test", "");
+// TestBundleResource *resource = new TestBundleResource();
+//
+// mocks.ExpectCall(builder, ResourceObject::Builder::build).Return(nullptr);
+//
+// m_pResourceContainer->registerResource(resource);
+//}
+
+// TC for unregistering resource should be implemented
+//TEST_F(ResourceContainerBundleAPITest, unregisterResourceTest)
+//{
+//}
+
+
+class ResourceContainerImplTest : public Test
+{
+ public:
+ ResourceContainerImpl *m_pResourceContainer;
+ BundleInfo *m_pBundleInfo;
+
+ protected:
+ void SetUp() override
+ {
+ m_pResourceContainer = ResourceContainerImpl::getImplInstance();
+ m_pBundleInfo = BundleInfo::createBundleInfo();
+ }
+};
+
+TEST_F(ResourceContainerImplTest, RegisterBundleTest)
+{
+ m_pBundleInfo->setPath("libTestBundle.so");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+
+ EXPECT_NE(((BundleInfoInternal *)m_pBundleInfo)->getBundleHandle(), nullptr);
+}
+
+TEST_F(ResourceContainerImplTest, RegisterBundleTestWithInvalidPath)
+{
+ m_pBundleInfo->setPath("");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+
+ EXPECT_EQ(((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator(), nullptr);
+}
+
+TEST_F(ResourceContainerImplTest, ActivateBundle)
+{
+ m_pBundleInfo->setPath("libTestBundle.so");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.test");
+
+ m_pResourceContainer->registerBundle(m_pBundleInfo);
+ m_pResourceContainer->activateBundle(m_pBundleInfo);
+
+ EXPECT_NE(((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator(), nullptr);
+}
+
+TEST_F(ResourceContainerImplTest, ActivateUnregisteredBundle)
+{
+ m_pBundleInfo->setPath("libTestBundle.so");
+ m_pBundleInfo->setVersion("1.0");
+ m_pBundleInfo->setID("oic.bundle.test");
+
+ m_pResourceContainer->activateBundle(m_pBundleInfo);
+
+ EXPECT_EQ(((BundleInfoInternal *)m_pBundleInfo)->getBundleActivator(), nullptr);
+}
+
+// TC for deactivating bundle should be implemented
+
+//TEST_F(ResourceContainerImplTest, DeactivateBundle)
+//{
+//
+//}
+
+
+/* Test for Configuration */
+TEST(ConfigurationTest, LoadConfigFileWithValidPath)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ EXPECT_EQ(config->isLoaded(), true);
+}
+
+TEST(ConfigurationTest, LoadConfigFileWithInvalidPath)
+{
+ Configuration *config = new Configuration("test");
+
+ EXPECT_EQ(config->isLoaded(), false);
+}
+
+TEST(ConfigurationTest, getConfiguredBundlesTest)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ configInfo bundles;
+ map<string, string> results;
+
+ config->getConfiguredBundles(&bundles);
+
+ results = *bundles.begin();
+
+ EXPECT_STREQ(results["id"].c_str(), "oic.bundle.test");
+ EXPECT_STREQ(results["path"].c_str(), "libTestBundle.so");
+ EXPECT_STREQ(results["version"].c_str(), "1.0.0");
+}
+
+TEST(ConfigurationTest, getBundleConfigurationTest)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ configInfo bundle;
+ map<string, string> results;
+
+ config->getBundleConfiguration("oic.bundle.test", &bundle);
+
+ results = *bundle.begin();
+
+ EXPECT_STREQ(results["id"].c_str(), "oic.bundle.test");
+ EXPECT_STREQ(results["path"].c_str(), "libTestBundle.so");
+ EXPECT_STREQ(results["version"].c_str(), "1.0.0");
+}
+
+TEST(ConfigurationTest, getBundleConfigurationTestWithInvalidBundleId)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ configInfo bundles;
+ config->getBundleConfiguration("test", &bundles);
+
+ EXPECT_EQ(bundles.empty(), true);
+}
+
+TEST(ConfigurationTest, getResourceConfigurationTest)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ vector<resourceInfo> resourceConfig;
+ resourceInfo result;
+
+ config->getResourceConfiguration("oic.bundle.test", &resourceConfig);
+
+ result = *resourceConfig.begin();
+
+ EXPECT_STREQ(result.name.c_str(), "test_resource");
+ EXPECT_STREQ(result.resourceType.c_str(), "oic.test");
+}
+
+TEST(ConfigurationTest, getResourceConfigurationTestWithInvalideBundleId)
+{
+ Configuration *config = new Configuration(CONFIG_FILE);
+
+ configInfo bundles;
+ vector<resourceInfo> resourceConfig;
+ config->getResourceConfiguration("test", &resourceConfig);
+
+ EXPECT_EQ(bundles.empty(), true);
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<container>
+ <bundle>
+ <id>oic.bundle.test</id>
+ <path>libTestBundle.so</path>
+ <version>1.0.0</version>
+ <resources>
+ <resourceInfo>
+ <name>test_resource</name>
+ <resourceType>oic.test</resourceType>
+ </resourceInfo>
+ </resources>
+ </bundle>
+</container>
--- /dev/null
+#******************************************************************
+#
+# Copyright 2015 Samsung Electronics All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+##
+# ResourceContainer Unit Test build script
+##
+import os
+Import('env')
+
+if env.get('RELEASE'):
+ env.AppendUnique(CCFLAGS = ['-Os'])
+ env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+ env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+ env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+container_gtest_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
+
+######################### unit test setting ##########################
+src_dir = lib_env.get('SRC_DIR')
+gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'
+######################################################################
+
+
+######################################################################
+# Build flags
+######################################################################
+gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
+gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')
+
+container_gtest_env.AppendUnique(
+ CPPPATH = [
+ env.get('SRC_DIR')+'/extlibs',
+ '../include',
+ '../include/internal',
+ '../bundle-api/include',
+ '../../serverBuilder/include',
+ '../../common/primitiveResource/include',
+ '/usr/lib/jvm/jdk1.8.0_40/include',
+ '/usr/lib/jvm/jdk1.8.0_40/include/linux'
+ ])
+
+if target_os not in ['windows', 'winrt']:
+ container_gtest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
+ if target_os != 'android':
+ container_gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
+ container_gtest_env.AppendUnique(LIBS = ['pthread'])
+
+if target_os == 'android':
+ container_gtest_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+ container_gtest_env.PrependUnique(LIBS = ['gnustl_shared', 'compatibility', 'log'])
+
+container_gtest_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippomocks-master',
+ gtest_dir + '/include'])
+
+container_gtest_env.AppendUnique(LIBPATH = ['/usr/lib/jvm/jdk1.8.0_40/jre/lib/amd64/server/'])
+container_gtest_env.PrependUnique(LIBS = ['ResContainerLib', 'server_builder', 'service_common', 'oc','octbstack', 'oc_logger', 'oc_logger_core', 'connectivity_abstraction', gtest, gtest_main])
+container_gtest_env.AppendUnique(LIBS = ['dl', 'jvm'])
+
+
+######################################################################
+# build test bundle
+######################################################################
+test_bundle_env = container_gtest_env.Clone()
+test_bundle_env.AppendUnique(CCFLAGS = ['-fPIC'])
+
+TEST_BUNDLE_DIR = 'TestBundle/'
+test_bundle_env.AppendUnique(CPPPATH = [
+ TEST_BUNDLE_DIR + 'include',
+ '../include/'
+ ])
+
+test_bundle_src = [ Glob(TEST_BUNDLE_DIR + 'src/*.cpp'), Glob('src/*.cpp')]
+
+TestBundle = test_bundle_env.SharedLibrary('TestBundle', test_bundle_src)
+test_bundle_env.InstallTarget(TestBundle, 'libTestBundle')
+
+
+######################################################################
+# Build Test
+######################################################################
+container_gtest_src = env.Glob('./*.cpp')
+
+container_test = container_gtest_env.Program('container_test', container_gtest_src)
+Alias("container_test", container_test)
+env.AppendTarget('container_test')
+
+# Copy test configuration
+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
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef TESTBUNDLE_H_
+#define TESTBUNDLE_H_
+
+#include <vector>
+
+#include "ResourceContainerBundleAPI.h"
+#include "BundleActivator.h"
+#include "BundleResource.h"
+
+using namespace OIC::Service;
+
+class TestBundleActivator : public BundleActivator
+{
+ public:
+ TestBundleActivator();
+ ~TestBundleActivator();
+
+ void activateBundle(ResourceContainerBundleAPI *resourceContainer, std::string bundleId);
+ void deactivateBundle();
+};
+
+#endif /* TESTBUNDLE_H_ */
--- /dev/null
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "TestBundleActivator.h"
+
+TestBundleActivator *bundle;
+
+TestBundleActivator::TestBundleActivator()
+{
+}
+
+TestBundleActivator::~TestBundleActivator()
+{
+}
+
+void TestBundleActivator::activateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId)
+{
+ std::cout << "TestBundleActivator::activateBundle .. " << std::endl;
+}
+
+void TestBundleActivator::deactivateBundle()
+{
+ std::cout << "TestBundleActivator::deactivateBundle .. " << std::endl;
+}
+
+extern "C" void externalActivateBundle(ResourceContainerBundleAPI *resourceContainer,
+ std::string bundleId)
+{
+ bundle = new TestBundleActivator();
+ bundle->activateBundle(resourceContainer, bundleId);
+}
+
+extern "C" void externalDeactivateBundle()
+{
+ if (!bundle)
+ {
+ bundle->deactivateBundle();
+ }
+}