aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2016-05-11 17:21:36 +0300
committerGabriel Schulhof <gabriel.schulhof@intel.com>2016-05-26 10:57:28 +0000
commit62e3a344c52c4ea2cd728efaade37892c58fe414 (patch)
treeb864313a8e490e97fe43804363b9e72795664081
parent4ebcfdfd11fe608392ed5ae37187decaec1c06b7 (diff)
All: 1.1.0-3 - A few more updates towards spec compliance and a bug fix1.1.0-3
Examples: * Conform to updated OCSetDeviceInfo() API * Add console.log() statemens for clarity OicServer: * Set event.type to be the same as the event name * Handle invalid OicResourceInit at registration Tests: * package.json: Retrieve OCF test suite via https * Introduce OCF test suite * Use the start-stack-test from the OCF test suite * Use resource (un)registration test from OCF suite JS API: * Add pretty names to the classes * Remove suffix "Resource" from (un)?registerResource * StorageHandler: Use process.cwd() + process.pid() in the absence of a module filename README.md: * Project description and link to Soletta spec instead of including it * List of prerequisite utilities (add wget and git) Build: * Use correct script to re-install dependencies Fixes gh-50 Change-Id: I7c1d8b319976b059d5e33f3b4f5be49365a89444 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/8353
-rw-r--r--README.md10
-rwxr-xr-xdist.sh4
-rw-r--r--grunt-build/tasks/alias.js2
-rw-r--r--grunt-build/tasks/ocf-suite.js42
-rw-r--r--js/client.discovery.js6
-rw-r--r--js/client.get.js4
-rw-r--r--js/high-level-resource-creation-client.js4
-rw-r--r--js/high-level-resource-creation-server.js6
-rw-r--r--js/high-level-server-example.js13
-rw-r--r--js/multi-server-client.js4
-rw-r--r--js/multi-server-server1.js8
-rw-r--r--js/multi-server-server2.js8
-rw-r--r--js/server.discoverable.js8
-rw-r--r--js/server.get.js8
-rw-r--r--js/server.observable.js8
-rw-r--r--js/server.presence.js6
-rw-r--r--lib/OicDevice.js2
-rw-r--r--lib/OicResource.js2
-rw-r--r--lib/OicServer.js38
-rw-r--r--lib/StorageHandler.js11
-rw-r--r--package.json3
-rw-r--r--spec/iot-js-spec.md481
-rw-r--r--tests/tests/API Complex Payload/server.js6
-rw-r--r--tests/tests/API Create Delete/server.js18
-rw-r--r--tests/tests/API Device ID Persistence.js4
-rw-r--r--tests/tests/API Device Information/server.js4
-rw-r--r--tests/tests/API Device Rediscovery.js12
-rw-r--r--tests/tests/API Discovery/server.js12
-rw-r--r--tests/tests/API Error Propagation/server.js13
-rw-r--r--tests/tests/API Observation/server.js8
-rw-r--r--tests/tests/API Presence/server.js12
-rw-r--r--tests/tests/API Query Parameters/server.js9
-rw-r--r--tests/tests/API Register Resource.js42
-rw-r--r--tests/tests/API Retrieve/server.js17
-rw-r--r--tests/tests/API Start Stack.js28
-rw-r--r--tests/tests/API Unregister Resource.js51
-rw-r--r--tests/tests/Interactive Server Startup.js33
37 files changed, 243 insertions, 704 deletions
diff --git a/README.md b/README.md
index 8eb3370..b381240 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# iotivity-node
## Description
-This project provides [iotivity][] node.js bindings.
+This project provides a Javascript API for [OCF][] functionality. The API follows a maintained [specification][] and is implemented as a native addon using [iotivity][] as its backend.
## Build status
<a href="https://travis-ci.org/otcshare/iotivity-node">
@@ -13,7 +13,7 @@ This project provides [iotivity][] node.js bindings.
### For the impatient:
0. Make sure [node][] is up and running
0. Install the following packages, which your distribution should provide:
- 0. unzip, scons, and make
+ 0. unzip, scons, wget, git, and make
0. Development headers for boost, libuuid, glib2, and libcurl
boost and libcurl are needed during the build process, but iotivity-node does not ultimately depend on either.
@@ -110,7 +110,9 @@ Make sure no firewall is running (or one is properly configured to allow iotivit
[1.1.0]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=tree;hb=1.1.0
[snapshot]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=snapshot;h=1.1.0;sf=tgz
[scons]: http://www.scons.org/
-[install.sh]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-2/install.sh
-[octbstack.pc.in]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-2/octbstack.pc.in
+[install.sh]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-3/install.sh
+[octbstack.pc.in]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-3/octbstack.pc.in
[iotivity wiki]: https://wiki.iotivity.org/faq_s
[video]: https://www.youtube.com/watch?v=95VTB_qgYfw
+[specification]: https://github.com/solettaproject/soletta/blob/v1_beta19/doc/js-spec/oic.md
+[OCF]: http://openconnectivity.org/
diff --git a/dist.sh b/dist.sh
index 9d8df7e..4e49d98 100755
--- a/dist.sh
+++ b/dist.sh
@@ -156,9 +156,7 @@ if test "x${DO_DEVREINST}x" = "xTRUEx"; then
echo "*** Re-installing dependencies ***"
# Restore devDependencies after having created the distribution package
- node -e 'Object.keys( require( "./package.json" ).devDependencies )
- .concat( Object.keys( require( "./package.json" ).dependencies ) )
- .map( function( item ){ console.log( item ) } );' | xargs npm install
+ npm install --ignore-scripts
fi
if test "x${DO_BUILD}x" = "xTRUEx"; then
diff --git a/grunt-build/tasks/alias.js b/grunt-build/tasks/alias.js
index 51dfa7a..ab2be20 100644
--- a/grunt-build/tasks/alias.js
+++ b/grunt-build/tasks/alias.js
@@ -18,7 +18,7 @@ grunt.registerTask( "lint", [ "jshint", "jscs" ] );
grunt.registerTask( "default", [ "test" ] );
-grunt.registerTask( "test", [ "lint", "testsuite", "testdist" ] );
+grunt.registerTask( "test", [ "lint", "testsuite", "ocf-suite", "testdist" ] );
grunt.registerTask( "format", [ "esformatter", "clangformat" ] );
diff --git a/grunt-build/tasks/ocf-suite.js b/grunt-build/tasks/ocf-suite.js
new file mode 100644
index 0000000..f71093e
--- /dev/null
+++ b/grunt-build/tasks/ocf-suite.js
@@ -0,0 +1,42 @@
+// Copyright 2016 Intel Corporation
+//
+// 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.
+
+module.exports = function( grunt ) {
+
+var _ = require( "lodash" ),
+ path = require( "path" );
+
+grunt.task.registerTask( "ocf-suite", "Run the OCF test suite", function() {
+ var done = this.async();
+ var testSuite = require( "ocf-test-suite" );
+
+ _.extend( testSuite, {
+ defaultCallbacks: _.extend( testSuite.defaultCallbacks, {
+ done: ( function( originalDone ) {
+ return function() {
+ if ( originalDone ) {
+ return originalDone.apply( this, arguments );
+ }
+ done();
+ };
+ } )( testSuite.defaultCallbacks.done )
+ } )
+ } )( _.extend( {
+ location: path.resolve( path.join( __dirname, "..", ".." ) )
+ }, grunt.option( "ocf-suites" ) ? {
+ tests: grunt.option( "ocf-suites" ).split( "," )
+ } : {} ) );
+} );
+
+};
diff --git a/js/client.discovery.js b/js/client.discovery.js
index c01c285..00552d5 100644
--- a/js/client.discovery.js
+++ b/js/client.discovery.js
@@ -34,6 +34,8 @@ var intervalId,
return returnValue;
} )();
+console.log( "Starting OCF stack in client mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_CLIENT );
@@ -41,6 +43,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Issuing discovery request" );
+
// Discover resources and list them
iotivity.OCDoResource(
@@ -60,7 +64,7 @@ iotivity.OCDoResource(
iotivity.OCConnectivityType.CT_DEFAULT,
iotivity.OCQualityOfService.OC_HIGH_QOS,
function( handle, response ) {
- console.log( JSON.stringify( response, null, 4 ) );
+ console.log( "Discovery response: " + JSON.stringify( response, null, 4 ) );
return iotivity.OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION;
},
diff --git a/js/client.get.js b/js/client.get.js
index 04f2cbd..317a4ac 100644
--- a/js/client.get.js
+++ b/js/client.get.js
@@ -19,6 +19,8 @@ var intervalId,
sampleUri = "/a/iotivity-node-get-sample",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in client mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_CLIENT );
@@ -26,6 +28,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Issuing discovery request" );
+
// Discover resources and list them
iotivity.OCDoResource(
diff --git a/js/high-level-resource-creation-client.js b/js/high-level-resource-creation-client.js
index 26a034a..98d5b1d 100644
--- a/js/high-level-resource-creation-client.js
+++ b/js/high-level-resource-creation-client.js
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+console.log( "Acquiring OCF device" );
+
var device = require( "iotivity-node" )( "client" );
function throwError( error ) {
@@ -19,7 +21,6 @@ function throwError( error ) {
process.exit( 1 );
}
-// This
new Promise( function( fulfill, reject ) {
var resourceFoundHandler = function( event ) {
console.log( "Discovered resource(s) via the following event:\n" +
@@ -36,6 +37,7 @@ new Promise( function( fulfill, reject ) {
// Add a listener that will receive the results of the discovery
device.addEventListener( "resourcefound", resourceFoundHandler );
+ console.log( "Issuing discovery request" );
device.findResources().catch( function( error ) {
device.removeEventListener( "resourcefound", resourceFoundHandler );
reject( "findResource() failed: " + error );
diff --git a/js/high-level-resource-creation-server.js b/js/high-level-resource-creation-server.js
index 322ca4a..7934d09 100644
--- a/js/high-level-resource-creation-server.js
+++ b/js/high-level-resource-creation-server.js
@@ -35,7 +35,7 @@ function throwError( error ) {
var requestHandlers = {
create: function( request ) {
console.log( "create request" );
- device.registerResource( _.extend( request.res, {
+ device.register( _.extend( request.res, {
discoverable: true
} ) ).then( function( resource ) {
console.log( "resource successfully registered" );
@@ -47,7 +47,7 @@ var requestHandlers = {
console.log( "delete request" );
if ( request.target.id.path === resourceCreatedByRemote.id.path &&
request.target.id.deviceId === resourceCreatedByRemote.id.deviceId ) {
- device.unregisterResource( resourceCreatedByRemote ).then(
+ device.unregister( resourceCreatedByRemote ).then(
function() {
console.log( "resource successfully deleted" );
request.sendResponse( null );
@@ -65,7 +65,7 @@ _.each( requestHandlers, function( handler, requestType ) {
} );
} );
-device.registerResource( {
+device.register( {
id: {
path: "/a/high-level-resource-creation-example"
},
diff --git a/js/high-level-server-example.js b/js/high-level-server-example.js
index c6265ef..c1f0fff 100644
--- a/js/high-level-server-example.js
+++ b/js/high-level-server-example.js
@@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var lightResource,
+var lightResource, device,
_ = require( "lodash" ),
observerCount = 0,
- sensor = require( "./mock-sensor" )(),
- device = require( "iotivity-node" )( "server" );
+ sensor = require( "./mock-sensor" )();
+console.log( "Acquiring OCF device" );
+
+device = require( "iotivity-node" )( "server" );
device.device = _.extend( device.device, {
name: "api-server-example"
} );
@@ -72,7 +74,10 @@ var lightResourceRequestHandlers = {
};
if ( device.device.uuid ) {
- device.registerResource( {
+
+ console.log( "Registering OCF resource" );
+
+ device.register( {
id: { path: "/a/high-level-example" },
resourceTypes: [ "core.light" ],
interfaces: [ "oic.if.baseline" ],
diff --git a/js/multi-server-client.js b/js/multi-server-client.js
index 65e7ff3..533444f 100644
--- a/js/multi-server-client.js
+++ b/js/multi-server-client.js
@@ -16,6 +16,8 @@ var intervalId,
handleReceptacle = {},
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_CLIENT );
@@ -23,6 +25,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Issuing discovery request" );
+
// Discover resources and list them
iotivity.OCDoResource(
diff --git a/js/multi-server-server1.js b/js/multi-server-server1.js
index f2423d3..efb4bcb 100644
--- a/js/multi-server-server1.js
+++ b/js/multi-server-server1.js
@@ -19,10 +19,12 @@ var intervalId,
sampleUri = "/a/iotivity-multi-server-server1",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
-iotivity.OCSetDeviceInfo( { deviceName: "server.observable" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.observable", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.observe.sample",
manufacturerName: "iotivity-node"
@@ -32,6 +34,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Registering resource" );
+
iotivity.OCCreateResource(
handleReceptacle,
"core.fan",
@@ -57,6 +61,8 @@ iotivity.OCCreateResource(
},
iotivity.OCResourceProperty.OC_DISCOVERABLE );
+console.log( "Server ready" );
+
// Exit gracefully when interrupted
process.on( "SIGINT", function() {
console.log( "SIGINT: Quitting..." );
diff --git a/js/multi-server-server2.js b/js/multi-server-server2.js
index 1e01e6f..1352561 100644
--- a/js/multi-server-server2.js
+++ b/js/multi-server-server2.js
@@ -19,10 +19,12 @@ var intervalId,
sampleUri = "/a/iotivity-multi-server-server2",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
-iotivity.OCSetDeviceInfo( { deviceName: "server.observable" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.observable", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.observe.sample",
manufacturerName: "iotivity-node"
@@ -32,6 +34,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Registering resource" );
+
iotivity.OCCreateResource(
handleReceptacle,
"core.fan",
@@ -57,6 +61,8 @@ iotivity.OCCreateResource(
},
iotivity.OCResourceProperty.OC_DISCOVERABLE );
+console.log( "Server ready" );
+
// Exit gracefully when interrupted
process.on( "SIGINT", function() {
console.log( "SIGINT: Quitting..." );
diff --git a/js/server.discoverable.js b/js/server.discoverable.js
index cbc1e5d..66ac83f 100644
--- a/js/server.discoverable.js
+++ b/js/server.discoverable.js
@@ -16,6 +16,8 @@ var intervalId,
handleReceptacle = {},
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
@@ -23,12 +25,14 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
-iotivity.OCSetDeviceInfo( { deviceName: "server.discoverable" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.discoverable", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.discoverable.sample",
manufacturerName: "iotivity-node"
} );
+console.log( "Registering resources" );
+
// Create a new resource
iotivity.OCCreateResource(
@@ -61,6 +65,8 @@ iotivity.OCCreateResource(
},
iotivity.OCResourceProperty.OC_DISCOVERABLE );
+console.log( "Server ready" );
+
// Exit gracefully when interrupted
process.on( "SIGINT", function() {
console.log( "SIGINT: Quitting..." );
diff --git a/js/server.get.js b/js/server.get.js
index 82a8db4..bdd21a1 100644
--- a/js/server.get.js
+++ b/js/server.get.js
@@ -19,10 +19,12 @@ var intervalId,
sampleUri = "/a/iotivity-node-get-sample",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
-iotivity.OCSetDeviceInfo( { deviceName: "server.get" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.get", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.get.sample",
manufacturerName: "iotivity-node"
@@ -32,6 +34,8 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
+console.log( "Registering resource" );
+
// Create a new resource
iotivity.OCCreateResource(
@@ -72,6 +76,8 @@ iotivity.OCCreateResource(
},
iotivity.OCResourceProperty.OC_DISCOVERABLE );
+console.log( "Server ready" );
+
// Exit gracefully when interrupted
process.on( "SIGINT", function() {
console.log( "SIGINT: Quitting..." );
diff --git a/js/server.observable.js b/js/server.observable.js
index 9074d67..8e52327 100644
--- a/js/server.observable.js
+++ b/js/server.observable.js
@@ -20,10 +20,12 @@ var intervalId,
sampleUri = "/a/iotivity-node-observe-sample",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
-iotivity.OCSetDeviceInfo( { deviceName: "server.observable" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.observable", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.observe.sample",
manufacturerName: "iotivity-node"
@@ -50,6 +52,8 @@ require( "./mock-sensor" )().on( "change", function( data ) {
}
} );
+console.log( "Registering resource" );
+
// Create a new resource
iotivity.OCCreateResource(
@@ -97,6 +101,8 @@ iotivity.OCCreateResource(
iotivity.OCResourceProperty.OC_DISCOVERABLE |
iotivity.OCResourceProperty.OC_OBSERVABLE );
+console.log( "Server ready" );
+
// Exit gracefully when interrupted
process.on( "SIGINT", function() {
console.log( "SIGINT: Quitting..." );
diff --git a/js/server.presence.js b/js/server.presence.js
index 5da0b01..305d010 100644
--- a/js/server.presence.js
+++ b/js/server.presence.js
@@ -19,6 +19,8 @@ var intervalId,
sampleUri = "/a/iotivity-node-presence-sample",
iotivity = require( "iotivity-node/lowlevel" );
+console.log( "Starting OCF stack in server mode" );
+
// Start iotivity and set up the processing loop
iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
@@ -26,12 +28,14 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
-iotivity.OCSetDeviceInfo( { deviceName: "server.discoverable" } );
+iotivity.OCSetDeviceInfo( { deviceName: "server.discoverable", types: [] } );
iotivity.OCSetPlatformInfo( {
platformID: "server.discoverable.sample",
manufacturerName: "iotivity-node"
} );
+console.log( "Registering resource" );
+
// Create a new resource
iotivity.OCCreateResource(
diff --git a/lib/OicDevice.js b/lib/OicDevice.js
index 77d2c3e..2f150cb 100644
--- a/lib/OicDevice.js
+++ b/lib/OicDevice.js
@@ -16,7 +16,7 @@ var iotivity = require( "bindings" )( "iotivity" ),
_ = require( "lodash" ),
StorageHandler = require( "./StorageHandler" ),
utils = require( "./utils" ),
- OicDevice = function( role ) {
+ OicDevice = function OicDevice( role ) {
if ( !this._isOicDevice ) {
return new OicDevice( role );
}
diff --git a/lib/OicResource.js b/lib/OicResource.js
index ded932b..2a35fac 100644
--- a/lib/OicResource.js
+++ b/lib/OicResource.js
@@ -23,7 +23,7 @@ var _ = require( "lodash" ),
},
utils = require( "./utils" ),
iotivity = require( "bindings" )( "iotivity" ),
- OicResource = function( init ) {
+ OicResource = function OicResource( init ) {
if ( !this._isOicResource ) {
return new OicResource( init );
}
diff --git a/lib/OicServer.js b/lib/OicServer.js
index 7c81e96..3d8326c 100644
--- a/lib/OicServer.js
+++ b/lib/OicServer.js
@@ -18,7 +18,7 @@ var iotivity = require( "bindings" )( "iotivity" ),
util = require( "util" ),
querystring = require( "querystring" ),
_ = require( "lodash" ),
- OicRequestEvent = function() {
+ OicRequestEvent = function OicRequestEvent() {
if ( !this._isOicRequestEvent ) {
return new OicRequestEvent();
}
@@ -210,32 +210,34 @@ _.extend( devicePrototype, {
}
}
- this.dispatchEvent( oicReq.type + "request", oicReq );
+ oicReq.type += "request";
+
+ this.dispatchEvent( oicReq.type, oicReq );
return iotivity.OCEntityHandlerResult.OC_EH_OK;
}, this );
},
- registerResource: function( init ) {
+ register: function( init ) {
return new Promise( _.bind( function( fulfill, reject ) {
if ( this._info.device.role === "client" ) {
- reject( new Error( "Not supported" ) );
- return;
+ return reject( new Error( "Not supported" ) );
+ }
+
+ if ( !init.id ) {
+ return reject( new Error( "No ID found" ) );
}
var resource;
var result = 0;
- var flag = 0;
+ var flag = 0 |
+ ( init.discoverable ? iotivity.OCResourceProperty.OC_DISCOVERABLE : 0 ) |
+ ( init.observable ? iotivity.OCResourceProperty.OC_OBSERVABLE : 0 ) |
+ ( init.slow ? iotivity.OCResourceProperty.OC_SLOW : 0 ) |
+ ( init.active ? iotivity.OCResourceProperty.OC_ACTIVE : 0 ) |
+ ( init.secure ? iotivity.OCResourceProperty.OC_SECURE : 0 );
var handleReceptacle = {};
- if ( init.discoverable ) {
- flag |= iotivity.OCResourceProperty.OC_DISCOVERABLE;
- }
-
- if ( init.observable ) {
- flag |= iotivity.OCResourceProperty.OC_OBSERVABLE;
- }
-
if ( !init.id.deviceId ) {
init.id.deviceId = iotivity.OCGetServerInstanceIDString();
}
@@ -257,7 +259,7 @@ _.extend( devicePrototype, {
flag );
if ( result !== iotivity.OCStackResult.OC_STACK_OK ) {
- reject( _.extend( new Error( "registerResource: OCCreateResource() failed" ), {
+ reject( _.extend( new Error( "register: OCCreateResource() failed" ), {
result: result
} ) );
return;
@@ -270,7 +272,7 @@ _.extend( devicePrototype, {
},
- unregisterResource: function( resource ) {
+ unregister: function( resource ) {
return new Promise( _.bind( function( fulfill, reject ) {
if ( this._info.device.role === "client" ) {
reject( new Error( "Not supported" ) );
@@ -280,14 +282,14 @@ _.extend( devicePrototype, {
resourceId = resource.id.deviceId + ":" + resource.id.path;
if ( !this._resources[ resourceId ] ) {
- reject( new Error( "unregisterResource: resource not found" ) );
+ reject( new Error( "unregister: resource not found" ) );
return;
}
result = iotivity.OCDeleteResource( this._resources[ resourceId ]._handle );
if ( result !== iotivity.OCStackResult.OC_STACK_OK ) {
reject( _.extend(
- new Error( "unregisterResource: OCDeleteResource() failed" ), {
+ new Error( "unregister: OCDeleteResource() failed" ), {
result: result
} ) );
return;
diff --git a/lib/StorageHandler.js b/lib/StorageHandler.js
index 3d4afdc..9c6d682 100644
--- a/lib/StorageHandler.js
+++ b/lib/StorageHandler.js
@@ -43,7 +43,7 @@ var _ = require( "lodash" ),
}
},
path = require( "path" ),
- StorageHandler = function() {
+ StorageHandler = function StorageHandler() {
if ( !this._isStorageHandler ) {
return new StorageHandler();
}
@@ -52,8 +52,13 @@ var _ = require( "lodash" ),
var myDirectory = path.join( rootDirectory,
// We hash the absolute path to the top-level script to create the directory where we
- // store the files for this instance
- sha( "sha256" ).update( process.argv[ 1 ], "utf8" ).digest( "hex" ) );
+ // store the files for this instance. If no top level script is found, we construct a
+ // path using the current working directory and the process id.
+ sha( "sha256" )
+ .update(
+ require.main && require.main.filename ||
+ path.join( process.cwd(), ( "" + process.pid ) ), "utf8" )
+ .digest( "hex" ) );
maybeMkdirSync( rootDirectory );
maybeMkdirSync( myDirectory );
diff --git a/package.json b/package.json
index e4ac6df..f6b52cc 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "iotivity-node",
- "version": "1.1.0-2",
+ "version": "1.1.0-3",
"description": "IoTivity bindings",
"repository": "https://github.com/otcshare/iotivity-node/",
"license": "Apache-2.0",
@@ -34,6 +34,7 @@
"grunt-jscs": "^2.1.0",
"load-grunt-config": "^0.17.2",
"load-grunt-tasks": "^3.2.0",
+ "ocf-test-suite": "https://github.com/gabrielschulhof/ocf-test-suite.git",
"qunitjs": "^1.18.0",
"shelljs": "^0.5.3",
"uuid": "^2.0.1"
diff --git a/spec/iot-js-spec.md b/spec/iot-js-spec.md
deleted file mode 100644
index 90721e0..0000000
--- a/spec/iot-js-spec.md
+++ /dev/null
@@ -1,481 +0,0 @@
-IoT Web API
-===========
-
-Abstract
---------
-This document presents a JavaScript API based on the [OIC](http://www.openinterconnect.org/)
-[Core Specification](http://openinterconnect.org/developer-resources/specs/), and the C and [C++](https://api-docs.iotivity.org/latest/index.html) API of the [IoTivity](https://www.iotivity.org/) project.
-
-Introduction
-------------
-**IoT** (Internet of Things) is the name given for the complex environment in which diverse *resources*, implemented in *devices*, can be accessed remotely, and can notify subscribers with data and state changes. The resources act as servers, and communication with them may involve different protocols. Therefore, resources may also be represented by devices which translate between resource-specific and standard protocols. These devices are called *gateways*, or OIC intermediary devices.
-
-Standardization is done by the [OIC](http://www.openinterconnect.org/) (Open Interconnect Consortium), which currently specifies:
-
- - the Core Framework for OIC core architecture, interfaces, protocols and services to enable OIC profiles implementation for IoT usages
-
- - Application Profiles Specification documents specify the OIC profiles to enable IoT usages for different market segments such as home, industrial, healthcare, and automotive.
-
-Multiple providers/solutions can share a physical hardware *platform*.
-A platform may host multiple physical or virtual *devices*.
-Devices run the OIC software stack, and are addressable endpoints of communication. A device hosts multiple physical or virtual *resources*.
-A resource represents *sensors* and *actuators*.
-A given sensor or actuator may be represented by multiple properties. A read-only property in a resource belongs to a sensor input, whereas a read-write property belongs to the state of an actuator.
-
-The devices support for resources can be extended via installable software modules called *applications*.
-
-This API enables writing the applications that implement resources and business logic.
-
-OIC high level Web API design notes
------------------------------------
-The API design starts minimal, solves the use cases relevant to JS developers, and gets expanded on demand.
-
-Code using this API is deployed to a device, which has one or more resources. In this version of the API it is assumed that the execution context of the code is separated for each device.
-
-Therefore the **API entry point** is an object that exposes the local device functionality, and can be requested with a ```require``` statement which invokes the constructor. When the object is garbage collected, the implementations should clean up native state.
-
-**Device identification** is UUID. Each device has an associated address + port.
-
-When a device is constructed, the implementation should announce its presence.
-Adding an event listener to the 'devicefound' event should turn on presence observing, i.e. the API implementation should make a request to watch presence notifications, and fire a 'devicefound' event when a presence notification is received.
-
-**Resource identification** is URL path, relative to a given device.
-
-On each device there are special resources, implementing device discovery, resource discovery, platform discovery, etc. Platform needs to be discoverable on a resource with a fixed URI ```/oic/p```, device on ```/oic/d``` and resources on ```/oic/res```. This API encapsulates these special resources and the hardcoded/fixed URIs by explicit function names and parameters.
-
-**Device discovery** uses endpoint discovery: multicast request "GET /oic/res" to "All CoAP nodes" (```224.0.1.187``` for IPv4 and ```FF0X::FD``` for IPv6, port 5683). The response lists devices and their resources (at least URI, resource type, interfaces, and media types). Since this is basically a resource discovery, it is merged with resource discovery.
-
-**Resource discovery** is based on the existence of resources (directories) set up for discovery. It can be achieved in 3 ways:
-- direct discovery through peer inquiry (unicast or multicast)
-- indirect discovery based on a 3rd party directory (a server for resource discovery)
-- presence advertisment: the resource enabling discovery is local to the initiator, and it is maintained by presence notifications.
-
-Implementations should encapsulate the resource discovery type, and should map the DiscoveryOptions values to the best suited protocol request(s).
-
-In this API the OIC request (query) options and header options are also encapsulated. When they convey functionality, they are exposed through explicit properties and parameters.
-
-Implementations should support automatic notifications for changed resources that have observers. However, a "manual" notify API is also exposed on the OicServer interface, for experimental purpose.
-
-Web IDL of the JavaScript API
------------------------------
-
-This API uses [Promises](http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects).
-
-### OIC Stack
-The API entry point is the local OIC stack executed on an OIC device. Multiple devices may be run on a given hardware platform, each having different network address, UUID and resources.
-
-When the constructor is invoked without parameters, the device is started in the default (server) role.
-```javascript
-var oic = require('oic');
-```
-If the OIC functionality is forced in client-only mode, the ```OicServer``` API is not available on it (all server methods fail with ```NotSupportedError```).
-```javascript
-var oic = require('oic')('client');
-```
-
-The ```require()``` call returns an ```OIC``` object initialized with the local device and platform information.
-
-The OIC object contains functionality to read device and platform information, discover remote devices and resources, add and remove local resources, create, retrieve, update and delete remote resources.
-```javascript
-enum OicRole { "client", "server" };
-
-[Constructor(optional OicRole role = "server")]
-interface OIC: EventTarget {
- readonly attribute OicDevice device; // getter for local device info
- readonly attribute OicPlatform platform; // getter for local platform info
-};
-```
-All the following interfaces are included in OIC, but are described separately.
-```javascript
-OIC implements OicServer;
-OIC implements OicClient;
-OIC implements OicDiscovery;
-OIC implements OicPresence;
-```
-The following information is exposed on the local ```/oic/d``` (device) resource.
-```javascript
-[NoInterfaceObject]
-interface OicDevice {
- readonly attribute USVString uuid;
- readonly attribute USVString url; // host:port
- readonly attribute DOMString name;
- readonly attribute sequence<DOMString> dataModels;
- // list of <vertical>.major.minor, e.g. vertical = “Smart Home”
- readonly attribute DOMString coreSpecVersion; // core.<major>.<minor>
- readonly attribute OicRole role;
- // setters may be supported later
-};
-```
-The following information is exposed on the local ```/oic/p``` (platform) resource.
-```javascript
-[NoInterfaceObject]
-interface OicPlatform {
- readonly attribute DOMString id;
- readonly attribute DOMString osVersion;
- readonly attribute DOMString model;
- readonly attribute DOMString manufacturerName;
- readonly attribute USVString manufacturerUrl;
- readonly attribute Date manufactureDate;
- readonly attribute DOMString platformVersion;
- readonly attribute DOMString firmwareVersion;
- readonly attribute USVString supportUrl;
- // setters may be supported later
-};
-```
-
-### OIC Resource
-The resources are identified by a device UUID and a resource path relative to that device.
-```javascript
-dictionary OicResourceId {
- USVString deviceId; // UUID
- USVString path; // resource path (short form)
-};
-```
-The properties of an OIC resource used in the application data model are represented as a JSON-serializable dictionary, which contains a snapshot of the custom properties of a resource, together with the linked resources.
-```javascript
-dictionary OicResourceRepresentation {
- // DateTime timestamp;
- // other properties
-};
-```
-The OIC resources are represented as follows.
-```javascript
-dictionary OicResourceInit {
- OicResourceId id;
- sequence<DOMString> resourceTypes;
- sequence<DOMString> interfaces;
- sequence<DOMString> mediaTypes;
- boolean discoverable;
- boolean observable;
- boolean secure;
- boolean slow;
- OicResourceRepresentation properties;
- sequence<OicResourceId> links;
-};
-
-[NoInterfaceObject]
-interface OicResource: EventTarget {
- // gets the properties of OicResourceInit, all read-only
- readonly attribute ResourceId id;
- readonly attribute sequence<DOMString> resourceTypes;
- readonly attribute sequence<DOMString> interfaces;
- readonly attribute sequence<DOMString> mediaTypes;
- readonly attribute boolean discoverable;
- readonly attribute boolean observable;
- readonly attribute boolean slow;
- readonly attribute OicResourceRepresentation properties;
- readonly attribute sequence<OicResourceId> links; // for resource hierarchies
-
- attribute EventHandler<OicResourceUpdateEvent> onupdate;
- attribute EventHandler ondelete; // simple event
-};
-
-interface OicResourceUpdateEvent: Event {
- readonly attribute OicResourceInit updates; // partial dictionary
-};
-```
-The ```OicResource``` objects can be created only by ```findResources()```.
-
-Adding the first event listener to ```onupdate``` should send an observation request.
-
-Removing the last event listener from ```onupdate``` should send an observation cancellation request.
-
-An ```OicResourceUpdateEvent``` contains a partial dictionary which describes the changed properties of the resource. Implementations should fire this event only if at least ```id``` and one more property are specified.
-
-### Discovery
-Discovery is exposed by the following interface:
-```javascript
-[NoInterfaceObject]
-interface OicDiscovery: EventTarget {
- // resource discovery: fire 'resourcefound' events on results
- Promise<void> findResources(optional OicDiscoveryOptions options);
-
- // get device info of a given remote device, using unicast
- // id is either a device UUID or a URL (host:port)
- Promise<OicDevice> getDeviceInfo(USVString id);
-
- // get platform info of a given remote device, using unicast
- Promise<OicPlatform> getPlatformInfo(USVString id);
-
- // multicast device discovery
- Promise<void> findDevices(); // fire a 'devicefound' event for each found
-
- attribute EventHandler<OicResourceEvent> onresourcefound;
- attribute EventHandler<OicDeviceEvent> ondevicefound;
- attribute EventHandler<OicErrorEvent> ondiscoveryerror;
-}
-
-dictionary OicDiscoveryOptions {
- USVString deviceId; // if provided, make direct discovery
- DOMString resourceType; // if provided, include this in the discovery request
- USVString resourcePath; // if provided, filter the results locally
- // timeout could be included later, if needed
- // unsigned long long timeout = Infinity; // in ms
-};
-
-interface OicResourceEvent : Event {
- readonly attribute OicResource resource;
-};
-
-interface OicDeviceEvent : Event {
- readonly attribute OicDevice device;
-};
-```
-When the ```findResources()``` method is invoked, run the following steps:
-- Return a Promise object ```promise``` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
-- If the functionality is not supported, reject ```promise``` with ```NotSupportedError```.
-- If there is no permission to use the method, reject ```promise``` with ```SecurityError```.
-- Configure a discovery request on resources as follows:
- - If ```options.resourcePath``` is specified, filter results locally.
- - If ```options.deviceId``` is specified, make a direct discovery request to that device
- - If ```options.resourceType``` is specified, include it as the ```rt``` parameter in a new endpoint multicast discovery request ```GET /oic/res``` to "All CoAP nodes" (```224.0.1.187``` for IPv4 and ```FF0X::FD``` for IPv6, port ```5683```).
-- If sending the request fails, reject the Promise with ```"NetworkError"```, otherwise resolve the Promise.
-- When a resource is discovered, fire an ```onresourcefound``` event with an ```OicResourceEvent``` structure, containing an ```OicResource``` object created from the received information.
-- If there is an error during the discovery protocol, fire a ```discoveryerror``` event on the device with that error.
-
-When the ```findDevices()``` method is invoked, run the following steps:
-- Return a Promise object ```promise``` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
-- If the functionality is not supported, reject ```promise``` with ```NotSupportedError```.
-- If there is no permission to use the method, reject ```promise``` with ```SecurityError```.
-- Send a multicast request for retrieving ```/oic/d``` and wait for the answer.
-- If the sending the request fails, reject the Promise with ```"NetworkError"```, otherwise resolve the Promise.
-- If there is an error during the discovery protocol, fire a ```discoveryerror``` event on the device with that error.
-- When a device information is discovered, fire a ```deviceinfo``` event with an ```OicDeviceEvent``` structure, containing an ```OicDevice``` object.
-
-When the ```getDeviceInfo(id)``` method is invoked, run the following steps:
-- Return a Promise object ```promise``` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
-- If the functionality is not supported, reject ```promise``` with ```NotSupportedError```.
-- If there is no permission to use the method, reject ```promise``` with ```SecurityError```.
-- Send a direct discovery request ```GET /oic/d``` with the given id (which can be either a device UUID or a device URL, and wait for the answer.
-- If there is an error during the request, reject ```promise``` with that error.
-- When the answer is received, resolve ```promise``` with an ```OicDevice``` object created from the response.
-
-When the ```getPlatformInfo(id)``` method is invoked, run the following steps:
-- Return a Promise object ```promise``` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
-- If the functionality is not supported, reject ```promise``` with ```NotSupportedError```.
-- If there is no permission to use the method, reject ```promise``` with ```SecurityError```.
-- Send a direct discovery request ```GET /oic/p``` with the given id (which can be either a device UUID or a device URL, and wait for the answer.
-- If there is an error during the request, reject ```promise``` with that error.
-- When the answer is received, resolve ```promise``` with an ```OicPlatform``` object created from the response.
-
-### OIC Presence
-The client API for accessing OIC Presence functionality.
-```javascript
-[NoInterfaceObject]
-interface OicPresence: EventTarget {
- Promise<void> subscribe(optional USVString url);
- Promise<void> unsubscribe(optional USVString url);
- attribute EventHandler<OicDeviceChangeEvent> ondevicechange;
-};
-
-// event received for device presence notifications
-interface OicDeviceChangeEvent : Event {
- readonly attribute OicChangeType type;
- readonly attribute OicDevice device;
-};
-
-enum OicChangeType { "added", "deleted", "changed" };
-```
-When the ```subscribe()``` method is invoked, turn on presence listening for the specified ```deviceId```, or if it is not specified, for any device. The Promise may be rejected with ```NotSupportedError```.
-
-### OIC Client
-The OIC Client API provides functionality to access (CRUD) remote resources.
-```javascript
-[NoInterfaceObject]
-interface OicClient {
- Promise<OicResource> create(OicResourceInit resource);
- Promise<void> retrieve(OicResourceId id, optional Dictionary parameters);
- Promise<void> update(OicResourceInit resource); // partial dictionary
- Promise<void> delete(OicResourceId id);
-};
-```
-The ```create()``` and ```update()``` methods take a resource dictionary, in which at least the ```id``` and one more property MUST be specified.
-
-The ```retrieve()``` method can take an optional parameter representing the ```REST``` query parameters passed along with the ```GET``` request as a JSON-serializable dictionary. Implementations SHOULD validate this client input to fit OIC requirements. The semantics of the parameters are application specific (e.g. requesting a resource representation in metric or imperial units). Similarly, the properties of an OIC resource representation are application specific and are represented as a JSON-serializable dictionary.
-
-### OIC Server
-The server API provides functionality for handling requests.
-```javascript
-[NoInterfaceObject]
-interface OicServer: EventTarget {
- Promise<OicResource> register(OicResourceInit resource);
- Promise<void> unregister(OicResourceId id);
-
- // handle CRUDN requests from clients
- attribute EventHandler<OicRequestEvent> onobserverequest;
- attribute EventHandler<OicRequestEvent> onunobserverequest;
- attribute EventHandler<OicRequestEvent> onretrieverequest;
- attribute EventHandler<OicRequestEvent> ondeleterequest;
- attribute EventHandler<OicResourceEvent> onupdaterequest;
- attribute EventHandler<OicResourceEvent> oncreaterequest;
-
- // update notification could be done automatically in most cases,
- // but in a few cases manual notification is needed
- Promise<void> notify(OicResourceInit resource);
- // delete notifications should be made automatic by implementations
-
- // enable/disable presence for this device
- Promise<void> enablePresence(optional unsigned long long ttl); // in ms
- Promise<void> disablePresence();
-};
-
-interface OicRequestEvent : Event {
- readonly attribute OicResourceId source;
- readonly attribute OicResourceId target;
-
- Promise<void> sendResponse(optional OicResource? resource);
- // reuses request info (type, requestId, source, target) to construct response,
- // sends back “ok”, plus the resource object if applicable
-
- Promise<void> sendError(DOMString? name,
- optional DOMString? message,
- optional OicResourceInit resource);
- // reuses request info (type, requestId, source, target) to construct response,
-};
-
-interface OicResourceEvent : OicRequestEvent {
- readonly attribute OicResourceInit resource;
-};
-```
-
-### Error handling
-Errors are reported using ```OicError``` objects, which extend [Error](http://www.ecma-international.org/ecma-262/6.0/#sec-error-objects) with OIC specific information.
-```javascript
-interface OicError: Error {
- readonly attribute USVString? deviceId;
- readonly attribute OicResourceInit? resource;
-};
-```
-The error names map to [DOMError](https://heycam.github.io/webidl/#idl-DOMException-error-names). The following error names may be used when rejecting Promises: ```NotSupportedError```, ```SecurityError```, ```TimeoutError```, ```NotFoundError```, ```NoModificationAllowedError```, ```InvalidModificationError```, ```TypeMismatchError```, ```InvalidStateError```, ```InvalidAccessError```, ```InvalidNodeTypeError```, ```NotReadableError```, ```IndexSizeError```, ```DataCloneError```.
-
-The following error event is used for protocol errors:
-```javascript
-interface OicErrorEvent: Event {
- OicError error;
-};
-```
-
-Code Examples
--------------
-### Getting device configuration
-
-```javascript
-var oic = require('oic');
-if (oic.device.uuid) { // configuration is valid
- startServer();
- startClient();
-} else {
- console.log("Error: device is not configured.");
-}
-```
-
-### OIC Client contolling a remote red LED.
-```javascript
-// Discover a remote red light, start observing it, and make sure it's not too bright.
-var red = null;
-function startClient() {
- // discover resources
- oic.onresourcefound = function(event) {
- if(event.resource && event.resource.id.path == "/light/ambience/red") {
- red = event.resource;
- red.addEventListener('update', redHandler);
- }
- }
- oic.findResources({ resourceType: “oic.r.light” })
- .then( () => { console.log("Resource discovery started.");})
- .catch((e) => {
- console.log("Error finding resources: " + e.message);
- });
-};
-
-function redHandler(red, updates) {
- console.log("Update received on " + red.id);
- console.lof("Running local business logic to determine further actions...");
- if (red && red.properties.dimmer > 0.5) {
- // do something, e.g. limit output
- oic.update({ id: red.id, properties.dimmer: 0.5 })
- .then(() => { console.log("Changed red light dimmer"); })
- .catch((e) => { console.log("Error changing red light"); });
- }
-};
-```
-
-### OIC Server exposing a local blue LED.
-
-```javascript
-var lightResource = null;
-function startServer() {
- // register the specific resources handled by this solution
- // which are not exposed by the device firmware
- oic.registerResource({
- id: { deviceId: oic.device.uuid; path: "/light/ambience/blue" },
- resourceTypes: [ "light" ],
- interfaces: [ "/oic/if/rw" ],
- discoverable: true,
- observable: true,
- properties: { color: "blue", dimmer: 0.2 }
- }).then((res) => {
- console.log("Local resource " + res.id.path + " has been registered.");
- lightResource = res;
- oic.addEventListener("updaterequest", onLightUpdate);
- oic.addEventListener("observerequest", onLightObserve);
- oic.addEventListener("deleterequest", onLightDelete);
- oic.addEventListener("retrieverequest", onLightRetrieve);
- oic.addEventListener("createrequest", onLightCreate);
- }
- }).catch((error) => {
- console.log("Error creating resource " + error.resource.id.path + " : " + error.message);
- });
-};
-
-function onLightRetrieve(event) {
- if (event.target.id.path == lightResource.id.path) {
- event.sendResponse(lightResource)
- .catch( (err) => {
- console.log("Error sending retrieve response.");
- });
- } else {
- event.sendError("NotFoundError", "", event.resource);
- .catch( (err) => {
- console.log("Error sending retrieve error response.");
- });
- }
-};
-
-function onLightUpdate(event) {
- // the implementation has by now updated this resource (lightResource)
- // this is a hook to update the business logic
- console.log("Resource " + event.target + " updated. Running the update hook.");
- // after local processing, do the notifications manually
- oic.notify(lightResource)
- .then( () => { console.log("Update notification sent.");})
- .catch( (err) => {
- console.log("No observers or error sending: " + err.name);
- });
-};
-
-function onLightObserve(event) {
- console.log("Resource " + event.target + " observed by " + event.source + ".");
- if (event.target.id.path == lightResource.id.path) {
- event.sendResponse(lightResource)
- .catch( (err) => {
- console.log("Error sending observe response.");
- });
- }
-};
-
-function onLightDelete(event) {
- console.log("Resource " + event.target + " has been requested to be deleted.");
- console.log("Running the delete hook.");
- // clean up local state
- // notification about deletion is automatic
- event.sendResponse()
- .catch( (err) => {
- console.log("Error sending delete response.");
- });
-};
-
-function onLightCreate(event) {
- event.sendError("NotSupportedError", "", event.resource);
-}
-```
diff --git a/tests/tests/API Complex Payload/server.js b/tests/tests/API Complex Payload/server.js
index ec079b5..325bf23 100644
--- a/tests/tests/API Complex Payload/server.js
+++ b/tests/tests/API Complex Payload/server.js
@@ -37,7 +37,7 @@ async.series( [
// Create resource and attach retrieve handler
function( callback ) {
- device.registerResource( {
+ device.register( {
id: { path: "/a/" + uuid },
discoverable: true,
observable: true,
@@ -57,7 +57,7 @@ async.series( [
fulfill();
}
};
- testUtils.assert( "strictEqual", request.type, "retrieve",
+ testUtils.assert( "strictEqual", request.type, "retrieverequest",
"Client: First event is 'retrieve'" );
request.sendResponse( _.extend( theResource, {
properties: {
@@ -97,7 +97,7 @@ async.series( [
}
};
- testUtils.assert( "strictEqual", request.type, "update",
+ testUtils.assert( "strictEqual", request.type, "updaterequest",
"Client: Second event is 'update'" );
testUtils.assert( "deepEqual", request.res, {
diff --git a/tests/tests/API Create Delete/server.js b/tests/tests/API Create Delete/server.js
index 65a6b27..e9c93ca 100644
--- a/tests/tests/API Create Delete/server.js
+++ b/tests/tests/API Create Delete/server.js
@@ -21,8 +21,8 @@ var resource,
console.log( JSON.stringify( { assertionCount: 5 } ) );
async.series( [
- function registerResource( callback ) {
- device.registerResource( {
+ function register( callback ) {
+ device.register( {
id: {
path: "/a/" + uuid
},
@@ -44,12 +44,12 @@ async.series( [
requestHandler = function( request ) {
switch ( requestIndex ) {
- // Both the initial "create" request and the subsequent duplicate "create"
- // request are handled by the same code. The expected behaviour is asserted by
- // the client.
+ // Both the initial "createrequest" event and the subsequent duplicate
+ // "createrequest" event are handled by the same code. The expected behaviour is
+ // asserted by the client.
case 0:
case 1:
- utils.assert( "strictEqual", request.type, "create",
+ utils.assert( "strictEqual", request.type, "createrequest",
"Server: " + ( requestIndex === 0 ? "First" : "Second" ) +
" request is 'create'" );
utils.assert( "deepEqual", request.res, {
@@ -64,7 +64,7 @@ async.series( [
someKey: "someValue"
}
}, "Server: Resource signature is as expected" );
- device.registerResource( request.res ).then(
+ device.register( request.res ).then(
function( theResource ) {
resource = theResource;
request.sendResponse( null ).catch( done );
@@ -75,9 +75,9 @@ async.series( [
break;
case 2:
- utils.assert( "strictEqual", request.type, "delete",
+ utils.assert( "strictEqual", request.type, "deleterequest",
"Server: Third request is 'delete'" );
- device.unregisterResource( resource ).then(
+ device.unregister( resource ).then(
function() {
request.sendResponse( null ).then( done, done );
},
diff --git a/tests/tests/API Device ID Persistence.js b/tests/tests/API Device ID Persistence.js
index 75e65a4..fa28c6a 100644
--- a/tests/tests/API Device ID Persistence.js
+++ b/tests/tests/API Device ID Persistence.js
@@ -19,7 +19,7 @@ function runAsServer() {
var device = require( "../../index" )( "server" );
process.on( "SIGINT", function() {
- device.unregisterResource( resource ).then(
+ device.unregister( resource ).then(
function() {
process.exit( 0 );
},
@@ -28,7 +28,7 @@ function runAsServer() {
} );
} );
- device.registerResource( {
+ device.register( {
id: { path: "/a/" + process.argv[ 3 ] },
discoverable: true,
resourceTypes: [ "core.light" ],
diff --git a/tests/tests/API Device Information/server.js b/tests/tests/API Device Information/server.js
index d6ffef9..ec0fddf 100644
--- a/tests/tests/API Device Information/server.js
+++ b/tests/tests/API Device Information/server.js
@@ -84,7 +84,7 @@ utils.assert( "strictEqual", theError ? {
null,
"Server: Setting the platform info succeeded" );
-oic.registerResource( {
+oic.register( {
id: { path: "/a/" + uuid },
resourceTypes: [ "core.light" ],
interfaces: [ "oic.if.baseline" ],
@@ -100,7 +100,7 @@ oic.registerResource( {
} );
process.on( "SIGINT", function() {
- oic.unregisterResource( theResource ).then(
+ oic.unregister( theResource ).then(
function() {
process.exit( 0 );
},
diff --git a/tests/tests/API Device Rediscovery.js b/tests/tests/API Device Rediscovery.js
index a1f8b0c..21dd323 100644
--- a/tests/tests/API Device Rediscovery.js
+++ b/tests/tests/API Device Rediscovery.js
@@ -156,21 +156,21 @@ function runAsServer() {
JSON.stringify( error ) );
} );
} else {
- device.unregisterResource( theResource ).then(
+ device.unregister( theResource ).then(
function() {
- testUtils.assert( "ok", true, "Server: unregisterResource() was successful" );
+ testUtils.assert( "ok", true, "Server: unregister() was successful" );
process.exit( 0 );
},
function( error ) {
- testUtils.die( "Server: unregisterResource failed with error: " +
+ testUtils.die( "Server: unregister failed with error: " +
JSON.stringify( error ) );
} );
}
} );
async.series( [
- function registerResource( callback ) {
- device.registerResource( {
+ function register( callback ) {
+ device.register( {
id: { path: "/a/" + process.argv[ 3 ] },
interfaces: [ "oic.if.baseline" ],
resourceTypes: [ "core.light" ],
@@ -178,7 +178,7 @@ function runAsServer() {
} ).then(
function( resource ) {
theResource = resource;
- testUtils.assert( "ok", true, "Server: registerResource() was successful" );
+ testUtils.assert( "ok", true, "Server: register() was successful" );
callback();
}, callback );
},
diff --git a/tests/tests/API Discovery/server.js b/tests/tests/API Discovery/server.js
index 65ca328..bdd9abe 100644
--- a/tests/tests/API Discovery/server.js
+++ b/tests/tests/API Discovery/server.js
@@ -21,7 +21,7 @@ console.log( JSON.stringify( { assertionCount: 3 } ) );
utils.assert( "ok", true, "Server: device configured successfully" );
-device.registerResource( {
+device.register( {
id: { path: "/a/" + uuid },
deviceId: uuid,
resourceTypes: [ "core.light" ],
@@ -31,26 +31,26 @@ device.registerResource( {
} ).then(
function( resource ) {
theResource = resource;
- utils.assert( "ok", true, "Server: device.registerResource() successful" );
+ utils.assert( "ok", true, "Server: device.register() successful" );
// Signal to the test suite that we're ready for the client
console.log( JSON.stringify( { ready: true } ) );
},
function( error ) {
utils.assert( "ok", false,
- "Server: device.registerResource() failed with: " + error );
+ "Server: device.register() failed with: " + error );
} );
// Cleanup on SIGINT
process.on( "SIGINT", function() {
- device.unregisterResource( theResource ).then(
+ device.unregister( theResource ).then(
function() {
- utils.assert( "ok", true, "Server: device.unregisterResource() successful" );
+ utils.assert( "ok", true, "Server: device.unregister() successful" );
process.exit( 0 );
},
function( error ) {
utils.assert( "ok", false,
- "Server: device.unregisterResource() failed with: " + error );
+ "Server: device.unregister() failed with: " + error );
process.exit( 0 );
} );
} );
diff --git a/tests/tests/API Error Propagation/server.js b/tests/tests/API Error Propagation/server.js
index 0ea62c2..05b52a3 100644
--- a/tests/tests/API Error Propagation/server.js
+++ b/tests/tests/API Error Propagation/server.js
@@ -23,7 +23,7 @@ console.log( JSON.stringify( { assertionCount: 2 } ) );
async.series( [
function registerTheResource( callback ) {
- device.registerResource( {
+ device.register( {
id: { path: "/a/" + uuid },
resourceTypes: [ "core.light" ],
interfaces: [ "oic.if.baseline" ],
@@ -36,7 +36,10 @@ async.series( [
},
function handleRequests( callback ) {
- var requestTypes = [ "create", "delete", "update", "retrieve", "observe", "unobserve" ],
+ var requestTypes = [
+ "create", "delete", "update",
+ "retrieve", "observe", "unobserve"
+ ],
requestCount = 0,
requestSequence = [],
teardown,
@@ -78,13 +81,13 @@ async.series( [
// Cleanup on SIGINT
process.on( "SIGINT", function() {
- device.unregisterResource( theResource ).then(
+ device.unregister( theResource ).then(
function() {
- utils.assert( "ok", true, "Server: device.unregisterResource() successful" );
+ utils.assert( "ok", true, "Server: device.unregister() successful" );
process.exit( 0 );
},
function( error ) {
- utils.die( "Server: device.unregisterResource() failed with: " + error +
+ utils.die( "Server: device.unregister() failed with: " + error +
" and result " + error.result );
process.exit( 0 );
} );
diff --git a/tests/tests/API Observation/server.js b/tests/tests/API Observation/server.js
index eeee006..d65accc 100644
--- a/tests/tests/API Observation/server.js
+++ b/tests/tests/API Observation/server.js
@@ -29,7 +29,7 @@ function cleanup() {
}
function lightResourceOnRequest( request ) {
- if ( request.type === "retrieve" || request.type === "observe" ) {
+ if ( request.type === "retrieverequest" || request.type === "observerequest" ) {
request.sendResponse( null );
}
}
@@ -58,7 +58,7 @@ function assertNotifyFailure() {
utils.assert( "ok", true, "device configured successfully" );
-device.registerResource( {
+device.register( {
id: { path: "/a/" + uuid },
deviceId: uuid,
resourceTypes: [ "core.light" ],
@@ -68,7 +68,7 @@ device.registerResource( {
properties: { increment: 0 }
} ).then(
function( resource ) {
- utils.assert( "ok", true, "registerResource() successful" );
+ utils.assert( "ok", true, "register() successful" );
lightResource = resource;
device.addEventListener( "retrieverequest", lightResourceOnRequest );
device.addEventListener( "observerequest", lightResourceOnRequest );
@@ -76,7 +76,7 @@ device.registerResource( {
console.log( JSON.stringify( { ready: true } ) );
},
function( error ) {
- utils.die( "registerResource() failed with " + error +
+ utils.die( "register() failed with " + error +
" and result " + error.result );
} );
diff --git a/tests/tests/API Presence/server.js b/tests/tests/API Presence/server.js
index 2aa3fee..e93cf67 100644
--- a/tests/tests/API Presence/server.js
+++ b/tests/tests/API Presence/server.js
@@ -55,7 +55,7 @@ device.addEventListener( "updaterequest", function( request ) {
device.enablePresence().then(
function() {
- device.registerResource( {
+ device.register( {
id: { path: "/a/" + uuid },
deviceId: uuid,
resourceTypes: [ "core.light" ],
@@ -65,14 +65,14 @@ device.enablePresence().then(
} ).then(
function( resource ) {
theResource = resource;
- utils.assert( "ok", true, "Server: device.registerResource() successful" );
+ utils.assert( "ok", true, "Server: device.register() successful" );
// Signal to the test suite that we're ready for the client
console.log( JSON.stringify( { ready: true } ) );
},
function( error ) {
utils.assert( "ok", false,
- "Server: device.registerResource() failed with: " + error );
+ "Server: device.register() failed with: " + error );
} );
}, function( error ) {
utils.assert( "ok", false,
@@ -81,14 +81,14 @@ device.enablePresence().then(
// Cleanup on SIGINT
process.on( "SIGINT", function() {
- device.unregisterResource( theResource ).then(
+ device.unregister( theResource ).then(
function() {
- utils.assert( "ok", true, "Server: device.unregisterResource() successful" );
+ utils.assert( "ok", true, "Server: device.unregister() successful" );
process.exit( 0 );
},
function( error ) {
utils.assert( "ok", false,
- "Server: device.unregisterResource() failed with: " + error );
+ "Server: device.unregister() failed with: " + error );
process.exit( 0 );
} );
} );
diff --git a/tests/tests/API Query Parameters/server.js b/tests/tests/API Query Parameters/server.js
index 96e02ad..2f25c0e 100644
--- a/tests/tests/API Query Parameters/server.js
+++ b/tests/tests/API Query Parameters/server.js
@@ -31,8 +31,9 @@ function die( message ) {
}
function resourceOnRequest( request ) {
- utils.assert( "strictEqual", request.type, "retrieve", "Server: Request is of type retrieve" );
- if ( request.type === "retrieve" ) {
+ utils.assert( "strictEqual", request.type, "retrieverequest",
+ "Server: Request is of type retrieve" );
+ if ( request.type === "retrieverequest" ) {
request.sendResponse( _.extend( {}, request.target, {
properties: {
"How many angels can dance on the head of a pin?":
@@ -42,7 +43,7 @@ function resourceOnRequest( request ) {
}
}
-device.registerResource( {
+device.register( {
id: { path: "/a/" + uuid },
resourceTypes: [ "core.light" ],
interfaces: [ "oic.if.baseline" ],
@@ -54,7 +55,7 @@ device.registerResource( {
function( resource ) {
device.addEventListener( "retrieverequest", resourceOnRequest );
process.on( "SIGINT", function() {
- device.unregisterResource( resource ).catch( die( "Failed to unregister resource" ) );
+ device.unregister( resource ).catch( die( "Failed to unregister resource" ) );
process.exit( 0 );
} );
console.log( JSON.stringify( { ready: true } ) );
diff --git a/tests/tests/API Register Resource.js b/tests/tests/API Register Resource.js
deleted file mode 100644
index cf847a2..0000000
--- a/tests/tests/API Register Resource.js
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2016 Intel Corporation
-//
-// 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.
-
-var testUtils = require( "../assert-to-console" );
-
-console.log( JSON.stringify( { assertionCount: 1 } ) );
-
-var device = require( "../../index" )( "server" );
-
-if ( device.device.uuid ) {
- var deviceId = device.device.uuid;
-
- device.registerResource( {
- id: { path: "/light/ambience/blue" },
- deviceId: deviceId,
- resourceTypes: [ "core.light" ],
- interfaces: [ "oic.if.baseline" ],
- discoverable: true,
- observable: true,
- properties: { color: "light-blue", dimmer: 0.2 }
- } ).then(
- function() {
- testUtils.assert( "ok", true, "Resource registered successfully" );
- process.exit( 0 );
- },
- function( error ) {
- testUtils.assert( "ok", false,
- "Resource not registered, error with code: " + error.result );
- process.exit( 0 );
- } );
-}
diff --git a/tests/tests/API Retrieve/server.js b/tests/tests/API Retrieve/server.js
index ebb1749..96a711f 100644
--- a/tests/tests/API Retrieve/server.js
+++ b/tests/tests/API Retrieve/server.js
@@ -22,22 +22,23 @@ console.log( JSON.stringify( { assertionCount: 8 } ) );
function resourceOnRequest( request ) {
totalRequests++;
- utils.assert( "strictEqual", request.type, "retrieve", "Server: Request is of type retrieve" );
- if ( request.type === "retrieve" ) {
+ utils.assert( "strictEqual", request.type, "retrieverequest",
+ "Server: Request is of type retrieve" );
+ if ( request.type === "retrieverequest" ) {
if ( totalRequests === 1 ) {
request.sendResponse( request.target ).then(
function() {
utils.assert( "ok", true,
"Server: Successfully responded to retrieve request" );
- device.unregisterResource( theResource ).then(
+ device.unregister( theResource ).then(
function() {
utils.assert( "ok", true,
- "Server: device.unregisterResource() successful" );
+ "Server: device.unregister() successful" );
theResource = null;
},
function( error ) {
utils.die(
- "Server: device.unregisterResource() failed with: " + error +
+ "Server: device.unregister() failed with: " + error +
" and result " + error.result );
} );
},
@@ -61,7 +62,7 @@ function resourceOnRequest( request ) {
utils.assert( "ok", true, "Server: device.configure() successful" );
-device.registerResource( {
+device.register( {
id: { path: "/a/" + uuid },
resourceTypes: [ "core.light" ],
interfaces: [ "oic.if.baseline" ],
@@ -72,14 +73,14 @@ device.registerResource( {
} ).then(
function( resource ) {
theResource = resource;
- utils.assert( "ok", true, "Server: device.registerResource() successful" );
+ utils.assert( "ok", true, "Server: device.register() successful" );
device.addEventListener( "retrieverequest", resourceOnRequest );
// Signal to the test suite that we're ready for the client
console.log( JSON.stringify( { ready: true } ) );
},
function( error ) {
- utils.die( "Server: device.registerResource() failed with: " + error +
+ utils.die( "Server: device.register() failed with: " + error +
" and result " + error.result );
} );
diff --git a/tests/tests/API Start Stack.js b/tests/tests/API Start Stack.js
deleted file mode 100644
index 4da7489..0000000
--- a/tests/tests/API Start Stack.js
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2016 Intel Corporation
-//
-// 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.
-
-var testUtils = require( "../assert-to-console" );
-var theError = null;
-
-console.log( JSON.stringify( { assertionCount: 1 } ) );
-
-try {
- require( "../../index" )();
-} catch ( anError ) {
- theError = anError;
-}
-
-testUtils.assert( "deepEqual", theError, null, "Stack started successfully" );
-
-process.exit( 0 );
diff --git a/tests/tests/API Unregister Resource.js b/tests/tests/API Unregister Resource.js
deleted file mode 100644
index 5f85546..0000000
--- a/tests/tests/API Unregister Resource.js
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2016 Intel Corporation
-//
-// 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.
-
-var testUtils = require( "../assert-to-console" );
-
-console.log( JSON.stringify( { assertionCount: 1 } ) );
-
-var device = require( "../../index" )( "server" );
-
-if ( device.device.uuid ) {
- var deviceId = device.device.uuid;
-
- device.registerResource( {
- id: { path: "/light/ambience/blue" },
- deviceId: deviceId,
- resourceTypes: [ "core.light" ],
- interfaces: [ "oic.if.baseline" ],
- discoverable: true,
- observable: true,
- properties: { color: "light-blue", dimmer: 0.2 }
- } ).then(
- function( resource ) {
- device.unregisterResource( resource ).then(
- function() {
- testUtils.assert( "ok", true, "Resource unregistered successfully" );
- process.exit( 0 );
- },
- function( error ) {
- testUtils.assert( "ok", false,
- "Resource cannot be unregistered, error with code: " + error.result );
- process.exit( 0 );
- } );
- },
- function( error ) {
- testUtils.assert( "ok", false,
- "Resource not registered while testing unregister, error with code: " +
- error.result );
- process.exit( 0 );
- } );
-}
diff --git a/tests/tests/Interactive Server Startup.js b/tests/tests/Interactive Server Startup.js
new file mode 100644
index 0000000..3db025e
--- /dev/null
+++ b/tests/tests/Interactive Server Startup.js
@@ -0,0 +1,33 @@
+var utils = require( "../assert-to-console" );
+
+var requirePath = require( "path" )
+ .join( require( "bindings" ).getRoot( __filename ), "index" );
+
+console.log( JSON.stringify( { assertionCount: 4 } ) );
+
+var stderr = "";
+var stdout = "";
+
+var childArguments = [ "-e",
+ "try { require( '" + requirePath + "' )( 'server' ); } " +
+ "catch( anError ) { " +
+ "console.error( anError.stack ); process.exit( 1 ); " +
+ "}" +
+ "process.exit( 0 );"
+ ];
+
+var theChild = require( "child_process" ).spawn( "node", childArguments )
+ .on( "exit", function( code, signal ) {
+ utils.assert( "strictEqual", code, 0, "require() from interactive shell succeeded" );
+ utils.assert( "strictEqual", signal, null,
+ "require() from interactive shell did not receive a signal" );
+ utils.assert( "strictEqual", stdout, "", "Process stdout is empty" );
+ utils.assert( "strictEqual", stderr, "", "Process stderr is empty" );
+ } );
+
+theChild.stdout.on( "data", function( data ) {
+ stdout += data.toString();
+} );
+theChild.stderr.on( "data", function( data ) {
+ stderr += data.toString();
+} );