aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbinmiao <bin.miao@intel.com>2016-06-29 15:43:07 +0800
committerGabriel Schulhof <gabriel.schulhof@intel.com>2016-08-08 11:42:46 +0000
commit7223f684f71fc04dac5c8d8da7a498b933ea9309 (patch)
tree61e379738f7ffed042f4dc81a064a5b21a86df94
parentfc2bdcaee0ac0e3c1abc92720c6b0de44828012b (diff)
Tests: Assert that JS API objects have all required properties
- Add tests to check existance and type for properties on interface OicClient, OicDevice, OicDiscovery, OicPlatform, OicPresence and OicServer. - There are 70 asserts (check points), 64 of them are passed and 6 failed. (On Edison with image#473[1], failure documented in gh-52) Closes gh-59 [1]:https://download.ostroproject.org/builds/ostro-os/2016-07-04_12-17-07-build-473/images/ Change-Id: I23402a9b4b259c748a612bac46b0d772f8715159 Signed-off-by: Bin Miao <bin.miao@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/10143 Reviewed-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Tested-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
-rw-r--r--tests/assert-to-console.js26
-rw-r--r--tests/tests/API Device Information/client.js22
-rw-r--r--tests/tests/API Device Information/server.js5
-rw-r--r--tests/tests/API OicClient Structure.js27
-rw-r--r--tests/tests/API OicDiscovery Structure.js30
-rw-r--r--tests/tests/API OicServer Structure.js34
-rw-r--r--tests/tests/API Presence/client.js44
7 files changed, 167 insertions, 21 deletions
diff --git a/tests/assert-to-console.js b/tests/assert-to-console.js
index 85e36da..f46cb35 100644
--- a/tests/assert-to-console.js
+++ b/tests/assert-to-console.js
@@ -38,5 +38,31 @@ module.exports = {
die: function( message ) {
console.log( JSON.stringify( { teardown: true, message: message, isError: true } ) );
process.exit( 1 );
+ },
+
+ // ObjectName: A string describing the object - for example "OicDiscovery"
+ // Object: The object to be examined
+ // Properties: An array of objects containing two properties:
+ // name: The name of the property which must be present on object
+ // type: The name of the type the property must have
+ // For example:
+ // assertProperties( "OicDevice", device, [
+ // { name: "name", type: "string" },
+ // { name: "uuid", type: "string" },
+ // ...
+ // ] );
+ assertProperties: function( objectName, object, properties ) {
+ var index;
+ for ( index in properties ) {
+ this.assert( "ok", properties[ index ].name in object,
+ objectName + " has " + properties[ index ].name );
+ if ( properties[ index ].type ) {
+ this.assert( "strictEqual", typeof object[ properties[ index ].name ],
+ properties[ index ].type,
+ objectName + "." + properties[ index ].name + " is a " +
+ properties[ index ].type );
+ }
+
+ }
}
};
diff --git a/tests/tests/API Device Information/client.js b/tests/tests/API Device Information/client.js
index b618ac8..4a91dbb 100644
--- a/tests/tests/API Device Information/client.js
+++ b/tests/tests/API Device Information/client.js
@@ -16,6 +16,7 @@ var _ = require( "lodash" );
var utils = require( "../../assert-to-console" );
var oic = require( "../../../index" )( "client" );
var uuid = process.argv[ 2 ];
+
var expectedDeviceInfo = {
// The uuid field will be set to the deviceId when we know the deviceId
@@ -34,7 +35,7 @@ var expectedPlatformInfo = {
supportUrl: "supportUrl:" + uuid
};
-console.log( JSON.stringify( { assertionCount: 4 } ) );
+console.log( JSON.stringify( { assertionCount: 34 } ) );
new Promise( function findTheDeviceId( fulfill, reject ) {
var teardown;
@@ -56,6 +57,14 @@ new Promise( function findTheDeviceId( fulfill, reject ) {
oic.findResources( { resourcePath: "/a/" + uuid } ).catch( teardown );
} ).then( function getDeviceInfo( deviceId ) {
return oic.getDeviceInfo( deviceId ).then( function assertDeviceInfo( deviceInfo ) {
+ utils.assertProperties( "Client: retrieved OicDevice", deviceInfo, [
+ { name: "uuid", type: "string" },
+ { name: "url", type: "string" },
+ { name: "name", type: "string" },
+ { name: "dataModels", type: "string" },
+ { name: "coreSpecVersion", type: "string" },
+ { name: "role", type: "string" }
+ ] );
utils.assert( "deepEqual", deviceInfo, expectedDeviceInfo,
"Client: The retrieved device information is as expected" );
return deviceId;
@@ -64,6 +73,17 @@ new Promise( function findTheDeviceId( fulfill, reject ) {
return oic.getPlatformInfo( deviceId ).then( function assertPlatformInfo( platformInfo ) {
// Convert the manufactureDate to a timestamp for unambiguous comparison
+ utils.assertProperties( "Client: retrieved OicPlatform", platformInfo, [
+ { name: "id", type: "string" },
+ { name: "osVersion", type: "string" },
+ { name: "model", type: "string" },
+ { name: "manufacturerName", type: "string" },
+ { name: "manufacturerUrl", type: "string" },
+ { name: "manufactureDate", type: "object" },
+ { name: "platformVersion", type: "string" },
+ { name: "firmwareVersion", type: "string" },
+ { name: "supportUrl", type: "string" }
+ ] );
utils.assert( "deepEqual", _.extend( platformInfo, {
manufactureDate: new Date( platformInfo.manufactureDate ).getTime()
} ), expectedPlatformInfo, "Client: The retrieved platform information is as expected" );
diff --git a/tests/tests/API Device Information/server.js b/tests/tests/API Device Information/server.js
index ec0fddf..742982a 100644
--- a/tests/tests/API Device Information/server.js
+++ b/tests/tests/API Device Information/server.js
@@ -34,7 +34,10 @@ console.log( JSON.stringify( { assertionCount: 4 } ) );
try {
oic.device = _.extend( {}, oic.device, {
- name: "API Device Info Server " + uuid
+ name: "API Device Info Server " + uuid,
+ coreSpecVersion: "test.0.0.1",
+ dataModels: [ "blah.1.1.1" ],
+ url: "http://example.com/"
} );
} catch ( anError ) {
theError = anError;
diff --git a/tests/tests/API OicClient Structure.js b/tests/tests/API OicClient Structure.js
new file mode 100644
index 0000000..47d00f4
--- /dev/null
+++ b/tests/tests/API OicClient Structure.js
@@ -0,0 +1,27 @@
+// 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 utils = require( "../assert-to-console" ),
+ device = require( "../../index" )( "client" );
+
+console.log( JSON.stringify( { assertionCount: 8 } ) );
+
+utils.assertProperties( "OicClient", device, [
+ { name: "create", type: "function" },
+ { name: "retrieve", type: "function" },
+ { name: "update", type: "function" },
+ { name: "delete", type: "function" }
+] );
+
+process.exit( 0 );
diff --git a/tests/tests/API OicDiscovery Structure.js b/tests/tests/API OicDiscovery Structure.js
new file mode 100644
index 0000000..d93d436
--- /dev/null
+++ b/tests/tests/API OicDiscovery Structure.js
@@ -0,0 +1,30 @@
+// 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 utils = require( "../assert-to-console" ),
+ device = require( "../../index" )( "client" );
+
+console.log( JSON.stringify( { assertionCount: 11 } ) );
+
+utils.assertProperties( "OicDiscovery", device, [
+ { name: "findResources", type: "function" },
+ { name: "getDeviceInfo", type: "function" },
+ { name: "getPlatformInfo", type: "function" },
+ { name: "findDevices", type: "function" },
+ { name: "onresourcefound" },
+ { name: "ondevicefound" },
+ { name: "ondiscoveryerror" }
+] );
+
+process.exit( 0 );
diff --git a/tests/tests/API OicServer Structure.js b/tests/tests/API OicServer Structure.js
new file mode 100644
index 0000000..f2550a7
--- /dev/null
+++ b/tests/tests/API OicServer Structure.js
@@ -0,0 +1,34 @@
+// 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 utils = require( "../assert-to-console" ),
+ device = require( "../../index" )( "server" );
+
+console.log( JSON.stringify( { assertionCount: 16 } ) );
+
+utils.assertProperties( "OicServer", device, [
+ { name: "register", type: "function" },
+ { name: "unregister", type: "function" },
+ { name: "notify", type: "function" },
+ { name: "enablePresence", type: "function" },
+ { name: "disablePresence", type: "function" },
+ { name: "onobserverequest" },
+ { name: "onunobserverequest" },
+ { name: "onretrieverequest" },
+ { name: "ondeleterequest" },
+ { name: "onupdaterequest" },
+ { name: "oncreaterequest" }
+] );
+
+process.exit( 0 );
diff --git a/tests/tests/API Presence/client.js b/tests/tests/API Presence/client.js
index 5b449d2..d628095 100644
--- a/tests/tests/API Presence/client.js
+++ b/tests/tests/API Presence/client.js
@@ -16,7 +16,13 @@ var utils = require( "../../assert-to-console" ),
device = require( "../../../index" )( "client" ),
uuid = process.argv[ 2 ];
-console.log( JSON.stringify( { assertionCount: 8 } ) );
+console.log( JSON.stringify( { assertionCount: 13 } ) );
+
+utils.assertProperties( "OicPresence", device, [
+ { name: "subscribe", type: "function" },
+ { name: "unsubscribe", type: "function" },
+ { name: "ondevicechange" }
+] );
// Tell the resource's server to perform an operation (either disablePresence or enablePresence)
// or, if op is undefined, then do not communicate with the server. Either way, wait five seconds
@@ -36,7 +42,7 @@ function countEvents( resource, op ) {
function resourcefound( event ) {
if ( event.resource.id.path === resource.id.path &&
- event.resource.id.deviceId === resource.id.deviceId ) {
+ event.resource.id.deviceId === resource.id.deviceId ) {
events.push( JSON.stringify( {
event: event.type,
source: event.resource.id
@@ -109,17 +115,17 @@ function discoverResources() {
} ) );
}
};
- resourcefound = function resourcefound( event ) {
- if ( event.resource.id.path === "/a/" + uuid ) {
- resources.push( event.resource );
- if ( resources.length >= 2 ) {
- teardown();
- }
+ resourcefound = function resourcefound( event ) {
+ if ( event.resource.id.path === "/a/" + uuid ) {
+ resources.push( event.resource );
+ if ( resources.length >= 2 ) {
+ teardown();
}
- };
+ }
+ };
- device.addEventListener( "resourcefound", resourcefound );
- device.findResources( { resourcePath: "/a/" + uuid } ).catch( teardown );
+ device.addEventListener( "resourcefound", resourcefound );
+ device.findResources( { resourcePath: "/a/" + uuid } ).catch( teardown );
} );
}
@@ -145,9 +151,9 @@ function performSubscription( operation, resourceIndex ) {
device[ operation ].apply( device,
( resourceIndex === undefined ? [] : [ resources[ resourceIndex ].id.deviceId ] ) )
] )
- .then( function passOnResources( result ) {
- return Promise.resolve( result[ 0 ] );
- } );
+ .then( function passOnResources( result ) {
+ return Promise.resolve( result[ 0 ] );
+ } );
};
}
@@ -184,7 +190,7 @@ discoverResources()
].sort()
];
}, "Client: Events upon disablePresence() of both servers while subscribed are as " +
- "expected" ) )
+ "expected" ) )
.then( performStep( "enablePresence",
function expectationForEnablePresenceWhileSubscribedToAll( resources ) {
return [
@@ -208,7 +214,7 @@ discoverResources()
].sort()
];
}, "Client: Events upon enablePresence() of both servers while subscribed are as " +
- "expected" ) )
+ "expected" ) )
.then( performSubscription( "unsubscribe", 0 ) )
.then( performStep( "disablePresence",
function expectationForDisablePresenceWithOneUnsubscribed( resources ) {
@@ -222,7 +228,7 @@ discoverResources()
].sort()
];
}, "Client: Events upon disablePresence() with one server not subscribed are as " +
- "expected" ) )
+ "expected" ) )
.then( performStep( "enablePresence",
function expectationForEnablePresenceWithOneUnsubscribed( resources ) {
return [
@@ -238,12 +244,12 @@ discoverResources()
].sort()
];
}, "Client: Events upon enablePresence() with one server not subscribed are as " +
- "expected" ) )
+ "expected" ) )
.then(
function() {
console.log( JSON.stringify( { killPeer: true } ) );
process.exit( 0 );
},
function( error ) {
- utils.die( ( "" + error ) );
+ utils.die( ( "" + error ) );
} );