├── .eslintrc.json ├── .travis.yml ├── Gruntfile.js ├── LICENSE ├── README.md ├── ble ├── README.md └── webidl.md ├── board ├── README.md ├── aio.md ├── arduino101.md ├── frdm_k64f.md ├── gpio.md ├── i2c.md ├── pwm.md ├── spi.md ├── uart.md └── webidl.md ├── ocf ├── README.md ├── client.md ├── examples.md ├── server.md ├── tests │ ├── oic1.1.0-0 │ │ ├── Create - Resource (Direct) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Create - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Delete - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Device │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Platform │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Resource (Direct) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Resource (Multiple Types & Interfaces) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Resource (Repeated) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Discovery - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource (Direct - Unobservable) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource (Direct) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource (Failure) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource (Repeated) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource (Simultaneous) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Observe - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Presence - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Presence │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Retrieve - Platform │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Retrieve - Resource (Direct) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Retrieve - Resource (Failure) │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Retrieve - Resource (Local Error).js │ │ ├── Retrieve - Resource │ │ │ ├── client.js │ │ │ └── server.js │ │ ├── Server - register and unregister resource.js │ │ ├── Structure - Client.js │ │ ├── Structure - Device.js │ │ ├── Structure - OCF.js │ │ ├── Structure - Platform.js │ │ ├── Structure - Server.js │ │ └── Update - Resource │ │ │ ├── client.js │ │ │ └── server.js │ └── oic1.1.0-1 │ │ ├── Create - Resource (Direct) │ │ ├── client.js │ │ └── server.js │ │ ├── Create - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Delete - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Device │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Platform │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Resource (Direct) │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Resource (Multiple Types & Interfaces) │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Resource (Repeated) │ │ ├── client.js │ │ └── server.js │ │ ├── Discovery - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource (Direct - Unobservable) │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource (Direct) │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource (Failure) │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource (Repeated) │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource (Simultaneous) │ │ ├── client.js │ │ └── server.js │ │ ├── Observe - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Presence - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Presence │ │ ├── client.js │ │ └── server.js │ │ ├── Retrieve - Platform │ │ ├── client.js │ │ └── server.js │ │ ├── Retrieve - Resource (Direct) │ │ ├── client.js │ │ └── server.js │ │ ├── Retrieve - Resource (Failure) │ │ ├── client.js │ │ └── server.js │ │ ├── Retrieve - Resource (Local Error).js │ │ ├── Retrieve - Resource │ │ ├── client.js │ │ └── server.js │ │ ├── Server - register and unregister resource.js │ │ ├── Structure - Client.js │ │ ├── Structure - Device.js │ │ ├── Structure - OCF.js │ │ ├── Structure - Platform.js │ │ ├── Structure - Server.js │ │ └── Update - Resource │ │ ├── client.js │ │ └── server.js └── webidl.md ├── package.json ├── scripts ├── build │ └── tasks │ │ ├── alias.js │ │ └── options │ │ └── eslint.js ├── index.js └── lib │ ├── callbacks.js │ └── setup.js ├── sensors └── README.md ├── tasks └── iot-js-api.js └── test-runner.md /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-jquery", 3 | "root": true, 4 | "globals": { 5 | "Promise": false 6 | }, 7 | "env": { 8 | "node": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - "4" 7 | 8 | install: 9 | - npm install -g grunt-cli 10 | - npm install 11 | 12 | script: grunt 13 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | module.exports = function( grunt ) { 17 | "use strict"; 18 | 19 | var path = require( "path" ); 20 | 21 | require( "load-grunt-config" )( grunt, { 22 | configPath: [ 23 | path.join( __dirname, "scripts", "build", "tasks", "options" ), 24 | path.join( __dirname, "scripts", "build", "tasks" ) 25 | ], 26 | init: true 27 | } ); 28 | 29 | require( "load-grunt-tasks" )( grunt ); 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /board/arduino101.md: -------------------------------------------------------------------------------- 1 | Board Support for Arduino 101 2 | ============================= 3 | 4 | This document defines the pin values that are accepted by implementations on board namespace. 5 | 6 | The board labels are described in the [Arduino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) board documentation. Also, for each board pin, the supported modes of each pin is described. 7 | 8 | The [Arduino 101](https://www.arduino.cc/en/Main/ArduinoBoard101) board has 20 I/O pins that operate at 3.3V and can be configured as described by the following table. 9 | 10 | Pins 0 and 1 can be also configured to be used as UART. The port name is exposed as `uart0`. 11 | 12 | On GPIO pins (0..13) interrupts can be configured to be triggered on low value, high value, rising edge and falling edge. Some of the GPIO pins can trigger interrupt on value *change* (pins 2, 5, 7, 8, 10, 11, 12, 13). 13 | 14 | Pins 3, 5, 6 and 9 can be used for PWM output. These pins are marked on the board by a ~ (tilde) symbol next to the pin numbers. Pin 3 corresponds to PWM channel 0, pin 5 to PWM channel 1, pin 6 to PWM channed 2, and pin 9 to PWM channel 3. 15 | 16 | Pins A0 to A5 can be used for analog input and each provide 10 bits of resolution (i.e. 1024 different values). 17 | 18 | There are 3 LEDs on the board that can be accessed by the pin names `"LED0"`, `"LED1"` and `"LED3"`. 19 | 20 | Other names: 21 | - UART on pin 0 and 1 can be accessed by the name `"uart0"`. 22 | - UART on USB can be accessed by the name `"serialUSB0"`, `"serialUSB2"`, etc. 23 | - I2C can be accessed by default on bus 0 (the SDA and SCL pins). 24 | - SPI can be accessed by default on bus 0. SPI pins on the board are: 25 | * SS (Slave Select) on pin 10 26 | * MOSI (Master Out Slave In) on pin 11 27 | * MISO (Master In Slave Out) on pin 12 28 | * SCK (Serial Clock) on pin 13. 29 | 30 | Arduino 101 pins are summarized in the following table (channel means the index of the same I/O type): 31 | 32 | |Pin value |Supported modes (channel) | 33 | | --- | --- | 34 | | `0` | GPIO_IN, GPIO_OUT, UART_RX(0) | 35 | | `1` | GPIO_IN, GPIO_OUT, UART_TX(0) | 36 | | `2` | GPIO_IN, GPIO_OUT | 37 | | `3` | GPIO_IN, GPIO_OUT, PWM(0) | 38 | | `4` | GPIO_IN, GPIO_OUT | 39 | | `5` | GPIO_IN, GPIO_OUT, PWM(1) | 40 | | `6` | GPIO_IN, GPIO_OUT, PWM(2) | 41 | | `7` | GPIO_IN, GPIO_OUT | 42 | | `8` | GPIO_IN, GPIO_OUT | 43 | | `9` | GPIO_IN, GPIO_OUT, PWM(3) | 44 | | `10` | GPIO_IN, GPIO_OUT, SPI_SS(0) | 45 | | `11` | GPIO_IN, GPIO_OUT, SPI_MOSI(0) | 46 | | `12` | GPIO_IN, GPIO_OUT, SPI_MISO(0) | 47 | | `13` | GPIO_IN, GPIO_OUT, SPI_SCLK(0) | 48 | | `"A0"` | ANALOG_IN(0) | 49 | | `"A1"` | ANALOG_IN(1) | 50 | | `"A2"` | ANALOG_IN(2) | 51 | | `"A3"` | ANALOG_IN(3) | 52 | | `"A4"` | ANALOG_IN(4) | 53 | | `"A5"` | ANALOG_IN(5) | 54 | | `"LED0"` | alias for GPIO connected LED, active on 1 | 55 | | `"LED1"` | alias for GPIO connected LED, active on 0 | 56 | | `"LED2"` | alias for GPIO connected LED, active on 0 | 57 | -------------------------------------------------------------------------------- /board/frdm_k64f.md: -------------------------------------------------------------------------------- 1 | Board Support for FRDM-K64F 2 | =========================== 3 | 4 | This document defines the pin values that are accepted by implementations on board namespace. 5 | 6 | The FRDM-K64F board pin names and locations are shown [here](https://developer.mbed.org/platforms/FRDM-K64F/). 7 | 8 | There are 16 general purpose I/O pins, `D0` - `D15`. `D14` and `D15` can currently be used as GPIO_INs but not as outputs. 9 | 10 | There is an onboard RGB LED which can be controlled through three different GPIO_OUTs for the red, green, and blue components. `LEDR` controls the red portion, `LEDG` the green portion, and `LEDB` the blue 11 | portion. They are all active on high. 12 | 13 | There are three onboard switches labeled `SW2`, `SW3`, and `RESET`. The `SW2` switch can be used as a GPIO_IN. The `RESET` switch can be used as an output. 14 | 15 | There are ten pins that can be used as PWM output, `PWM0` - `PWM9`. 16 | 17 | There are six analog input pins, `A0` - `A5`. 18 | 19 | Supported pins are summarized in the following table: 20 | 21 | |Pin name |Supported modes (channel) | 22 | | --- | --- | 23 | | `D0` | GPIO_IN, GPIO_OUT, UART_RX(3) | 24 | | `D1` | GPIO_IN, GPIO_OUT, UART_TX(3) | 25 | | `D2` | GPIO_IN, GPIO_OUT | 26 | | `D3` | GPIO_IN, GPIO_OUT, PWM(0) | 27 | | `D4` | GPIO_IN, GPIO_OUT | 28 | | `D5` | GPIO_IN, GPIO_OUT, PWM(1) | 29 | | `D6` | GPIO_IN, GPIO_OUT, PWM(2) | 30 | | `D7` | GPIO_IN, GPIO_OUT, PWM(3) | 31 | | `D8` | GPIO_IN, GPIO_OUT, PWM(4) | 32 | | `D9` | GPIO_IN, GPIO_OUT, PWM(5) | 33 | | `D10` | GPIO_IN, GPIO_OUT, PWM(6) | 34 | | `D11` | GPIO_IN, GPIO_OUT, PWM(7), SPI_MOSI(0) | 35 | | `D12` | GPIO_IN, GPIO_OUT, PWM(8), SPI_MISO(0) | 36 | | `D13` | GPIO_IN, GPIO_OUT, PWM(9), SPI_SCLK(0) | 37 | | `D14` | GPIO_IN, I2C_SDA(0) | 38 | | `D15` | GPIO_IN, I2C_SCL(0) | 39 | | `"A0"` | ANALOG_IN(0) | 40 | | `"A1"` | ANALOG_IN(1) | 41 | | `"A2"` | ANALOG_IN(2) | 42 | | `"A3"` | ANALOG_IN(3) | 43 | | `"A4"` | ANALOG_IN(4), PWM | 44 | | `"A5"` | ANALOG_IN(5), PWM | 45 | | `"LED0"`| active on 1 | 46 | | `"LED1"`| active on 0 | 47 | | `"LED2"`| active on 0 | 48 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Create - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var desiredNewResource = { 18 | resourcePath: "/some/new/resource", 19 | interfaces: [ "oic.if.baseline" ], 20 | resourceTypes: [ "core.light" ], 21 | discoverable: true 22 | }; 23 | 24 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 25 | 26 | function filterKeys( object, keys ) { 27 | var index; 28 | var returnValue = {}; 29 | 30 | for ( index in keys ) { 31 | if ( keys[ index ] in object ) { 32 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 33 | } 34 | } 35 | 36 | return returnValue; 37 | } 38 | 39 | // Perform directed resource discovery on a device 40 | function getResources( device ) { 41 | var resourceList = {}; 42 | 43 | function resourcefound( resource ) { 44 | if ( resource.resourcePath === desiredNewResource.resourcePath ) { 45 | resourceList.desired = resource; 46 | } 47 | } 48 | 49 | return client.findResources( { deviceId: device.uuid }, resourcefound ) 50 | .then( function() { 51 | client.removeListener( "resourcefound", resourcefound ); 52 | return resourceList; 53 | } ); 54 | } 55 | 56 | // Perform the create() method on a device if it's the right device 57 | function tryDevice( device ) { 58 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 59 | return; 60 | } 61 | 62 | // We've found the server, so stop looking 63 | client.removeListener( "devicefound", tryDevice ); 64 | 65 | desiredNewResource.deviceId = device.uuid; 66 | 67 | client.create( desiredNewResource ) 68 | .then( function( newResource ) { 69 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 70 | filterKeys( newResource, [ 71 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "deviceId" 72 | ] ), 73 | desiredNewResource, 74 | "Client: The newly created resource has the expected structure" 75 | ] } ) ); 76 | return getResources( device ); 77 | } ) 78 | .then( function( resourceList ) { 79 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 80 | resourceList.desired, 81 | "Client: After creating the resource, the device contains the desired resource" 82 | ] } ) ); 83 | console.log( JSON.stringify( { finished: 0 } ) ); 84 | } ) 85 | .catch( function( error ) { 86 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 87 | false, "Client: Failed to process device: " + 88 | ( "" + error ) + "\n" + JSON.stringify( { 89 | error: error, 90 | device: device 91 | }, null, 4 ) 92 | ] } ) ); 93 | } ); 94 | } 95 | 96 | client.findDevices( tryDevice ) 97 | .catch( function( error ) { 98 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 99 | false, "Client: Starting device discovery failed: " + 100 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 101 | ] } ) ); 102 | } ); 103 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Create - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 20 | 21 | ocf.server 22 | .oncreate( function( request ) { 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | "target" in request, false, "Server: Create request has no target" 25 | ] } ) ); 26 | ocf.server.register( request.data ) 27 | .then( 28 | function( resource ) { 29 | return request.respond( resource ); 30 | }, 31 | function( error ) { 32 | return request.respondWithError( error ); 33 | } ) 34 | .then( 35 | function() { 36 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 37 | true, "Server: Response successfully sent" 38 | ] } ) ); 39 | }, 40 | function( anError ) { 41 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 42 | false, "Server: Error: " + 43 | ( "" + anError ) + "\n" + JSON.stringify( anError, null, 4 ) 44 | ] } ) ); 45 | } ); 46 | } ); 47 | 48 | console.log( JSON.stringify( { ready: true } ) ); 49 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Create - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/target-resource", 24 | interfaces: [ "oic.if.baseline" ], 25 | resourceTypes: [ "core.light" ], 26 | discoverable: true 27 | } ) 28 | .then( 29 | function( resource ) { 30 | resource.oncreate( function( request ) { 31 | ocf.server.register( request.data ) 32 | .then( 33 | function( resource ) { 34 | request.respond( resource ); 35 | }, 36 | function( error ) { 37 | request.respondWithError( error ); 38 | } ); 39 | } ); 40 | console.log( JSON.stringify( { ready: true } ) ); 41 | }, 42 | function( error ) { 43 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 44 | false, "Server: Failed to register resource: " + 45 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 46 | ] } ) ); 47 | } ); 48 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Delete - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | // Perform the create() method on a device if it's the right device 20 | function tryDevice( device ) { 21 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 22 | return; 23 | } 24 | 25 | // We've found the server, so stop looking 26 | client.removeListener( "devicefound", tryDevice ); 27 | 28 | client 29 | .delete( { deviceId: device.uuid, resourcePath: "/some/new/resource" } ) 30 | .then( 31 | function() { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | true, "Client: Resource successfully deleted" 34 | ] } ) ); 35 | }, 36 | function( anError ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | false, "Client: failed to delete resource: " + 39 | ( "" + anError ) + "\n" + JSON.stringify( anError, null, 4 ) 40 | ] } ) ); 41 | } ) 42 | .then( function() { 43 | console.log( JSON.stringify( { finished: 0 } ) ); 44 | } ); 45 | } 46 | 47 | client.findDevices( tryDevice ) 48 | .catch( function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Client: Starting device discovery failed: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Delete - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/some/new/resource", 24 | interfaces: [ "oic.if.baseline" ], 25 | resourceTypes: [ "core.light" ], 26 | discoverable: true 27 | } ) 28 | .then( 29 | function( resource ) { 30 | resource.ondelete( function( request ) { 31 | resource.unregister() 32 | .then( 33 | function() { 34 | request.respond(); 35 | }, 36 | function( error ) { 37 | request.respondWithError( error ); 38 | } ); 39 | } ); 40 | console.log( JSON.stringify( { ready: true } ) ); 41 | }, 42 | function( error ) { 43 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 44 | false, "Server: Failed to register resource: " + 45 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 46 | ] } ) ); 47 | } ); 48 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Device/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 4 } ) ); 18 | 19 | function handleDeviceFound( device ) { 20 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 21 | ocf.client.removeListener( "devicefound", handleDeviceFound ); 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | true, "Client: Found device via .on()" 24 | ] } ) ); 25 | ocf.client.getDeviceInfo( device.uuid ) 26 | .then( 27 | function( deviceViaGet ) { 28 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 29 | deviceViaGet, device, 30 | "Client: Retrieved device info is identical to discovered device info" 31 | ] } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Client: Unexpectedly failed to retrieve device info: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ) 39 | .then( function() { 40 | console.log( JSON.stringify( { finished: 0 } ) ); 41 | } ); 42 | } 43 | } 44 | 45 | function handleDeviceFoundConvenience( device ) { 46 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 47 | ocf.client.removeListener( "devicefound", handleDeviceFoundConvenience ); 48 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 49 | true, "Client: Found device via convenience handler" 50 | ] } ) ); 51 | } 52 | } 53 | 54 | ocf.client 55 | .on( "devicefound", handleDeviceFound ) 56 | .findDevices( handleDeviceFoundConvenience ) 57 | .then( 58 | function() { 59 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 60 | true, "Client: Device discovery successfully started" 61 | ] } ) ); 62 | }, 63 | function( error ) { 64 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 65 | false, "Client: Starting device discovery failed: " + 66 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 67 | ] } ) ); 68 | } ); 69 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Device/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | console.log( JSON.stringify( { ready: true } ) ); 22 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Platform/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 18 | 19 | var conditionsMet = 0; 20 | function maybeQuit() { 21 | if ( ++conditionsMet === 2 ) { 22 | console.log( JSON.stringify( { finished: 0 } ) ); 23 | } 24 | } 25 | 26 | ocf.client 27 | .on( "platformfound", function( platform ) { 28 | if ( platform.supportURL === "ocf://test-device-" + process.argv[ 2 ] ) { 29 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 30 | true, "Client: Found platform via .on()" 31 | ] } ) ); 32 | maybeQuit(); 33 | } 34 | } ) 35 | .findPlatforms( function( platform ) { 36 | if ( platform.supportURL === "ocf://test-device-" + process.argv[ 2 ] ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | true, "Client: Found platform via convenience handler" 39 | ] } ) ); 40 | maybeQuit(); 41 | } 42 | } ).then( 43 | function() { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | true, "Client: Platform discovery successfully started" 46 | ] } ) ); 47 | }, 48 | function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | true, "Client: Failed to start platform discovery: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | Promise.all( [ 20 | new Promise( function( fulfill ) { 21 | function devicefound( device ) { 22 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 23 | ocf.client.removeListener( "devicefound", devicefound ); 24 | fulfill( device ); 25 | } 26 | } 27 | ocf.client.on( "devicefound", devicefound ); 28 | } ), 29 | ocf.client 30 | .findDevices() 31 | .catch( function( error ) { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | false, "Failed to start device discovery: " + 34 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 35 | ] } ) ); 36 | } ) 37 | ] ).then( function( results ) { 38 | var device = results[ 0 ]; 39 | return Promise.all( [ 40 | new Promise( function( fulfill ) { 41 | ocf.client.on( "resourcefound", function( resource ) { 42 | if ( resource.deviceId === device.uuid && 43 | resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 44 | fulfill( resource ); 45 | } 46 | } ); 47 | } ), 48 | ocf.client 49 | .findResources( { 50 | deviceId: device.uuid, 51 | resourcePath: "/a/" + process.argv[ 2 ] 52 | } ) 53 | .then( 54 | function() { 55 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 56 | true, "Client: Direct resource discovery successfully started" 57 | ] } ) ); 58 | }, 59 | function( error ) { 60 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 61 | false, "Client: Starting direct resource discovery failed: " + 62 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 63 | ] } ) ); 64 | } ) 65 | ] ).then( function() { 66 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 67 | true, "Client: Resource directly discovered" 68 | ] } ) ); 69 | console.log( JSON.stringify( { finished: 0 } ) ); 70 | } ); 71 | } ); 72 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/a/" + process.argv[ 2 ], 24 | resourceTypes: [ "core.light" ], 25 | interfaces: [ "oic.if.baseline" ], 26 | discoverable: true 27 | } ) 28 | .then( 29 | function() { 30 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 31 | true, "Server: Resource successfully registered" 32 | ] } ) ); 33 | console.log( JSON.stringify( { ready: true } ) ); 34 | }, 35 | function( error ) { 36 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 37 | false, "Server: Resource registration failed: " + 38 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 39 | ] } ) ); 40 | } ); 41 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Multiple Types & Interfaces)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function filterKeys( object, keys ) { 16 | var index; 17 | var returnValue = {}; 18 | 19 | for ( index in keys ) { 20 | if ( keys[ index ] in object ) { 21 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 22 | } 23 | } 24 | 25 | return returnValue; 26 | } 27 | 28 | var client = require( process.argv[ 3 ] ).client; 29 | 30 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 31 | 32 | client 33 | .on( "resourcefound", function( resource ) { 34 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 35 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 36 | filterKeys( resource, [ 37 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "observable", 38 | "secure" 39 | ] ), 40 | { 41 | resourcePath: "/a/" + process.argv[ 2 ], 42 | interfaces: [ "oic.if.baseline", "oic.if.custom" ], 43 | resourceTypes: [ "core.light", "core.fan" ], 44 | discoverable: true, 45 | observable: false, 46 | secure: false 47 | }, "Client: Resource found" 48 | ] } ) ); 49 | console.log( JSON.stringify( { finished: 0 } ) ); 50 | } 51 | } ) 52 | .findResources() 53 | .then( 54 | function() { 55 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 56 | true, "Client: Resource discovery successfully started" 57 | ] } ) ); 58 | }, 59 | function( error ) { 60 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 61 | false, "Client: Starting resource discovery failed: " + 62 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 63 | ] } ) ); 64 | } ); 65 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Multiple Types & Interfaces)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | server.register( { 20 | resourcePath: "/a/" + process.argv[ 2 ], 21 | resourceTypes: [ "core.light", "core.fan" ], 22 | interfaces: [ "oic.if.baseline", "oic.if.custom" ], 23 | discoverable: true 24 | } ).then( 25 | function() { 26 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 27 | true, "Server: Resource registered successfully" 28 | ] } ) ); 29 | 30 | console.log( JSON.stringify( { ready: true } ) ); 31 | }, 32 | function( error ) { 33 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 34 | false, "Server: Resource registration failed: " + 35 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 36 | ] } ) ); 37 | } ).catch( 38 | function( error ) { 39 | console.log( JSON.stringify( { 40 | teardown: true, 41 | message: "Server: Fatal error: " + 42 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 43 | } ) ); 44 | } ); 45 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Repeated)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // We assume that discovery results arrive in under this many milliseconds 16 | var discoveryDuration = 6000; 17 | var client = require( process.argv[ 3 ] ).client; 18 | var firstRunResults; 19 | 20 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 21 | 22 | function doOneDiscovery() { 23 | var numberFound = 0, numberConvenientlyFound = 0; 24 | 25 | function resourcefound( resource ) { 26 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 27 | numberFound++; 28 | } 29 | } 30 | function resourcefoundConveniently( resource ) { 31 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 32 | numberConvenientlyFound++; 33 | } 34 | } 35 | 36 | return client 37 | .on( "resourcefound", resourcefound ) 38 | .findResources( resourcefoundConveniently ) 39 | .then( function() { 40 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 41 | true, "Client: Resource discovery successfully started" 42 | ] } ) ); 43 | } ) 44 | 45 | // Spend some time collecting resources using the above listeners, then clean up and return 46 | // the resulting counts 47 | .then( function() { 48 | return new Promise( function( fulfill ) { 49 | setTimeout( function() { 50 | client.removeAllListeners( "resourcefound" ); 51 | fulfill( [ numberFound, numberConvenientlyFound ] ); 52 | }, discoveryDuration ); 53 | } ); 54 | } ); 55 | } 56 | 57 | doOneDiscovery() 58 | .then( function( results ) { 59 | firstRunResults = results; 60 | return doOneDiscovery(); 61 | } ) 62 | .then( function( results ) { 63 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 64 | results, firstRunResults, 65 | "Client: Second discovery round results are identical to the first" 66 | ] } ) ); 67 | console.log( JSON.stringify( { finished: 0 } ) ); 68 | } ) 69 | .catch( function( error ) { 70 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 71 | false, "Client: Fatal error: " + ( "" + error ) + "\n" + 72 | JSON.stringify( error, null, 4 ) 73 | ] } ) ); 74 | } ); 75 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource (Repeated)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function filterKeys( object, keys ) { 18 | var index; 19 | var returnValue = {}; 20 | 21 | for ( index in keys ) { 22 | if ( keys[ index ] in object ) { 23 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 24 | } 25 | } 26 | 27 | return returnValue; 28 | } 29 | 30 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 31 | 32 | var desiredResource = { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | discoverable: true 37 | }; 38 | 39 | server.register( desiredResource ).then( 40 | function( resource ) { 41 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 42 | filterKeys( resource, [ 43 | "resourcePath", "resourceTypes", "interfaces", "discoverable" 44 | ] ), desiredResource, "Server: Resource registered successfully" 45 | ] } ) ); 46 | 47 | console.log( JSON.stringify( { ready: true } ) ); 48 | }, 49 | function( error ) { 50 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 51 | false, "Server: Resource registration failed: " + 52 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 53 | ] } ) ); 54 | } ).catch( 55 | function( error ) { 56 | console.log( JSON.stringify( { 57 | teardown: true, 58 | message: "Server: Fatal error: " + 59 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 60 | } ) ); 61 | } ); 62 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var conditionsMet = 0; 16 | function maybeQuit() { 17 | if ( ++conditionsMet === 2 ) { 18 | console.log( JSON.stringify( { finished: 0 } ) ); 19 | } 20 | } 21 | 22 | function filterKeys( object, keys ) { 23 | var index; 24 | var returnValue = {}; 25 | 26 | for ( index in keys ) { 27 | if ( keys[ index ] in object ) { 28 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 29 | } 30 | } 31 | 32 | return returnValue; 33 | } 34 | 35 | var client = require( process.argv[ 3 ] ).client; 36 | 37 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 38 | 39 | function resourcefound( resource ) { 40 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 41 | client.removeListener( "resourcefound", resourcefound ); 42 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 43 | filterKeys( resource, [ 44 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "observable", 45 | "secure" 46 | ] ), 47 | { 48 | resourcePath: "/a/" + process.argv[ 2 ], 49 | interfaces: [ "oic.if.baseline" ], 50 | resourceTypes: [ "core.light" ], 51 | discoverable: true, 52 | observable: false, 53 | secure: false 54 | }, "Client: Resource found via .on()" 55 | ] } ) ); 56 | maybeQuit(); 57 | } 58 | } 59 | 60 | function resourcefoundConveniently( resource ) { 61 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 62 | client.removeListener( "resourcefound", resourcefoundConveniently ); 63 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 64 | true, "Client: Resource found via convenience handler" 65 | ] } ) ); 66 | maybeQuit(); 67 | } 68 | } 69 | 70 | client 71 | .on( "resourcefound", resourcefound ) 72 | .findResources( resourcefoundConveniently ) 73 | .then( 74 | function() { 75 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 76 | true, "Client: Resource discovery successfully started" 77 | ] } ) ); 78 | }, 79 | function( error ) { 80 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 81 | false, "Client: Starting resource discovery failed: " + 82 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 83 | ] } ) ); 84 | } ); 85 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Discovery - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function filterKeys( object, keys ) { 18 | var index; 19 | var returnValue = {}; 20 | 21 | for ( index in keys ) { 22 | if ( keys[ index ] in object ) { 23 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 24 | } 25 | } 26 | 27 | return returnValue; 28 | } 29 | 30 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 31 | 32 | var desiredResource = { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | discoverable: true 37 | }; 38 | 39 | server.register( desiredResource ).then( 40 | function( resource ) { 41 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 42 | filterKeys( resource, [ 43 | "resourcePath", "resourceTypes", "interfaces", "discoverable" 44 | ] ), desiredResource, "Server: Resource registered successfully" 45 | ] } ) ); 46 | 47 | console.log( JSON.stringify( { ready: true } ) ); 48 | }, 49 | function( error ) { 50 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 51 | false, "Server: Resource registration failed: " + 52 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 53 | ] } ) ); 54 | } ).catch( 55 | function( error ) { 56 | console.log( JSON.stringify( { 57 | teardown: true, 58 | message: "Server: Fatal error: " + 59 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 60 | } ) ); 61 | } ); 62 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Direct - Unobservable)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | // Dummy listener function. 20 | function listener() {} 21 | 22 | function devicefound( device ) { 23 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 24 | return; 25 | } 26 | client.removeListener( "devicefound", devicefound ); 27 | client.retrieve( { 28 | deviceId: device.uuid, 29 | resourcePath: "/a/" + process.argv[ 2 ] 30 | }, listener ) 31 | .then( 32 | function( resource ) { 33 | resource.removeListener( "update", listener ); 34 | console.log( JSON.stringify( { finished: 0 } ) ); 35 | }, 36 | function( error ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | false, "Client: Failed to directly retrieve resource: " + 39 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 40 | ] } ) ); 41 | } ); 42 | } 43 | 44 | client 45 | .findDevices( devicefound ) 46 | .catch( function( error ) { 47 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 48 | false, "Client: Failed to start device discovery: " + 49 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 50 | ] } ) ); 51 | } ); 52 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Direct - Unobservable)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | var server = ocf.server; 17 | 18 | var oldObserverCount = 0; 19 | var observerCount = 0; 20 | var timeoutId; 21 | var fakeSensorStarted = false; 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 26 | 27 | function fakeSensorLoop( resource ) { 28 | var notificationCount = 0; 29 | function timeout() { 30 | resource.properties.value = Math.random() + 1; 31 | 32 | // Ensure a total of six notifications 33 | timeoutId = ( ++notificationCount < 2 ) ? 34 | setTimeout( timeout, ( Math.random() ) * 1000 + 500 ) : 0; 35 | 36 | resource.notify() 37 | .then( 38 | function() { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | true, "Server: Notification successful" 41 | ] } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Notification error: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | timeout(); 51 | } 52 | 53 | server 54 | .register( { 55 | resourcePath: "/a/" + process.argv[ 2 ], 56 | resourceTypes: [ "core.light" ], 57 | interfaces: [ "oic.if.baseline" ], 58 | discoverable: true, 59 | properties: { 60 | value: Math.random() + 1 61 | } 62 | } ) 63 | .then( 64 | function( resource ) { 65 | resource.onretrieve( function( request ) { 66 | oldObserverCount = observerCount; 67 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 68 | 69 | // Start the notification loop when all observers have checked in 70 | if ( observerCount >= 1 && !fakeSensorStarted ) { 71 | fakeSensorLoop( resource ); 72 | fakeSensorStarted = true; 73 | } 74 | 75 | request.respond() 76 | .then( 77 | function() { 78 | 79 | // We quit when the last observer was removed 80 | if ( oldObserverCount > 0 && observerCount === 0 ) { 81 | console.log( JSON.stringify( { 82 | assertion: "ok", 83 | arguments: [ 84 | timeoutId === 0, 85 | "Server: Timeout was removed by the time the last " + 86 | "observer signed off" 87 | ] } ) ); 88 | console.log( JSON.stringify( { finished: 0 } ) ); 89 | } 90 | }, 91 | function( error ) { 92 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 93 | false, "Server: Failed to respond to retrieve request: " + 94 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 95 | ] } ) ); 96 | } ); 97 | } ); 98 | console.log( JSON.stringify( { ready: true } ) ); 99 | }, 100 | function( error ) { 101 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 102 | false, "Server: Registering resource failed unexpectedly: " + 103 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 104 | ] } ) ); 105 | } ); 106 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var observationCount = 0; 18 | 19 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 20 | 21 | function listener( resource ) { 22 | observationCount++; 23 | if ( observationCount === 3 ) { 24 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 25 | true, "Client: Performed three observations" 26 | ] } ) ); 27 | resource.removeListener( "update", listener ); 28 | } 29 | } 30 | 31 | function devicefound( device ) { 32 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 33 | return; 34 | } 35 | client.removeListener( "devicefound", devicefound ); 36 | client.retrieve( { 37 | deviceId: device.uuid, 38 | resourcePath: "/a/" + process.argv[ 2 ] 39 | }, listener ) 40 | .catch( 41 | function( error ) { 42 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 43 | false, "Client: Failed to directly retrieve resource: " + 44 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 45 | ] } ) ); 46 | } ); 47 | } 48 | 49 | client 50 | .findDevices( devicefound ) 51 | .catch( function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Client: Failed to start device discovery: " + 54 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ); 57 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | var server = ocf.server; 17 | 18 | var oldObserverCount = 0; 19 | var observerCount = 0; 20 | var timeoutId; 21 | var fakeSensorStarted = false; 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 26 | 27 | function fakeSensorLoop( resource ) { 28 | var notificationCount = 0; 29 | function timeout() { 30 | resource.properties.value = Math.random() + 1; 31 | 32 | // Ensure a total of six notifications 33 | timeoutId = ( ++notificationCount < 2 ) ? 34 | setTimeout( timeout, ( Math.random() ) * 1000 + 500 ) : 0; 35 | 36 | resource.notify() 37 | .then( 38 | function() { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | true, "Server: Notification successful" 41 | ] } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Notification error: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | timeout(); 51 | } 52 | 53 | server 54 | .register( { 55 | resourcePath: "/a/" + process.argv[ 2 ], 56 | resourceTypes: [ "core.light" ], 57 | interfaces: [ "oic.if.baseline" ], 58 | discoverable: true, 59 | observable: true, 60 | properties: { 61 | value: Math.random() + 1 62 | } 63 | } ) 64 | .then( 65 | function( resource ) { 66 | resource.onretrieve( function( request ) { 67 | oldObserverCount = observerCount; 68 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 69 | 70 | // Start the notification loop when all observers have checked in 71 | if ( observerCount >= 1 && !fakeSensorStarted ) { 72 | fakeSensorLoop( resource ); 73 | fakeSensorStarted = true; 74 | } 75 | 76 | request.respond() 77 | .then( 78 | function() { 79 | 80 | // We quit when the last observer was removed 81 | if ( oldObserverCount > 0 && observerCount === 0 ) { 82 | console.log( JSON.stringify( { 83 | assertion: "ok", 84 | arguments: [ 85 | timeoutId === 0, 86 | "Server: Timeout was removed by the time the last " + 87 | "observer signed off" 88 | ] } ) ); 89 | console.log( JSON.stringify( { finished: 0 } ) ); 90 | } 91 | }, 92 | function( error ) { 93 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 94 | false, "Server: Failed to respond to retrieve request: " + 95 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 96 | ] } ) ); 97 | } ); 98 | } ); 99 | console.log( JSON.stringify( { ready: true } ) ); 100 | }, 101 | function( error ) { 102 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 103 | false, "Server: Registering resource failed unexpectedly: " + 104 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 105 | ] } ) ); 106 | } ); 107 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Failure)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | function dummyListener() {} 20 | 21 | function performObservation( resource ) { 22 | resource 23 | .on( "error", function( error ) { 24 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 25 | error.message, "Server responded with error", 26 | "Client: Failure to observe resulted in expected error" 27 | ] } ) ); 28 | console.log( JSON.stringify( { finished: 0 } ) ); 29 | } ) 30 | .on( "update", dummyListener ); 31 | client.removeListener( "resourcefound", performObservation ); 32 | } 33 | 34 | client 35 | .on( "resourcefound", performObservation ) 36 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 37 | .catch( function( error ) { 38 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 39 | false, "Client: Starting device discovery failed: " + 40 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 41 | ] } ) ); 42 | } ); 43 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Failure)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | server 20 | .register( { 21 | resourcePath: "/a/" + process.argv[ 2 ], 22 | resourceTypes: [ "core.light" ], 23 | interfaces: [ "oic.if.baseline" ], 24 | discoverable: true, 25 | observable: true 26 | } ) 27 | .then( 28 | function( resource ) { 29 | resource.onretrieve( function( request ) { 30 | request.respondWithError( "Go about yer merry way!" ); 31 | } ); 32 | console.log( JSON.stringify( { ready: true } ) ); 33 | }, 34 | function( error ) { 35 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 36 | false, "Server: Registering resource failed unexpectedly: " + 37 | ( "" + error ) + "\n" + JSON.stringify( error ) 38 | ] } ) ); 39 | } ); 40 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Repeated)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | function observeResource( resource ) { 20 | return new Promise( function( fulfill ) { 21 | var updateCount = 0; 22 | function update( resource ) { 23 | if ( ++updateCount === 6 ) { 24 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 25 | true, "Client: Observation sequence complete" 26 | ] } ) ); 27 | resource.removeListener( "update", update ); 28 | fulfill(); 29 | } 30 | } 31 | resource.on( "update", update ); 32 | } ); 33 | } 34 | 35 | function resourcefound( resource ) { 36 | client.removeListener( "resourcefound", resourcefound ); 37 | observeResource( resource ) 38 | .then( function() { 39 | return new Promise( function( fulfill ) { 40 | setTimeout( function() { 41 | fulfill( observeResource( resource ) ); 42 | }, 5000 ); 43 | } ); 44 | } ) 45 | .catch( function( error ) { 46 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 47 | false, "Client: Error during observation: " + ( "" + error ) + "\n" + 48 | JSON.stringify( error, null, 4 ) 49 | ] } ) ); 50 | } ); 51 | } 52 | 53 | client 54 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] }, resourcefound ) 55 | .catch( function( error ) { 56 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 57 | false, "Client: Failed to initiate resource discovery: " + ( "" + error ) + "\n" + 58 | JSON.stringify( error, null, 4 ) 59 | ] } ) ); 60 | } ); 61 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Repeated)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | var timeoutId = 0; 17 | var observerCount = 0; 18 | var cycleCount = 0; 19 | 20 | console.log( JSON.stringify( { assertionCount: 8 } ) ); 21 | 22 | function fakeSensorLoop( resource ) { 23 | resource.properties.value = Math.random() + 1; 24 | 25 | // Ensure a total of six notifications 26 | timeoutId = setTimeout( fakeSensorLoop, ( Math.random() ) * 1000 + 500, resource ); 27 | 28 | resource.notify().catch( function( error ) { 29 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 30 | false, "Server: Notification error: " + 31 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 32 | ] } ) ); 33 | } ); 34 | } 35 | 36 | server 37 | .register( { 38 | resourcePath: "/a/" + process.argv[ 2 ], 39 | resourceTypes: [ "core.light" ], 40 | interfaces: [ "oic.if.baseline" ], 41 | discoverable: true, 42 | observable: true, 43 | properties: { 44 | value: Math.random() + 1 45 | } 46 | } ) 47 | .then( 48 | function( resource ) { 49 | resource.onretrieve( function( request ) { 50 | 51 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 52 | 53 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 54 | true, "Server: Retrieve request " + 55 | "(observe: " + request.observe + ", count: " + observerCount + ")" 56 | ] } ) ); 57 | 58 | // Start the notification loop when all observers have checked in 59 | if ( observerCount > 0 && !timeoutId ) { 60 | timeoutId = setTimeout( fakeSensorLoop, 1000, resource ); 61 | } else if ( observerCount === 0 && timeoutId ) { 62 | timeoutId = clearTimeout( timeoutId ); 63 | cycleCount++; 64 | } 65 | 66 | request.respond().then( 67 | function() { 68 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 69 | true, "Server: Successfully responded to retrieve request" 70 | ] } ) ); 71 | if ( cycleCount === 2 ) { 72 | console.log( JSON.stringify( { finished: 0 } ) ); 73 | } 74 | }, 75 | function( error ) { 76 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 77 | false, "Server: Failed to respond to retrieve request: " + 78 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 79 | ] } ) ); 80 | } ); 81 | } ); 82 | console.log( JSON.stringify( { ready: true } ) ); 83 | }, 84 | function( error ) { 85 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 86 | false, "Server: Registering resource failed unexpectedly: " + 87 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 88 | ] } ) ); 89 | } ); 90 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Simultaneous)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var Listener = function Listener( prefix, desiredNotificationCount ) { 18 | var countSoFar = 0; 19 | var listener = function listenToResource( resource ) { 20 | countSoFar++; 21 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 22 | resource.properties.value > 0, "Client: " + prefix + ": Received notification " + 23 | countSoFar + " of " + desiredNotificationCount 24 | ] } ) ); 25 | if ( countSoFar >= desiredNotificationCount ) { 26 | resource.removeListener( "update", listener ); 27 | } 28 | }; 29 | 30 | return listener; 31 | }; 32 | 33 | console.log( JSON.stringify( { assertionCount: 20 } ) ); 34 | 35 | function doOneRetrieveAndObserve( prefix, resource ) { 36 | client 37 | .retrieve( { deviceId: resource.deviceId, resourcePath: resource.resourcePath } ) 38 | .then( function( resource ) { 39 | resource.on( "update", Listener( prefix, 10 ) ); 40 | } ) 41 | .catch( function( error ) { 42 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 43 | false, "Unexpected error attaching listener: " + 44 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 45 | ] } ) ); 46 | } ); 47 | } 48 | 49 | function performObservation( resource ) { 50 | client.removeListener( "resourcefound", performObservation ); 51 | 52 | setTimeout( function() { 53 | doOneRetrieveAndObserve( "immediate", resource ); 54 | 55 | setTimeout( function() { 56 | doOneRetrieveAndObserve( "delayed", resource ); 57 | }, 1000 ); 58 | }, 1000 ); 59 | } 60 | 61 | client 62 | .on( "resourcefound", performObservation ) 63 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 64 | .catch( function( error ) { 65 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 66 | false, "Client: Starting device discovery failed: " + 67 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 68 | ] } ) ); 69 | } ); 70 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Observe - Resource (Simultaneous)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function FakeSensor( resource ) { 18 | var breakLength = function randomBreakLength() { 19 | return Math.random() * 1000 + 500; 20 | }; 21 | var timeout = function fakeSensorTimeout() { 22 | 23 | // Pick a random value for the fake sensor 24 | resource.properties.value = Math.random() + 1; 25 | 26 | // Set up the next notification 27 | this._timeoutId = setTimeout( timeout, breakLength() ); 28 | 29 | // Notify observers 30 | resource.notify() 31 | .catch( function( error ) { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | false, "Server: Notification error: " + 34 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 35 | ] } ) ); 36 | } ); 37 | }; 38 | 39 | if ( !( this instanceof FakeSensor ) ) { 40 | return new FakeSensor( resource ); 41 | } 42 | 43 | this._timeoutId = setTimeout( timeout, breakLength() ); 44 | } 45 | 46 | FakeSensor.prototype.stop = function stopFakeSensor() { 47 | clearTimeout( this._timeoutId ); 48 | this._timeoutId = 0; 49 | }; 50 | 51 | var fakeSensor; 52 | var oldObserverCount = 0; 53 | var observerCount = 0; 54 | 55 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 56 | 57 | server 58 | .register( { 59 | resourcePath: "/a/" + process.argv[ 2 ], 60 | resourceTypes: [ "core.light" ], 61 | interfaces: [ "oic.if.baseline" ], 62 | discoverable: true, 63 | observable: true, 64 | properties: { 65 | value: Math.random() + 1 66 | } 67 | } ) 68 | .then( 69 | function( resource ) { 70 | resource.onretrieve( function( request ) { 71 | oldObserverCount = observerCount; 72 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 73 | 74 | // Start the notification loop when all observers have checked in 75 | if ( observerCount >= 1 && oldObserverCount === 0 ) { 76 | fakeSensor = new FakeSensor( resource ); 77 | } else if ( oldObserverCount >= 1 && observerCount === 0 ) { 78 | fakeSensor = fakeSensor.stop(); 79 | console.log( JSON.stringify( { finished: 0 } ) ); 80 | } 81 | 82 | request 83 | .respond() 84 | .catch( function( error ) { 85 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 86 | false, "Server: Failed to respond to retrieve request: " + 87 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 88 | ] } ) ); 89 | } ); 90 | } ); 91 | console.log( JSON.stringify( { ready: true } ) ); 92 | }, 93 | function( error ) { 94 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 95 | false, "Server: Registering resource failed unexpectedly: " + 96 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 97 | ] } ) ); 98 | } ); 99 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Presence - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var ocf = require( process.argv[ 3 ] ); 20 | 21 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | Promise.all( [ 26 | ocf.server.register( { 27 | resourcePath: "/target-resource", 28 | resourceTypes: [ "core.light" ], 29 | interfaces: [ "oic.if.baseline" ], 30 | discoverable: true 31 | } ), 32 | ocf.server.register( { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | discoverable: true 37 | } ) 38 | ] ).then( function( resources ) { 39 | resources[ 0 ].onupdate( function( request ) { 40 | if ( request.data.uuid === process.argv[ 2 ] ) { 41 | resources[ 1 ].unregister().then( function() { 42 | return request.respond(); 43 | } ).catch( function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | "Server: Failed to respond to update() event: " + ( "" + error ) + "\n" + 46 | JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | } ); 51 | } ).catch( function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Server: Unexpected error: " + ( "" + error ) + "\n" + 54 | JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ); 57 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Presence - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var client = require( process.argv[ 3 ] ).client; 20 | 21 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 22 | 23 | var interesting = {}; 24 | 25 | var devices = []; 26 | var resources = []; 27 | 28 | // Collect the information we need for setting up the "delete" listener 29 | function testSetUp() { 30 | var device, resource; 31 | 32 | while ( devices.length > 0 && !interesting.device ) { 33 | device = devices.shift(); 34 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 35 | interesting.device = device; 36 | } 37 | } 38 | 39 | while ( resources.length > 0 && interesting.device && 40 | !( interesting.object && interesting.control ) ) { 41 | resource = resources.shift(); 42 | if ( resource.deviceId === interesting.device.uuid ) { 43 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 44 | interesting.object = resource; 45 | } else if ( resource.resourcePath === "/target-resource" ) { 46 | interesting.control = resource; 47 | } 48 | } 49 | } 50 | 51 | if ( interesting.device && interesting.control && interesting.object ) { 52 | client 53 | .removeListener( "resourcefound", resourcefound ) 54 | .removeListener( "devicefound", devicefound ); 55 | interesting.object.on( "delete", function() { 56 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 57 | true, "Client: Received 'delete' event" 58 | ] } ) ); 59 | console.log( JSON.stringify( { finished: 0 } ) ); 60 | } ); 61 | interesting.control.properties.uuid = process.argv[ 2 ]; 62 | client.update( interesting.control ).catch( function( error ) { 63 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 64 | false, "Client: Failed to update() control resource: " + ( "" + error ) + "\n" + 65 | JSON.stringify( error, null, 4 ) 66 | ] } ) ); 67 | } ); 68 | } 69 | } 70 | 71 | function resourcefound( resource ) { 72 | resources.push( resource ); 73 | testSetUp(); 74 | } 75 | 76 | function devicefound( device ) { 77 | devices.push( device ); 78 | testSetUp(); 79 | } 80 | 81 | client 82 | .on( "resourcefound", resourcefound ) 83 | .on( "devicefound", devicefound ); 84 | 85 | console.log( JSON.stringify( { ready: true } ) ); 86 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Presence/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var ocf = require( process.argv[ 3 ] ); 20 | 21 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Presence/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var client = require( process.argv[ 3 ] ).client; 20 | 21 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 22 | 23 | client 24 | .on( "devicefound", function( device ) { 25 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 26 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 27 | true, "Client: test device has appeared" 28 | ] } ) ); 29 | console.log( JSON.stringify( { finished: 0 } ) ); 30 | } 31 | } ); 32 | 33 | console.log( JSON.stringify( { ready: true } ) ); 34 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Platform/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | function devicefound( device ) { 20 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 21 | ocf.client.removeListener( "devicefound", devicefound ); 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | true, "Client: Found device" 24 | ] } ) ); 25 | ocf.client.getPlatformInfo( device.uuid ) 26 | .then( 27 | function( platform ) { 28 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 29 | platform.supportURL, "ocf://test-device-" + process.argv[ 2 ], 30 | "Client: Retrieved platform info has expected support URL" 31 | ] } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Client: Unexpectedly failed to retrieve platform info: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ) 39 | .then( function() { 40 | console.log( JSON.stringify( { finished: 0 } ) ); 41 | } ); 42 | } 43 | } 44 | 45 | ocf.client 46 | .on( "devicefound", devicefound ) 47 | .findDevices() 48 | .catch( function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Client: Starting device discovery failed: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Platform/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | ocf.platform.supportURL = "ocf://test-device-" + process.argv[ 2 ]; 22 | 23 | console.log( JSON.stringify( { ready: true } ) ); 24 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function filterKeys( object, keys ) { 16 | var index; 17 | var returnValue = {}; 18 | 19 | for ( index in keys ) { 20 | if ( keys[ index ] in object ) { 21 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 22 | } 23 | } 24 | 25 | return returnValue; 26 | } 27 | 28 | var client = require( process.argv[ 3 ] ).client; 29 | 30 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 31 | 32 | function devicefound( device ) { 33 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 34 | return; 35 | } 36 | client.removeListener( "devicefound", devicefound ); 37 | client.retrieve( { deviceId: device.uuid, resourcePath: "/non-existing-resource" } ) 38 | .then( 39 | function( resource ) { 40 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 41 | false, "Client: Retrieved non-existing resource: " + 42 | JSON.stringify( resource, null, 4 ) 43 | ] } ) ); 44 | }, 45 | function( error ) { 46 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 47 | error.message, "Access denied", 48 | "Client: Error indicating inability to directly access resource has " + 49 | "the expected message" 50 | ] } ) ); 51 | } ) 52 | .then( function() { 53 | return client.retrieve( { deviceId: device.uuid, resourcePath: "/direct" } ); 54 | } ) 55 | .then( 56 | function( resource ) { 57 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 58 | filterKeys( resource, [ 59 | "resourcePath", "properties", "deviceId" 60 | ] ), { 61 | deviceId: device.uuid, 62 | resourcePath: "/direct", 63 | properties: { 64 | name: "Pankovski" 65 | } 66 | }, "Client: Directly accessed resource has expected structure" 67 | ] } ) ); 68 | }, 69 | function( error ) { 70 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 71 | false, "Client: Failed to directly retrieve resource: " + 72 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 73 | ] } ) ); 74 | } ) 75 | .then( function() { 76 | console.log( JSON.stringify( { finished: 0 } ) ); 77 | } ); 78 | } 79 | 80 | client 81 | .findDevices( devicefound ) 82 | .catch( function( error ) { 83 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 84 | false, "Client: Failed to start device discovery: " + 85 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 86 | ] } ) ); 87 | } ); 88 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/direct", 24 | resourceTypes: [ "core.light" ], 25 | interfaces: [ "oic.if.baseline" ], 26 | discoverable: true, 27 | properties: { 28 | name: "Pankovski" 29 | } 30 | } ) 31 | .then( 32 | function( resource ) { 33 | resource.onretrieve( function( request ) { 34 | request.respond(); 35 | } ); 36 | 37 | console.log( JSON.stringify( { ready: true } ) ); 38 | }, 39 | function( error ) { 40 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 41 | false, "Server: Registering resource failed unexpectedly: " + 42 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 43 | ] } ) ); 44 | } ); 45 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource (Failure)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | client 20 | .on( "resourcefound", function( resource ) { 21 | client.retrieve( resource ) 22 | .then( 23 | function() { 24 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 25 | false, 26 | "Client: Resource retrieval succeeded" 27 | ] } ) ); 28 | }, 29 | function( error ) { 30 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 31 | error.message, "retrieve: unexpected response", 32 | "Client: retrieve() failed as expected" 33 | ] } ) ); 34 | } ) 35 | .then( function() { 36 | console.log( JSON.stringify( { finished: 0 } ) ); 37 | } ); 38 | } ) 39 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 40 | .catch( function( error ) { 41 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 42 | false, "Client: Starting device discovery failed: " + 43 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 44 | ] } ) ); 45 | } ); 46 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource (Failure)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | server 20 | .register( { 21 | resourcePath: "/a/" + process.argv[ 2 ], 22 | resourceTypes: [ "core.light" ], 23 | interfaces: [ "oic.if.baseline" ], 24 | discoverable: true 25 | } ) 26 | .then( 27 | function( resource ) { 28 | resource.onretrieve( function( request ) { 29 | request.respondWithError( "Go bug someone else!" ); 30 | } ); 31 | console.log( JSON.stringify( { ready: true } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Server: Registering resource failed unexpectedly: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ); 39 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource (Local Error).js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | client.retrieve( { resourcePath: "/a/xyzzy", deviceId: "xyzzy" } ) 20 | .then( 21 | function() { 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | false, "Succeeded retrieving fake resource - Welcome to the Twilight Zone™!" 24 | ] } ) ); 25 | }, 26 | function( error ) { 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | error.message, "Device not found", "Retrieving fake resource failed as expected" 29 | ] } ) ); 30 | } ) 31 | .then( function() { 32 | console.log( JSON.stringify( { finished: 0 } ) ); 33 | } ); 34 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 18 | 19 | function resourcefound( resource ) { 20 | client 21 | .removeListener( "resourcefound", resourcefound ) 22 | .retrieve( resource ) 23 | .then( 24 | function( retrievedResource ) { 25 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 26 | retrievedResource === resource, 27 | "Client: Retrieved resource is the discovered resource" 28 | ] } ) ); 29 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 30 | retrievedResource.properties, { value: 42, arrayValue: [ 4, 5, 6 ] }, 31 | "Client: Retrieved resource properties are as expected" 32 | ] } ) ); 33 | }, 34 | function( error ) { 35 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 36 | false, "Client: retrieve() failed unexpectedly: " + 37 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 38 | ] } ) ); 39 | } ) 40 | .then( function() { 41 | 42 | // Retrieve the resource again, this time with query options 43 | return client.retrieve( resource, { scale: -1 } ); 44 | } ) 45 | .then( 46 | function( retrievedResource ) { 47 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 48 | retrievedResource.properties, { value: -42, arrayValue: [ 4, 5, 6 ] }, 49 | "Client: Retrieved resouce properties change based on query options" 50 | ] } ) ); 51 | }, 52 | function( error ) { 53 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 54 | false, "Client: retrieve() with options failed unexpectedly: " + 55 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 56 | ] } ) ); 57 | } ) 58 | .then( function() { 59 | console.log( JSON.stringify( { finished: 0 } ) ); 60 | } ); 61 | } 62 | 63 | client 64 | .on( "resourcefound", resourcefound ) 65 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 66 | .catch( function( error ) { 67 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 68 | false, "Client: Starting device discovery failed: " + 69 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 70 | ] } ) ); 71 | } ); 72 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Retrieve - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 5 } ) ); 18 | 19 | // Multiply a value by a scale given in the options 20 | function transformSensorData( options ) { 21 | var scale = ( options && "scale" in options ) ? ( +options.scale ) : 1; 22 | 23 | if ( isNaN( scale ) ) { 24 | scale = 1; 25 | } 26 | 27 | return { value: this.properties.value * scale, arrayValue: this.properties.arrayValue }; 28 | } 29 | 30 | server 31 | .register( { 32 | resourcePath: "/a/" + process.argv[ 2 ], 33 | resourceTypes: [ "core.light" ], 34 | interfaces: [ "oic.if.baseline" ], 35 | discoverable: true 36 | } ) 37 | .then( 38 | function( resource ) { 39 | var requestCount = 0; 40 | 41 | resource.properties = { 42 | value: 42, 43 | arrayValue: [ 4, 5, 6 ] 44 | }; 45 | resource.ontranslate( transformSensorData ).onretrieve( function( request ) { 46 | if ( requestCount++ > 1 ) { 47 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 48 | false, "Server: Unexpected extra request" 49 | ] } ) ); 50 | } 51 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 52 | request.target === resource, 53 | "Server: Resource passed to retrieve request is the one that was registered" 54 | ] } ) ); 55 | request.respond() 56 | .then( 57 | function() { 58 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 59 | true, "Server: Successful response to retrieve request" 60 | ] } ) ); 61 | }, 62 | function( error ) { 63 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 64 | false, "Server: Failed to respond to retrieve request: " + 65 | ( "" + error.message ) + "\n" + 66 | JSON.stringify( error, null, 4 ) 67 | ] } ) ); 68 | } ); 69 | } ); 70 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 71 | true, "Server: Registering resource succeeded" 72 | ] } ) ); 73 | console.log( JSON.stringify( { ready: true } ) ); 74 | }, 75 | function( error ) { 76 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 77 | false, "Server: Registering resource failed unexpectedly: " + 78 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 79 | ] } ) ); 80 | } ); 81 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Structure - Client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 10 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof client.getDeviceInfo, "function", "client.getDeviceInfo is a function" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof client.getPlatformInfo, "function", "client.getPlatformInfo is a function" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | typeof client.create, "function", "client.create is a function" 29 | ] } ) ); 30 | 31 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 32 | typeof client.retrieve, "function", "client.retrieve is a function" 33 | ] } ) ); 34 | 35 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 36 | typeof client.update, "function", "client.update is a function" 37 | ] } ) ); 38 | 39 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 40 | typeof client.delete, "function", "client.delete is a function" 41 | ] } ) ); 42 | 43 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 44 | typeof client.findDevices, "function", "client.findDevices is a function" 45 | ] } ) ); 46 | 47 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 48 | typeof client.findPlatforms, "function", "client.findPlatforms is a function" 49 | ] } ) ); 50 | 51 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 52 | typeof client.findResources, "function", "client.findResources is a function" 53 | ] } ) ); 54 | 55 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 56 | typeof client.on, "function", "client.on is a function" 57 | ] } ) ); 58 | 59 | console.log( JSON.stringify( { finished: 0 } ) ); 60 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Structure - Device.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var property, updatedDevice; 16 | var ocf = require( process.argv[ 3 ] ); 17 | 18 | console.log( JSON.stringify( { assertionCount: 30 } ) ); 19 | 20 | function assertDeviceStructure( prefix ) { 21 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 22 | typeof ocf.device.name, "string", prefix + ": ocf.device.name is a string" 23 | ] } ) ); 24 | 25 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 26 | ocf.device.name, "", prefix + ": ocf.device.name is not an empty string" 27 | ] } ) ); 28 | 29 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 30 | typeof ocf.device.coreSpecVersion, "string", 31 | prefix + ": ocf.device.coreSpecVersion is a string" 32 | ] } ) ); 33 | 34 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 35 | ocf.device.coreSpecVersion, "", 36 | prefix + ": ocf.device.coreSpecVersion is not an empty string" 37 | ] } ) ); 38 | 39 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 40 | typeof ocf.device.uuid, "string", prefix + ": ocf.device.uuid is a string" 41 | ] } ) ); 42 | 43 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 44 | !!ocf.device.uuid.match( /[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}/ ), true, 45 | prefix + ": ocf.device.uuid is a UUID" 46 | ] } ) ); 47 | 48 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 49 | ocf.device.dataModels instanceof Array, true, 50 | prefix + ": ocf.device.dataModels is an array" 51 | ] } ) ); 52 | 53 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 54 | ocf.device.dataModels.length > 0, true, 55 | prefix + ": ocf.device.dataModels has at least one element" 56 | ] } ) ); 57 | 58 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 59 | typeof ocf.device.dataModels[ 0 ], "string", 60 | prefix + ": First element of ocf.device.dataModels is a string" 61 | ] } ) ); 62 | 63 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 64 | ocf.device.dataModels[ 0 ], "", 65 | prefix + ": First element of ocf.device.dataModels is not an empty string" 66 | ] } ) ); 67 | } 68 | 69 | assertDeviceStructure( "Initially" ); 70 | 71 | ocf.device.name = "some-other-name"; 72 | 73 | assertDeviceStructure( "After setting a member of ocf.device" ); 74 | 75 | // Copy the device information from ocf.device, creating a new object in the process, then 76 | // change one of the properties on the new object, and assign the whole object to ocf.device. 77 | updatedDevice = {}; 78 | for ( property in ocf.device ) { 79 | updatedDevice[ property ] = ocf.device[ property ]; 80 | } 81 | updatedDevice.name = "yet-another-name"; 82 | ocf.device = updatedDevice; 83 | 84 | assertDeviceStructure( "After setting the whole ocf.device structure" ); 85 | 86 | console.log( JSON.stringify( { finished: 0 } ) ); 87 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Structure - OCF.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 4 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof ocf.device, "object", "ocf.device is an object" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof ocf.platform, "object", "ocf.platform is an object" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | typeof ocf.client, "object", "ocf.client is an object" 29 | ] } ) ); 30 | 31 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 32 | typeof ocf.server, "object", "ocf.server is an object" 33 | ] } ) ); 34 | 35 | console.log( JSON.stringify( { finished: 0 } ) ); 36 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Structure - Platform.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var property, newValue; 16 | var ocf = require( process.argv[ 3 ] ); 17 | 18 | console.log( JSON.stringify( { assertionCount: 14 } ) ); 19 | 20 | function assertPlatformStructure( prefix ) { 21 | 22 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 23 | typeof ocf.platform.manufacturerName, "string", 24 | prefix + ": ocf.platform.manufacturerName is a string" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 28 | ocf.platform.manufacturerName, "", 29 | prefix + ": ocf.platform.manufacturerName is not an empty string" 30 | ] } ) ); 31 | 32 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 33 | typeof ocf.platform.id, "string", prefix + ": ocf.platform.id is a string" 34 | ] } ) ); 35 | 36 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 37 | !!ocf.platform.id.match( /[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}/ ), true, 38 | prefix + ": ocf.platform.id is a UUID" 39 | ] } ) ); 40 | 41 | } 42 | 43 | assertPlatformStructure( "Initially" ); 44 | 45 | ocf.platform.manufacturerName = "Test Name"; 46 | 47 | assertPlatformStructure( "Set individual platform info member" ); 48 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 49 | ocf.platform.manufacturerName, "Test Name", 50 | "Set individual platform info member: ocf.platform.manufacturerName has the expected value" 51 | ] } ) ); 52 | 53 | newValue = {}; 54 | for ( property in ocf.platform ) { 55 | newValue[ property ] = ocf.platform[ property ]; 56 | } 57 | newValue.manufacturerName = "Another Name"; 58 | ocf.platform = newValue; 59 | 60 | assertPlatformStructure( "Set entire platform info" ); 61 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 62 | ocf.platform.manufacturerName, "Another Name", 63 | "Set entire platform info: ocf.platform.manufacturerName has the expected value" 64 | ] } ) ); 65 | 66 | console.log( JSON.stringify( { finished: 0 } ) ); 67 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Structure - Server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof server.register, "function", "server.register is a function" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof server.oncreate, "function", "server.oncreate is a function" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { finished: 0 } ) ); 28 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-0/Update - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | var desiredValue = { 17 | value: 42, 18 | anotherValue: "something", 19 | childValues: { 20 | nullValue: null, 21 | booleanValue: true 22 | } 23 | }; 24 | 25 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 26 | 27 | function resourcefound( resource ) { 28 | client.removeListener( "resourcefound", resourcefound ); 29 | resource.properties = desiredValue; 30 | client.update( resource ) 31 | .then( 32 | function( updatedResource ) { 33 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 34 | updatedResource === resource, 35 | "Client: Updated resource is the discovered resource" 36 | ] } ) ); 37 | }, 38 | function( error ) { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | false, "Client: update() failed unexpectedly: " + 41 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 42 | ] } ) ); 43 | } ) 44 | .then( function() { 45 | 46 | // Retrieve the resource to see if the properties were applied 47 | return client.retrieve( resource ); 48 | } ) 49 | .then( 50 | function( retrievedResource ) { 51 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 52 | retrievedResource.properties, desiredValue, 53 | "Client: Retrieved resouce properties are as expected" 54 | ] } ) ); 55 | }, 56 | function( error ) { 57 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 58 | false, "Client: retrieve() failed unexpectedly: " + 59 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 60 | ] } ) ); 61 | } ) 62 | .then( function() { 63 | console.log( JSON.stringify( { finished: 0 } ) ); 64 | } ); 65 | } 66 | 67 | client 68 | .on( "resourcefound", resourcefound ) 69 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 70 | .catch( function( error ) { 71 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 72 | false, "Client: Starting device discovery failed: " + 73 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 74 | ] } ) ); 75 | } ); 76 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Create - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var desiredNewResource = { 18 | resourcePath: "/some/new/resource", 19 | interfaces: [ "oic.if.baseline" ], 20 | resourceTypes: [ "core.light" ], 21 | discoverable: true, 22 | secure: ( process.argv[ 4 ] === "true" ) 23 | }; 24 | 25 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 26 | 27 | function filterKeys( object, keys ) { 28 | var index; 29 | var returnValue = {}; 30 | 31 | for ( index in keys ) { 32 | if ( keys[ index ] in object ) { 33 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 34 | } 35 | } 36 | 37 | return returnValue; 38 | } 39 | 40 | // Perform directed resource discovery on a device 41 | function getResources( device ) { 42 | var resourceList = {}; 43 | 44 | function resourcefound( resource ) { 45 | if ( resource.resourcePath === desiredNewResource.resourcePath ) { 46 | resourceList.desired = resource; 47 | } 48 | } 49 | 50 | return client.findResources( { deviceId: device.uuid }, resourcefound ) 51 | .then( function() { 52 | client.removeListener( "resourcefound", resourcefound ); 53 | return resourceList; 54 | } ); 55 | } 56 | 57 | // Perform the create() method on a device if it's the right device 58 | function tryDevice( device ) { 59 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 60 | return; 61 | } 62 | 63 | // We've found the server, so stop looking 64 | client.removeListener( "devicefound", tryDevice ); 65 | 66 | desiredNewResource.deviceId = device.uuid; 67 | 68 | client.create( desiredNewResource ) 69 | .then( function( newResource ) { 70 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 71 | filterKeys( newResource, [ 72 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "deviceId", 73 | "secure" 74 | ] ), 75 | desiredNewResource, 76 | "Client: The newly created resource has the expected structure" 77 | ] } ) ); 78 | return getResources( device ); 79 | } ) 80 | .then( function( resourceList ) { 81 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 82 | resourceList.desired, 83 | "Client: After creating the resource, the device contains the desired resource" 84 | ] } ) ); 85 | console.log( JSON.stringify( { finished: 0 } ) ); 86 | } ) 87 | .catch( function( error ) { 88 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 89 | false, "Client: Failed to process device: " + 90 | ( "" + error ) + "\n" + JSON.stringify( { 91 | error: error, 92 | device: device 93 | }, null, 4 ) 94 | ] } ) ); 95 | } ); 96 | } 97 | 98 | client.findDevices( tryDevice ) 99 | .catch( function( error ) { 100 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 101 | false, "Client: Starting device discovery failed: " + 102 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 103 | ] } ) ); 104 | } ); 105 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Create - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 20 | 21 | ocf.server 22 | .oncreate( function( request ) { 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | "target" in request, false, "Server: Create request has no target" 25 | ] } ) ); 26 | ocf.server.register( request.data ) 27 | .then( 28 | function( resource ) { 29 | return request.respond( resource ); 30 | }, 31 | function( error ) { 32 | return request.respondWithError( error ); 33 | } ) 34 | .then( 35 | function() { 36 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 37 | true, "Server: Response successfully sent" 38 | ] } ) ); 39 | }, 40 | function( anError ) { 41 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 42 | false, "Server: Error: " + 43 | ( "" + anError ) + "\n" + JSON.stringify( anError, null, 4 ) 44 | ] } ) ); 45 | } ); 46 | } ); 47 | 48 | console.log( JSON.stringify( { ready: true } ) ); 49 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Create - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/target-resource", 24 | interfaces: [ "oic.if.baseline" ], 25 | resourceTypes: [ "core.light" ], 26 | secure: ( process.argv[ 4 ] === "true" ), 27 | discoverable: true 28 | } ) 29 | .then( 30 | function( resource ) { 31 | resource.oncreate( function( request ) { 32 | ocf.server.register( request.data ) 33 | .then( 34 | function( resource ) { 35 | request.respond( resource ); 36 | }, 37 | function( error ) { 38 | request.respondWithError( error ); 39 | } ); 40 | } ); 41 | console.log( JSON.stringify( { ready: true } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Failed to register resource: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Delete - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | // Perform the create() method on a device if it's the right device 20 | function tryDevice( device ) { 21 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 22 | return; 23 | } 24 | 25 | // We've found the server, so stop looking 26 | client.removeListener( "devicefound", tryDevice ); 27 | 28 | client 29 | .delete( { deviceId: device.uuid, resourcePath: "/some/new/resource" } ) 30 | .then( 31 | function() { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | true, "Client: Resource successfully deleted" 34 | ] } ) ); 35 | }, 36 | function( anError ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | false, "Client: failed to delete resource: " + 39 | ( "" + anError ) + "\n" + JSON.stringify( anError, null, 4 ) 40 | ] } ) ); 41 | } ) 42 | .then( function() { 43 | console.log( JSON.stringify( { finished: 0 } ) ); 44 | } ); 45 | } 46 | 47 | client.findDevices( tryDevice ) 48 | .catch( function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Client: Starting device discovery failed: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Delete - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/some/new/resource", 24 | interfaces: [ "oic.if.baseline" ], 25 | resourceTypes: [ "core.light" ], 26 | secure: ( process.argv[ 4 ] === "true" ), 27 | discoverable: true 28 | } ) 29 | .then( 30 | function( resource ) { 31 | resource.ondelete( function( request ) { 32 | resource.unregister() 33 | .then( 34 | function() { 35 | request.respond(); 36 | }, 37 | function( error ) { 38 | request.respondWithError( error ); 39 | } ); 40 | } ); 41 | console.log( JSON.stringify( { ready: true } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Failed to register resource: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Device/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 4 } ) ); 18 | 19 | function handleDeviceFound( device ) { 20 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 21 | ocf.client.removeListener( "devicefound", handleDeviceFound ); 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | true, "Client: Found device via .on()" 24 | ] } ) ); 25 | ocf.client.getDeviceInfo( device.uuid ) 26 | .then( 27 | function( deviceViaGet ) { 28 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 29 | deviceViaGet, device, 30 | "Client: Retrieved device info is identical to discovered device info" 31 | ] } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Client: Unexpectedly failed to retrieve device info: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ) 39 | .then( function() { 40 | console.log( JSON.stringify( { finished: 0 } ) ); 41 | } ); 42 | } 43 | } 44 | 45 | function handleDeviceFoundConvenience( device ) { 46 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 47 | ocf.client.removeListener( "devicefound", handleDeviceFoundConvenience ); 48 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 49 | true, "Client: Found device via convenience handler" 50 | ] } ) ); 51 | } 52 | } 53 | 54 | ocf.client 55 | .on( "devicefound", handleDeviceFound ) 56 | .findDevices( handleDeviceFoundConvenience ) 57 | .then( 58 | function() { 59 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 60 | true, "Client: Device discovery successfully started" 61 | ] } ) ); 62 | }, 63 | function( error ) { 64 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 65 | false, "Client: Starting device discovery failed: " + 66 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 67 | ] } ) ); 68 | } ); 69 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Device/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | console.log( JSON.stringify( { ready: true } ) ); 22 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Platform/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 18 | 19 | var conditionsMet = 0; 20 | function maybeQuit() { 21 | if ( ++conditionsMet === 2 ) { 22 | console.log( JSON.stringify( { finished: 0 } ) ); 23 | } 24 | } 25 | 26 | ocf.client 27 | .on( "platformfound", function platformFoundViaOn( platform ) { 28 | if ( platform.supportURL === "ocf://test-device-" + process.argv[ 2 ] ) { 29 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 30 | true, "Client: Found platform via .on()" 31 | ] } ) ); 32 | ocf.client.removeListener( "platformfound", platformFoundViaOn ); 33 | maybeQuit(); 34 | } 35 | } ) 36 | .findPlatforms( function platformFoundViaConvenienceHandler( platform ) { 37 | if ( platform.supportURL === "ocf://test-device-" + process.argv[ 2 ] ) { 38 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 39 | true, "Client: Found platform via convenience handler" 40 | ] } ) ); 41 | ocf.client.removeListener( "platformfound", platformFoundViaConvenienceHandler ); 42 | maybeQuit(); 43 | } 44 | } ).then( 45 | function() { 46 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 47 | true, "Client: Platform discovery successfully started" 48 | ] } ) ); 49 | }, 50 | function( error ) { 51 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 52 | true, "Client: Failed to start platform discovery: " + 53 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 54 | ] } ) ); 55 | } ); 56 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | Promise.all( [ 20 | new Promise( function( fulfill ) { 21 | function devicefound( device ) { 22 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 23 | ocf.client.removeListener( "devicefound", devicefound ); 24 | fulfill( device ); 25 | } 26 | } 27 | ocf.client.on( "devicefound", devicefound ); 28 | } ), 29 | ocf.client 30 | .findDevices() 31 | .catch( function( error ) { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | false, "Failed to start device discovery: " + 34 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 35 | ] } ) ); 36 | } ) 37 | ] ).then( function( results ) { 38 | var device = results[ 0 ]; 39 | return Promise.all( [ 40 | new Promise( function( fulfill ) { 41 | ocf.client.on( "resourcefound", function( resource ) { 42 | if ( resource.deviceId === device.uuid && 43 | resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 44 | fulfill( resource ); 45 | } 46 | } ); 47 | } ), 48 | ocf.client 49 | .findResources( { 50 | deviceId: device.uuid, 51 | resourcePath: "/a/" + process.argv[ 2 ] 52 | } ) 53 | .then( 54 | function() { 55 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 56 | true, "Client: Direct resource discovery successfully started" 57 | ] } ) ); 58 | }, 59 | function( error ) { 60 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 61 | false, "Client: Starting direct resource discovery failed: " + 62 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 63 | ] } ) ); 64 | } ) 65 | ] ).then( function() { 66 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 67 | true, "Client: Resource directly discovered" 68 | ] } ) ); 69 | console.log( JSON.stringify( { finished: 0 } ) ); 70 | } ); 71 | } ); 72 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/a/" + process.argv[ 2 ], 24 | resourceTypes: [ "core.light" ], 25 | interfaces: [ "oic.if.baseline" ], 26 | secure: ( process.argv[ 4 ] === "true" ), 27 | discoverable: true 28 | } ) 29 | .then( 30 | function() { 31 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 32 | true, "Server: Resource successfully registered" 33 | ] } ) ); 34 | console.log( JSON.stringify( { ready: true } ) ); 35 | }, 36 | function( error ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | false, "Server: Resource registration failed: " + 39 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 40 | ] } ) ); 41 | } ); 42 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Multiple Types & Interfaces)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function filterKeys( object, keys ) { 16 | var index; 17 | var returnValue = {}; 18 | 19 | for ( index in keys ) { 20 | if ( keys[ index ] in object ) { 21 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 22 | } 23 | } 24 | 25 | return returnValue; 26 | } 27 | 28 | var client = require( process.argv[ 3 ] ).client; 29 | 30 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 31 | 32 | client 33 | .on( "resourcefound", function( resource ) { 34 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 35 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 36 | filterKeys( resource, [ 37 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "observable", 38 | "secure" 39 | ] ), 40 | { 41 | resourcePath: "/a/" + process.argv[ 2 ], 42 | interfaces: [ "oic.if.baseline", "oic.if.custom" ], 43 | resourceTypes: [ "core.light", "core.fan" ], 44 | discoverable: true, 45 | observable: false, 46 | secure: ( process.argv[ 4 ] === "true" ) 47 | }, "Client: Resource found" 48 | ] } ) ); 49 | console.log( JSON.stringify( { finished: 0 } ) ); 50 | } 51 | } ) 52 | .findResources() 53 | .then( 54 | function() { 55 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 56 | true, "Client: Resource discovery successfully started" 57 | ] } ) ); 58 | }, 59 | function( error ) { 60 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 61 | false, "Client: Starting resource discovery failed: " + 62 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 63 | ] } ) ); 64 | } ); 65 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Multiple Types & Interfaces)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | server.register( { 20 | resourcePath: "/a/" + process.argv[ 2 ], 21 | resourceTypes: [ "core.light", "core.fan" ], 22 | interfaces: [ "oic.if.baseline", "oic.if.custom" ], 23 | secure: ( process.argv[ 4 ] === "true" ), 24 | discoverable: true 25 | } ).then( 26 | function() { 27 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 28 | true, "Server: Resource registered successfully" 29 | ] } ) ); 30 | 31 | console.log( JSON.stringify( { ready: true } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Server: Resource registration failed: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ).catch( 39 | function( error ) { 40 | console.log( JSON.stringify( { 41 | teardown: true, 42 | message: "Server: Fatal error: " + 43 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 44 | } ) ); 45 | } ); 46 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Repeated)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // We assume that discovery results arrive in under this many milliseconds 16 | var discoveryDuration = 6000; 17 | var client = require( process.argv[ 3 ] ).client; 18 | var firstRunResults; 19 | 20 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 21 | 22 | function doOneDiscovery() { 23 | var numberFound = 0, numberConvenientlyFound = 0; 24 | 25 | function resourcefound( resource ) { 26 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 27 | numberFound++; 28 | } 29 | } 30 | function resourcefoundConveniently( resource ) { 31 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 32 | numberConvenientlyFound++; 33 | } 34 | } 35 | 36 | return client 37 | .on( "resourcefound", resourcefound ) 38 | .findResources( resourcefoundConveniently ) 39 | .then( function() { 40 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 41 | true, "Client: Resource discovery successfully started" 42 | ] } ) ); 43 | } ) 44 | 45 | // Spend some time collecting resources using the above listeners, then clean up and return 46 | // the resulting counts 47 | .then( function() { 48 | return new Promise( function( fulfill ) { 49 | setTimeout( function() { 50 | client.removeAllListeners( "resourcefound" ); 51 | fulfill( [ numberFound, numberConvenientlyFound ] ); 52 | }, discoveryDuration ); 53 | } ); 54 | } ); 55 | } 56 | 57 | doOneDiscovery() 58 | .then( function( results ) { 59 | firstRunResults = results; 60 | return doOneDiscovery(); 61 | } ) 62 | .then( function( results ) { 63 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 64 | results, firstRunResults, 65 | "Client: Second discovery round results are identical to the first" 66 | ] } ) ); 67 | console.log( JSON.stringify( { finished: 0 } ) ); 68 | } ) 69 | .catch( function( error ) { 70 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 71 | false, "Client: Fatal error: " + ( "" + error ) + "\n" + 72 | JSON.stringify( error, null, 4 ) 73 | ] } ) ); 74 | } ); 75 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource (Repeated)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function filterKeys( object, keys ) { 18 | var index; 19 | var returnValue = {}; 20 | 21 | for ( index in keys ) { 22 | if ( keys[ index ] in object ) { 23 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 24 | } 25 | } 26 | 27 | return returnValue; 28 | } 29 | 30 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 31 | 32 | var desiredResource = { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | secure: ( process.argv[ 4 ] === "true" ), 37 | discoverable: true 38 | }; 39 | 40 | server.register( desiredResource ).then( 41 | function( resource ) { 42 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 43 | filterKeys( resource, [ 44 | "resourcePath", "resourceTypes", "interfaces", "discoverable", 45 | "secure" 46 | ] ), desiredResource, "Server: Resource registered successfully" 47 | ] } ) ); 48 | 49 | console.log( JSON.stringify( { ready: true } ) ); 50 | }, 51 | function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Server: Resource registration failed: " + 54 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ).catch( 57 | function( error ) { 58 | console.log( JSON.stringify( { 59 | teardown: true, 60 | message: "Server: Fatal error: " + 61 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 62 | } ) ); 63 | } ); 64 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var conditionsMet = 0; 16 | function maybeQuit() { 17 | if ( ++conditionsMet === 2 ) { 18 | console.log( JSON.stringify( { finished: 0 } ) ); 19 | } 20 | } 21 | 22 | function filterKeys( object, keys ) { 23 | var index; 24 | var returnValue = {}; 25 | 26 | for ( index in keys ) { 27 | if ( keys[ index ] in object ) { 28 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 29 | } 30 | } 31 | 32 | return returnValue; 33 | } 34 | 35 | var client = require( process.argv[ 3 ] ).client; 36 | 37 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 38 | 39 | function resourcefound( resource ) { 40 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 41 | client.removeListener( "resourcefound", resourcefound ); 42 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 43 | filterKeys( resource, [ 44 | "resourcePath", "interfaces", "resourceTypes", "discoverable", "observable", 45 | "secure" 46 | ] ), 47 | { 48 | resourcePath: "/a/" + process.argv[ 2 ], 49 | interfaces: [ "oic.if.baseline" ], 50 | resourceTypes: [ "core.light" ], 51 | discoverable: true, 52 | observable: false, 53 | secure: ( process.argv[ 4 ] === "true" ) 54 | }, "Client: Resource found via .on()" 55 | ] } ) ); 56 | maybeQuit(); 57 | } 58 | } 59 | 60 | function resourcefoundConveniently( resource ) { 61 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 62 | client.removeListener( "resourcefound", resourcefoundConveniently ); 63 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 64 | true, "Client: Resource found via convenience handler" 65 | ] } ) ); 66 | maybeQuit(); 67 | } 68 | } 69 | 70 | client 71 | .on( "resourcefound", resourcefound ) 72 | .findResources( resourcefoundConveniently ) 73 | .then( 74 | function() { 75 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 76 | true, "Client: Resource discovery successfully started" 77 | ] } ) ); 78 | }, 79 | function( error ) { 80 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 81 | false, "Client: Starting resource discovery failed: " + 82 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 83 | ] } ) ); 84 | } ); 85 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Discovery - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function filterKeys( object, keys ) { 18 | var index; 19 | var returnValue = {}; 20 | 21 | for ( index in keys ) { 22 | if ( keys[ index ] in object ) { 23 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 24 | } 25 | } 26 | 27 | return returnValue; 28 | } 29 | 30 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 31 | 32 | var desiredResource = { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | secure: ( process.argv[ 4 ] === "true" ), 37 | discoverable: true 38 | }; 39 | 40 | server.register( desiredResource ).then( 41 | function( resource ) { 42 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 43 | filterKeys( resource, [ 44 | "resourcePath", "resourceTypes", "interfaces", "discoverable", "secure" 45 | ] ), desiredResource, "Server: Resource registered successfully" 46 | ] } ) ); 47 | 48 | console.log( JSON.stringify( { ready: true } ) ); 49 | }, 50 | function( error ) { 51 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 52 | false, "Server: Resource registration failed: " + 53 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 54 | ] } ) ); 55 | } ).catch( 56 | function( error ) { 57 | console.log( JSON.stringify( { 58 | teardown: true, 59 | message: "Server: Fatal error: " + 60 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 61 | } ) ); 62 | } ); 63 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Direct - Unobservable)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | // Dummy listener function. 20 | function listener() {} 21 | 22 | function devicefound( device ) { 23 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 24 | return; 25 | } 26 | client.removeListener( "devicefound", devicefound ); 27 | client.retrieve( { 28 | deviceId: device.uuid, 29 | resourcePath: "/a/" + process.argv[ 2 ] 30 | }, listener ) 31 | .then( 32 | function( resource ) { 33 | client.retrieve( resource, listener, true ); 34 | console.log( JSON.stringify( { finished: 0 } ) ); 35 | }, 36 | function( error ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | false, "Client: Failed to directly retrieve resource: " + 39 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 40 | ] } ) ); 41 | } ); 42 | } 43 | 44 | client 45 | .findDevices( devicefound ) 46 | .catch( function( error ) { 47 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 48 | false, "Client: Failed to start device discovery: " + 49 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 50 | ] } ) ); 51 | } ); 52 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Direct - Unobservable)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | var server = ocf.server; 17 | 18 | var oldObserverCount = 0; 19 | var observerCount = 0; 20 | var timeoutId; 21 | var fakeSensorStarted = false; 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 26 | 27 | function fakeSensorLoop( resource ) { 28 | var notificationCount = 0; 29 | function timeout() { 30 | resource.properties.value = Math.random() + 1; 31 | 32 | // Ensure a total of six notifications 33 | timeoutId = ( ++notificationCount < 2 ) ? 34 | setTimeout( timeout, ( Math.random() ) * 1000 + 500 ) : 0; 35 | 36 | resource.notify() 37 | .then( 38 | function() { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | true, "Server: Notification successful" 41 | ] } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Notification error: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | timeout(); 51 | } 52 | 53 | server 54 | .register( { 55 | resourcePath: "/a/" + process.argv[ 2 ], 56 | resourceTypes: [ "core.light" ], 57 | interfaces: [ "oic.if.baseline" ], 58 | discoverable: true, 59 | secure: ( process.argv[ 4 ] === "true" ), 60 | properties: { 61 | value: Math.random() + 1 62 | } 63 | } ) 64 | .then( 65 | function( resource ) { 66 | resource.onretrieve( function( request ) { 67 | oldObserverCount = observerCount; 68 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 69 | 70 | // Start the notification loop when all observers have checked in 71 | if ( observerCount >= 1 && !fakeSensorStarted ) { 72 | fakeSensorLoop( resource ); 73 | fakeSensorStarted = true; 74 | } 75 | 76 | request.respond() 77 | .then( 78 | function() { 79 | 80 | // We quit when the last observer was removed 81 | if ( oldObserverCount > 0 && observerCount === 0 ) { 82 | console.log( JSON.stringify( { 83 | assertion: "ok", 84 | arguments: [ 85 | timeoutId === 0, 86 | "Server: Timeout was removed by the time the last " + 87 | "observer signed off" 88 | ] } ) ); 89 | console.log( JSON.stringify( { finished: 0 } ) ); 90 | } 91 | }, 92 | function( error ) { 93 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 94 | false, "Server: Failed to respond to retrieve request: " + 95 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 96 | ] } ) ); 97 | } ); 98 | } ); 99 | console.log( JSON.stringify( { ready: true } ) ); 100 | }, 101 | function( error ) { 102 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 103 | false, "Server: Registering resource failed unexpectedly: " + 104 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 105 | ] } ) ); 106 | } ); 107 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var observationCount = 0; 18 | 19 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 20 | 21 | function listener( resource ) { 22 | observationCount++; 23 | if ( observationCount === 3 ) { 24 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 25 | true, "Client: Performed three observations" 26 | ] } ) ); 27 | client.retrieve( resource, listener, true ); 28 | } 29 | } 30 | 31 | function devicefound( device ) { 32 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 33 | return; 34 | } 35 | client.removeListener( "devicefound", devicefound ); 36 | client.retrieve( { 37 | deviceId: device.uuid, 38 | resourcePath: "/a/" + process.argv[ 2 ] 39 | }, listener ) 40 | .catch( 41 | function( error ) { 42 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 43 | false, "Client: Failed to directly retrieve resource: " + 44 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 45 | ] } ) ); 46 | } ); 47 | } 48 | 49 | client 50 | .findDevices( devicefound ) 51 | .catch( function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Client: Failed to start device discovery: " + 54 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ); 57 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | var server = ocf.server; 17 | 18 | var oldObserverCount = 0; 19 | var observerCount = 0; 20 | var timeoutId; 21 | var fakeSensorStarted = false; 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 26 | 27 | function fakeSensorLoop( resource ) { 28 | var notificationCount = 0; 29 | function timeout() { 30 | resource.properties.value = Math.random() + 1; 31 | 32 | // Ensure a total of six notifications 33 | timeoutId = ( ++notificationCount < 2 ) ? 34 | setTimeout( timeout, ( Math.random() ) * 1000 + 500 ) : 0; 35 | 36 | resource.notify() 37 | .then( 38 | function() { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | true, "Server: Notification successful" 41 | ] } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | false, "Server: Notification error: " + 46 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | timeout(); 51 | } 52 | 53 | server 54 | .register( { 55 | resourcePath: "/a/" + process.argv[ 2 ], 56 | resourceTypes: [ "core.light" ], 57 | interfaces: [ "oic.if.baseline" ], 58 | discoverable: true, 59 | secure: ( process.argv[ 4 ] === "true" ), 60 | observable: true, 61 | properties: { 62 | value: Math.random() + 1 63 | } 64 | } ) 65 | .then( 66 | function( resource ) { 67 | resource.onretrieve( function( request ) { 68 | oldObserverCount = observerCount; 69 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 70 | 71 | // Start the notification loop when all observers have checked in 72 | if ( observerCount >= 1 && !fakeSensorStarted ) { 73 | fakeSensorLoop( resource ); 74 | fakeSensorStarted = true; 75 | } 76 | 77 | request.respond() 78 | .then( 79 | function() { 80 | 81 | // We quit when the last observer was removed 82 | if ( oldObserverCount > 0 && observerCount === 0 ) { 83 | console.log( JSON.stringify( { 84 | assertion: "ok", 85 | arguments: [ 86 | timeoutId === 0, 87 | "Server: Timeout was removed by the time the last " + 88 | "observer signed off" 89 | ] } ) ); 90 | console.log( JSON.stringify( { finished: 0 } ) ); 91 | } 92 | }, 93 | function( error ) { 94 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 95 | false, "Server: Failed to respond to retrieve request: " + 96 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 97 | ] } ) ); 98 | } ); 99 | } ); 100 | console.log( JSON.stringify( { ready: true } ) ); 101 | }, 102 | function( error ) { 103 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 104 | false, "Server: Registering resource failed unexpectedly: " + 105 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 106 | ] } ) ); 107 | } ); 108 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Failure)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | function pickEndpoint( endpoints ) { 20 | var index, isSecureEndpoint; 21 | 22 | for ( index in endpoints ) { 23 | isSecureEndpoint = endpoints[ index ].origin.substr( 0, 5 ) === "coaps"; 24 | if ( isSecureEndpoint && process.argv[ 4 ] === "true" ) { 25 | return endpoints[ index ]; 26 | } else if ( !isSecureEndpoint && process.argv[ 4 ] === "false" ) { 27 | return endpoints[ index ]; 28 | } 29 | } 30 | } 31 | 32 | function dummyListener() {} 33 | 34 | function performObservation( resource ) { 35 | resource.endpoint = pickEndpoint( resource.endpoints ); 36 | resource 37 | .on( "error", function( error ) { 38 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 39 | error.message, "Server responded with error", 40 | "Client: Failure to observe resulted in expected error" 41 | ] } ) ); 42 | console.log( JSON.stringify( { finished: 0 } ) ); 43 | } ); 44 | client.retrieve( resource, dummyListener ); 45 | client.removeListener( "resourcefound", performObservation ); 46 | } 47 | 48 | client 49 | .on( "resourcefound", performObservation ) 50 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 51 | .catch( function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Client: Starting device discovery failed: " + 54 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ); 57 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Failure)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | server 20 | .register( { 21 | resourcePath: "/a/" + process.argv[ 2 ], 22 | resourceTypes: [ "core.light" ], 23 | interfaces: [ "oic.if.baseline" ], 24 | discoverable: true, 25 | secure: ( process.argv[ 4 ] === "true" ), 26 | observable: true 27 | } ) 28 | .then( 29 | function( resource ) { 30 | resource.onretrieve( function( request ) { 31 | request.respondWithError( "Go about yer merry way!" ); 32 | } ); 33 | console.log( JSON.stringify( { ready: true } ) ); 34 | }, 35 | function( error ) { 36 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 37 | false, "Server: Registering resource failed unexpectedly: " + 38 | ( "" + error ) + "\n" + JSON.stringify( error ) 39 | ] } ) ); 40 | } ); 41 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Repeated)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | function pickEndpoint( endpoints ) { 20 | var index, isSecureEndpoint; 21 | 22 | for ( index in endpoints ) { 23 | isSecureEndpoint = endpoints[ index ].origin.substr( 0, 5 ) === "coaps"; 24 | if ( isSecureEndpoint && process.argv[ 4 ] === "true" ) { 25 | return endpoints[ index ]; 26 | } else if ( !isSecureEndpoint && process.argv[ 4 ] === "false" ) { 27 | return endpoints[ index ]; 28 | } 29 | } 30 | } 31 | 32 | function observeResource( resource ) { 33 | return new Promise( function( fulfill ) { 34 | var updateCount = 0; 35 | function update( resource ) { 36 | if ( ++updateCount === 6 ) { 37 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 38 | true, "Client: Observation sequence complete" 39 | ] } ) ); 40 | client.retrieve( resource, update, true ).then( fulfill ); 41 | } 42 | } 43 | resource.endpoint = pickEndpoint( resource.endpoints ); 44 | client.retrieve( resource, update ); 45 | } ); 46 | } 47 | 48 | function resourcefound( resource ) { 49 | client.removeListener( "resourcefound", resourcefound ); 50 | observeResource( resource ) 51 | .then( function() { 52 | return new Promise( function( fulfill ) { 53 | setTimeout( function() { 54 | fulfill( observeResource( resource ) ); 55 | }, 5000 ); 56 | } ); 57 | } ) 58 | .catch( function( error ) { 59 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 60 | false, "Client: Error during observation: " + ( "" + error ) + "\n" + 61 | JSON.stringify( error, null, 4 ) 62 | ] } ) ); 63 | } ); 64 | } 65 | 66 | client 67 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] }, resourcefound ) 68 | .catch( function( error ) { 69 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 70 | false, "Client: Failed to initiate resource discovery: " + ( "" + error ) + "\n" + 71 | JSON.stringify( error, null, 4 ) 72 | ] } ) ); 73 | } ); 74 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Repeated)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | var timeoutId = 0; 17 | var observerCount = 0; 18 | var cycleCount = 0; 19 | 20 | console.log( JSON.stringify( { assertionCount: 8 } ) ); 21 | 22 | function fakeSensorLoop( resource ) { 23 | resource.properties.value = Math.random() + 1; 24 | 25 | // Ensure a total of six notifications 26 | timeoutId = setTimeout( fakeSensorLoop, ( Math.random() ) * 1000 + 500, resource ); 27 | 28 | resource.notify().catch( function( error ) { 29 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 30 | false, "Server: Notification error: " + 31 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 32 | ] } ) ); 33 | } ); 34 | } 35 | 36 | server 37 | .register( { 38 | resourcePath: "/a/" + process.argv[ 2 ], 39 | resourceTypes: [ "core.light" ], 40 | interfaces: [ "oic.if.baseline" ], 41 | discoverable: true, 42 | secure: ( process.argv[ 4 ] === "true" ), 43 | observable: true, 44 | properties: { 45 | value: Math.random() + 1 46 | } 47 | } ) 48 | .then( 49 | function( resource ) { 50 | resource.onretrieve( function( request ) { 51 | 52 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 53 | 54 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 55 | true, "Server: Retrieve request " + 56 | "(observe: " + request.observe + ", count: " + observerCount + ")" 57 | ] } ) ); 58 | 59 | // Start the notification loop when all observers have checked in 60 | if ( observerCount > 0 && !timeoutId ) { 61 | timeoutId = setTimeout( fakeSensorLoop, 1000, resource ); 62 | } else if ( observerCount === 0 && timeoutId ) { 63 | timeoutId = clearTimeout( timeoutId ); 64 | cycleCount++; 65 | } 66 | 67 | request.respond().then( 68 | function() { 69 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 70 | true, "Server: Successfully responded to retrieve request" 71 | ] } ) ); 72 | if ( cycleCount === 2 ) { 73 | console.log( JSON.stringify( { finished: 0 } ) ); 74 | } 75 | }, 76 | function( error ) { 77 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 78 | false, "Server: Failed to respond to retrieve request: " + 79 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 80 | ] } ) ); 81 | } ); 82 | } ); 83 | console.log( JSON.stringify( { ready: true } ) ); 84 | }, 85 | function( error ) { 86 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 87 | false, "Server: Registering resource failed unexpectedly: " + 88 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 89 | ] } ) ); 90 | } ); 91 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Simultaneous)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | var Listener = function Listener( prefix, desiredNotificationCount ) { 18 | var countSoFar = 0; 19 | var listener = function listenToResource( resource ) { 20 | countSoFar++; 21 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 22 | resource.properties.value > 0, "Client: " + prefix + ": Received notification " + 23 | countSoFar + " of " + desiredNotificationCount 24 | ] } ) ); 25 | if ( countSoFar >= desiredNotificationCount ) { 26 | client 27 | .retrieve( resource, listener, true ) 28 | .catch( function( error ) { 29 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 30 | false, "Unexpected error detaching listener: " + 31 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 32 | ] } ) ); 33 | } ); 34 | } 35 | }; 36 | 37 | return listener; 38 | }; 39 | 40 | console.log( JSON.stringify( { assertionCount: 20 } ) ); 41 | 42 | function doOneRetrieveAndObserve( prefix, resource ) { 43 | client 44 | .retrieve( { deviceId: resource.deviceId, resourcePath: resource.resourcePath } ) 45 | .then( function( resource ) { 46 | return client.retrieve( resource, Listener( prefix, 10 ) ); 47 | } ) 48 | .catch( function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Unexpected error attaching listener: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | } 55 | 56 | function performObservation( resource ) { 57 | client.removeListener( "resourcefound", performObservation ); 58 | 59 | setTimeout( function() { 60 | doOneRetrieveAndObserve( "immediate", resource ); 61 | 62 | setTimeout( function() { 63 | doOneRetrieveAndObserve( "delayed", resource ); 64 | }, 1000 ); 65 | }, 1000 ); 66 | } 67 | 68 | client 69 | .on( "resourcefound", performObservation ) 70 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 71 | .catch( function( error ) { 72 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 73 | false, "Client: Starting device discovery failed: " + 74 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 75 | ] } ) ); 76 | } ); 77 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Observe - Resource (Simultaneous)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | function FakeSensor( resource ) { 18 | var breakLength = function randomBreakLength() { 19 | return Math.random() * 1000 + 500; 20 | }; 21 | var timeout = function fakeSensorTimeout() { 22 | 23 | // Pick a random value for the fake sensor 24 | resource.properties.value = Math.random() + 1; 25 | 26 | // Set up the next notification 27 | this._timeoutId = setTimeout( timeout, breakLength() ); 28 | 29 | // Notify observers 30 | resource.notify() 31 | .catch( function( error ) { 32 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 33 | false, "Server: Notification error: " + 34 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 35 | ] } ) ); 36 | } ); 37 | }; 38 | 39 | if ( !( this instanceof FakeSensor ) ) { 40 | return new FakeSensor( resource ); 41 | } 42 | 43 | this._timeoutId = setTimeout( timeout, breakLength() ); 44 | } 45 | 46 | FakeSensor.prototype.stop = function stopFakeSensor() { 47 | clearTimeout( this._timeoutId ); 48 | this._timeoutId = 0; 49 | }; 50 | 51 | var fakeSensor; 52 | var oldObserverCount = 0; 53 | var observerCount = 0; 54 | 55 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 56 | 57 | server 58 | .register( { 59 | resourcePath: "/a/" + process.argv[ 2 ], 60 | resourceTypes: [ "core.light" ], 61 | interfaces: [ "oic.if.baseline" ], 62 | discoverable: true, 63 | secure: ( process.argv[ 4 ] === "true" ), 64 | observable: true, 65 | properties: { 66 | value: Math.random() + 1 67 | } 68 | } ) 69 | .then( 70 | function( resource ) { 71 | resource.onretrieve( function( request ) { 72 | oldObserverCount = observerCount; 73 | observerCount += ( "observe" in request ) ? ( request.observe ? 1 : -1 ) : 0; 74 | 75 | // Start the notification loop when all observers have checked in 76 | if ( observerCount >= 1 && oldObserverCount === 0 ) { 77 | fakeSensor = new FakeSensor( resource ); 78 | } else if ( oldObserverCount >= 1 && observerCount === 0 ) { 79 | fakeSensor = fakeSensor.stop(); 80 | console.log( JSON.stringify( { finished: 0 } ) ); 81 | } 82 | 83 | request 84 | .respond() 85 | .catch( function( error ) { 86 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 87 | false, "Server: Failed to respond to retrieve request: " + 88 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 89 | ] } ) ); 90 | } ); 91 | } ); 92 | console.log( JSON.stringify( { ready: true } ) ); 93 | }, 94 | function( error ) { 95 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 96 | false, "Server: Registering resource failed unexpectedly: " + 97 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 98 | ] } ) ); 99 | } ); 100 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Presence - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var ocf = require( process.argv[ 3 ] ); 20 | 21 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | 25 | Promise.all( [ 26 | ocf.server.register( { 27 | resourcePath: "/target-resource", 28 | resourceTypes: [ "core.light" ], 29 | interfaces: [ "oic.if.baseline" ], 30 | discoverable: true 31 | } ), 32 | ocf.server.register( { 33 | resourcePath: "/a/" + process.argv[ 2 ], 34 | resourceTypes: [ "core.light" ], 35 | interfaces: [ "oic.if.baseline" ], 36 | discoverable: true 37 | } ) 38 | ] ).then( function( resources ) { 39 | resources[ 0 ].onupdate( function( request ) { 40 | if ( request.data.uuid === process.argv[ 2 ] ) { 41 | resources[ 1 ].unregister().then( function() { 42 | return request.respond(); 43 | } ).catch( function( error ) { 44 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 45 | "Server: Failed to respond to update() event: " + ( "" + error ) + "\n" + 46 | JSON.stringify( error, null, 4 ) 47 | ] } ) ); 48 | } ); 49 | } 50 | } ); 51 | } ).catch( function( error ) { 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | false, "Server: Unexpected error: " + ( "" + error ) + "\n" + 54 | JSON.stringify( error, null, 4 ) 55 | ] } ) ); 56 | } ); 57 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Presence - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var client = require( process.argv[ 3 ] ).client; 20 | 21 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 22 | 23 | var interesting = {}; 24 | 25 | var devices = []; 26 | var resources = []; 27 | 28 | // Collect the information we need for setting up the "delete" listener 29 | function testSetUp() { 30 | var device, resource; 31 | 32 | while ( devices.length > 0 && !interesting.device ) { 33 | device = devices.shift(); 34 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 35 | interesting.device = device; 36 | } 37 | } 38 | 39 | while ( resources.length > 0 && interesting.device && 40 | !( interesting.object && interesting.control ) ) { 41 | resource = resources.shift(); 42 | if ( resource.deviceId === interesting.device.uuid ) { 43 | if ( resource.resourcePath === "/a/" + process.argv[ 2 ] ) { 44 | interesting.object = resource; 45 | } else if ( resource.resourcePath === "/target-resource" ) { 46 | interesting.control = resource; 47 | } 48 | } 49 | } 50 | 51 | if ( interesting.device && interesting.control && interesting.object ) { 52 | client 53 | .removeListener( "resourcefound", resourcefound ) 54 | .removeListener( "devicefound", devicefound ); 55 | interesting.object.on( "delete", function() { 56 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 57 | true, "Client: Received 'delete' event" 58 | ] } ) ); 59 | console.log( JSON.stringify( { finished: 0 } ) ); 60 | } ); 61 | interesting.control.properties.uuid = process.argv[ 2 ]; 62 | client.update( interesting.control ).catch( function( error ) { 63 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 64 | false, "Client: Failed to update() control resource: " + ( "" + error ) + "\n" + 65 | JSON.stringify( error, null, 4 ) 66 | ] } ) ); 67 | } ); 68 | } 69 | } 70 | 71 | function resourcefound( resource ) { 72 | resources.push( resource ); 73 | testSetUp(); 74 | } 75 | 76 | function devicefound( device ) { 77 | devices.push( device ); 78 | testSetUp(); 79 | } 80 | 81 | client 82 | .on( "resourcefound", resourcefound ) 83 | .on( "devicefound", devicefound ); 84 | 85 | console.log( JSON.stringify( { ready: true } ) ); 86 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Presence/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var ocf = require( process.argv[ 3 ] ); 20 | 21 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 22 | 23 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 24 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Presence/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // The file names for client and server are reversed in this test, because the test suite uses the 16 | // file name to decide which to run first ("server.js"). In the case of presence, however, the 17 | // client must run first, because it must catch the announcement from the server when it comes up. 18 | 19 | var client = require( process.argv[ 3 ] ).client; 20 | 21 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 22 | 23 | client 24 | .on( "devicefound", function( device ) { 25 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 26 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 27 | true, "Client: test device has appeared" 28 | ] } ) ); 29 | console.log( JSON.stringify( { finished: 0 } ) ); 30 | } 31 | } ); 32 | 33 | console.log( JSON.stringify( { ready: true } ) ); 34 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Platform/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | function devicefound( device ) { 20 | if ( device.name === "test-device-" + process.argv[ 2 ] ) { 21 | ocf.client.removeListener( "devicefound", devicefound ); 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | true, "Client: Found device" 24 | ] } ) ); 25 | ocf.client.getPlatformInfo( device.uuid ) 26 | .then( 27 | function( platform ) { 28 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 29 | platform.supportURL, "ocf://test-device-" + process.argv[ 2 ], 30 | "Client: Retrieved platform info has expected support URL" 31 | ] } ) ); 32 | }, 33 | function( error ) { 34 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 35 | false, "Client: Unexpectedly failed to retrieve platform info: " + 36 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 37 | ] } ) ); 38 | } ) 39 | .then( function() { 40 | console.log( JSON.stringify( { finished: 0 } ) ); 41 | } ); 42 | } 43 | } 44 | 45 | ocf.client 46 | .on( "devicefound", devicefound ) 47 | .findDevices() 48 | .catch( function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Client: Starting device discovery failed: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ); 54 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Platform/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 20 | 21 | ocf.platform.supportURL = "ocf://test-device-" + process.argv[ 2 ]; 22 | 23 | console.log( JSON.stringify( { ready: true } ) ); 24 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource (Direct)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function filterKeys( object, keys ) { 16 | var index; 17 | var returnValue = {}; 18 | 19 | for ( index in keys ) { 20 | if ( keys[ index ] in object ) { 21 | returnValue[ keys[ index ] ] = object[ keys[ index ] ]; 22 | } 23 | } 24 | 25 | return returnValue; 26 | } 27 | 28 | var client = require( process.argv[ 3 ] ).client; 29 | 30 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 31 | 32 | function devicefound( device ) { 33 | if ( device.name !== "test-device-" + process.argv[ 2 ] ) { 34 | return; 35 | } 36 | client.removeListener( "devicefound", devicefound ); 37 | client.retrieve( { deviceId: device.uuid, resourcePath: "/non-existing-resource" } ) 38 | .then( 39 | function( resource ) { 40 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 41 | false, "Client: Retrieved non-existing resource: " + 42 | JSON.stringify( resource, null, 4 ) 43 | ] } ) ); 44 | }, 45 | function( error ) { 46 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 47 | error.message, "Access denied", 48 | "Client: Error indicating inability to directly access resource has " + 49 | "the expected message" 50 | ] } ) ); 51 | } ) 52 | .then( function() { 53 | return client.retrieve( { deviceId: device.uuid, resourcePath: "/direct" } ); 54 | } ) 55 | .then( 56 | function( resource ) { 57 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 58 | filterKeys( resource, [ 59 | "resourcePath", "properties", "deviceId" 60 | ] ), { 61 | deviceId: device.uuid, 62 | resourcePath: "/direct", 63 | properties: { 64 | name: "Pankovski" 65 | } 66 | }, "Client: Directly accessed resource has expected structure" 67 | ] } ) ); 68 | }, 69 | function( error ) { 70 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 71 | false, "Client: Failed to directly retrieve resource: " + 72 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 73 | ] } ) ); 74 | } ) 75 | .then( function() { 76 | console.log( JSON.stringify( { finished: 0 } ) ); 77 | } ); 78 | } 79 | 80 | client 81 | .findDevices( devicefound ) 82 | .catch( function( error ) { 83 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 84 | false, "Client: Failed to start device discovery: " + 85 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 86 | ] } ) ); 87 | } ); 88 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource (Direct)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | ocf.device.name = "test-device-" + process.argv[ 2 ]; 18 | 19 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 20 | 21 | ocf.server 22 | .register( { 23 | resourcePath: "/direct", 24 | resourceTypes: [ "core.light" ], 25 | interfaces: [ "oic.if.baseline" ], 26 | discoverable: true, 27 | secure: ( process.argv[ 4 ] === "true" ), 28 | properties: { 29 | name: "Pankovski" 30 | } 31 | } ) 32 | .then( 33 | function( resource ) { 34 | resource.onretrieve( function( request ) { 35 | request.respond(); 36 | } ); 37 | 38 | console.log( JSON.stringify( { ready: true } ) ); 39 | }, 40 | function( error ) { 41 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 42 | false, "Server: Registering resource failed unexpectedly: " + 43 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 44 | ] } ) ); 45 | } ); 46 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource (Failure)/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | function pickEndpoint( endpoints ) { 20 | var index, isSecureEndpoint; 21 | 22 | for ( index in endpoints ) { 23 | isSecureEndpoint = endpoints[ index ].origin.substr( 0, 5 ) === "coaps"; 24 | if ( isSecureEndpoint && process.argv[ 4 ] === "true" ) { 25 | return endpoints[ index ]; 26 | } else if ( !isSecureEndpoint && process.argv[ 4 ] === "false" ) { 27 | return endpoints[ index ]; 28 | } 29 | } 30 | } 31 | 32 | client 33 | .on( "resourcefound", function( resource ) { 34 | resource.endpoint = pickEndpoint( resource.endpoints ); 35 | client.retrieve( resource ) 36 | .then( 37 | function() { 38 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 39 | false, 40 | "Client: Resource retrieval succeeded" 41 | ] } ) ); 42 | }, 43 | function( error ) { 44 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 45 | error.message, "retrieve: unexpected response", 46 | "Client: retrieve() failed as expected" 47 | ] } ) ); 48 | } ) 49 | .then( function() { 50 | console.log( JSON.stringify( { finished: 0 } ) ); 51 | } ); 52 | } ) 53 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 54 | .catch( function( error ) { 55 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 56 | false, "Client: Starting device discovery failed: " + 57 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 58 | ] } ) ); 59 | } ); 60 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource (Failure)/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 0 } ) ); 18 | 19 | server 20 | .register( { 21 | resourcePath: "/a/" + process.argv[ 2 ], 22 | resourceTypes: [ "core.light" ], 23 | interfaces: [ "oic.if.baseline" ], 24 | secure: ( process.argv[ 4 ] === "true" ), 25 | discoverable: true 26 | } ) 27 | .then( 28 | function( resource ) { 29 | resource.onretrieve( function( request ) { 30 | request.respondWithError( "Go bug someone else!" ); 31 | } ); 32 | console.log( JSON.stringify( { ready: true } ) ); 33 | }, 34 | function( error ) { 35 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 36 | false, "Server: Registering resource failed unexpectedly: " + 37 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 38 | ] } ) ); 39 | } ); 40 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource (Local Error).js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 1 } ) ); 18 | 19 | client.retrieve( { resourcePath: "/a/xyzzy", deviceId: "xyzzy" } ) 20 | .then( 21 | function() { 22 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 23 | false, "Succeeded retrieving fake resource - Welcome to the Twilight Zone™!" 24 | ] } ) ); 25 | }, 26 | function( error ) { 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | error.message, "Device not found", "Retrieving fake resource failed as expected" 29 | ] } ) ); 30 | } ) 31 | .then( function() { 32 | console.log( JSON.stringify( { finished: 0 } ) ); 33 | } ); 34 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | function pickEndpoint( endpoints ) { 18 | var index, isSecureEndpoint; 19 | 20 | for ( index in endpoints ) { 21 | isSecureEndpoint = endpoints[ index ].origin.substr( 0, 5 ) === "coaps"; 22 | if ( isSecureEndpoint && process.argv[ 4 ] === "true" ) { 23 | return endpoints[ index ]; 24 | } else if ( !isSecureEndpoint && process.argv[ 4 ] === "false" ) { 25 | return endpoints[ index ]; 26 | } 27 | } 28 | } 29 | 30 | console.log( JSON.stringify( { assertionCount: 3 } ) ); 31 | 32 | function resourcefound( resource ) { 33 | resource.endpoint = pickEndpoint( resource.endpoints ); 34 | client 35 | .removeListener( "resourcefound", resourcefound ) 36 | .retrieve( resource ) 37 | .then( 38 | function( retrievedResource ) { 39 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 40 | retrievedResource === resource, 41 | "Client: Retrieved resource is the discovered resource" 42 | ] } ) ); 43 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 44 | retrievedResource.properties, { value: 42, arrayValue: [ 4, 5, 6 ] }, 45 | "Client: Retrieved resource properties are as expected" 46 | ] } ) ); 47 | }, 48 | function( error ) { 49 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 50 | false, "Client: retrieve() failed unexpectedly: " + 51 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 52 | ] } ) ); 53 | } ) 54 | .then( function() { 55 | 56 | // Retrieve the resource again, this time with query options 57 | return client.retrieve( resource, { scale: -1 } ); 58 | } ) 59 | .then( 60 | function( retrievedResource ) { 61 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 62 | retrievedResource.properties, { value: -42, arrayValue: [ 4, 5, 6 ] }, 63 | "Client: Retrieved resouce properties change based on query options" 64 | ] } ) ); 65 | }, 66 | function( error ) { 67 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 68 | false, "Client: retrieve() with options failed unexpectedly: " + 69 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 70 | ] } ) ); 71 | } ) 72 | .then( function() { 73 | console.log( JSON.stringify( { finished: 0 } ) ); 74 | } ); 75 | } 76 | 77 | client 78 | .on( "resourcefound", resourcefound ) 79 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 80 | .catch( function( error ) { 81 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 82 | false, "Client: Starting device discovery failed: " + 83 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 84 | ] } ) ); 85 | } ); 86 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Retrieve - Resource/server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 5 } ) ); 18 | 19 | // Multiply a value by a scale given in the options 20 | function transformSensorData( options ) { 21 | var scale = ( options && "scale" in options ) ? ( +options.scale ) : 1; 22 | 23 | if ( isNaN( scale ) ) { 24 | scale = 1; 25 | } 26 | 27 | return { value: this.properties.value * scale, arrayValue: this.properties.arrayValue }; 28 | } 29 | 30 | server 31 | .register( { 32 | resourcePath: "/a/" + process.argv[ 2 ], 33 | resourceTypes: [ "core.light" ], 34 | interfaces: [ "oic.if.baseline" ], 35 | secure: ( process.argv[ 4 ] === "true" ), 36 | discoverable: true 37 | } ) 38 | .then( 39 | function( resource ) { 40 | var requestCount = 0; 41 | 42 | resource.properties = { 43 | value: 42, 44 | arrayValue: [ 4, 5, 6 ] 45 | }; 46 | resource.ontranslate( transformSensorData ).onretrieve( function( request ) { 47 | if ( requestCount++ > 1 ) { 48 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 49 | false, "Server: Unexpected extra request" 50 | ] } ) ); 51 | } 52 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 53 | request.target === resource, 54 | "Server: Resource passed to retrieve request is the one that was registered" 55 | ] } ) ); 56 | request.respond() 57 | .then( 58 | function() { 59 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 60 | true, "Server: Successful response to retrieve request" 61 | ] } ) ); 62 | }, 63 | function( error ) { 64 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 65 | false, "Server: Failed to respond to retrieve request: " + 66 | ( "" + error.message ) + "\n" + 67 | JSON.stringify( error, null, 4 ) 68 | ] } ) ); 69 | } ); 70 | } ); 71 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 72 | true, "Server: Registering resource succeeded" 73 | ] } ) ); 74 | console.log( JSON.stringify( { ready: true } ) ); 75 | }, 76 | function( error ) { 77 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 78 | false, "Server: Registering resource failed unexpectedly: " + 79 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 80 | ] } ) ); 81 | } ); 82 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Structure - Client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | 17 | console.log( JSON.stringify( { assertionCount: 10 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof client.getDeviceInfo, "function", "client.getDeviceInfo is a function" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof client.getPlatformInfo, "function", "client.getPlatformInfo is a function" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | typeof client.create, "function", "client.create is a function" 29 | ] } ) ); 30 | 31 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 32 | typeof client.retrieve, "function", "client.retrieve is a function" 33 | ] } ) ); 34 | 35 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 36 | typeof client.update, "function", "client.update is a function" 37 | ] } ) ); 38 | 39 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 40 | typeof client.delete, "function", "client.delete is a function" 41 | ] } ) ); 42 | 43 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 44 | typeof client.findDevices, "function", "client.findDevices is a function" 45 | ] } ) ); 46 | 47 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 48 | typeof client.findPlatforms, "function", "client.findPlatforms is a function" 49 | ] } ) ); 50 | 51 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 52 | typeof client.findResources, "function", "client.findResources is a function" 53 | ] } ) ); 54 | 55 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 56 | typeof client.on, "function", "client.on is a function" 57 | ] } ) ); 58 | 59 | console.log( JSON.stringify( { finished: 0 } ) ); 60 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Structure - Device.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var property, updatedDevice; 16 | var ocf = require( process.argv[ 3 ] ); 17 | 18 | console.log( JSON.stringify( { assertionCount: 30 } ) ); 19 | 20 | function assertDeviceStructure( prefix ) { 21 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 22 | typeof ocf.device.name, "string", prefix + ": ocf.device.name is a string" 23 | ] } ) ); 24 | 25 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 26 | ocf.device.name, "", prefix + ": ocf.device.name is not an empty string" 27 | ] } ) ); 28 | 29 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 30 | typeof ocf.device.coreSpecVersion, "string", 31 | prefix + ": ocf.device.coreSpecVersion is a string" 32 | ] } ) ); 33 | 34 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 35 | ocf.device.coreSpecVersion, "", 36 | prefix + ": ocf.device.coreSpecVersion is not an empty string" 37 | ] } ) ); 38 | 39 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 40 | typeof ocf.device.uuid, "string", prefix + ": ocf.device.uuid is a string" 41 | ] } ) ); 42 | 43 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 44 | !!ocf.device.uuid.match( /[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}/ ), true, 45 | prefix + ": ocf.device.uuid is a UUID" 46 | ] } ) ); 47 | 48 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 49 | ocf.device.dataModels instanceof Array, true, 50 | prefix + ": ocf.device.dataModels is an array" 51 | ] } ) ); 52 | 53 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 54 | ocf.device.dataModels.length > 0, true, 55 | prefix + ": ocf.device.dataModels has at least one element" 56 | ] } ) ); 57 | 58 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 59 | typeof ocf.device.dataModels[ 0 ], "string", 60 | prefix + ": First element of ocf.device.dataModels is a string" 61 | ] } ) ); 62 | 63 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 64 | ocf.device.dataModels[ 0 ], "", 65 | prefix + ": First element of ocf.device.dataModels is not an empty string" 66 | ] } ) ); 67 | } 68 | 69 | assertDeviceStructure( "Initially" ); 70 | 71 | ocf.device.name = "some-other-name"; 72 | 73 | assertDeviceStructure( "After setting a member of ocf.device" ); 74 | 75 | // Copy the device information from ocf.device, creating a new object in the process, then 76 | // change one of the properties on the new object, and assign the whole object to ocf.device. 77 | updatedDevice = {}; 78 | for ( property in ocf.device ) { 79 | updatedDevice[ property ] = ocf.device[ property ]; 80 | } 81 | updatedDevice.name = "yet-another-name"; 82 | ocf.device = updatedDevice; 83 | 84 | assertDeviceStructure( "After setting the whole ocf.device structure" ); 85 | 86 | console.log( JSON.stringify( { finished: 0 } ) ); 87 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Structure - OCF.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var ocf = require( process.argv[ 3 ] ); 16 | 17 | console.log( JSON.stringify( { assertionCount: 4 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof ocf.device, "object", "ocf.device is an object" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof ocf.platform, "object", "ocf.platform is an object" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 28 | typeof ocf.client, "object", "ocf.client is an object" 29 | ] } ) ); 30 | 31 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 32 | typeof ocf.server, "object", "ocf.server is an object" 33 | ] } ) ); 34 | 35 | console.log( JSON.stringify( { finished: 0 } ) ); 36 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Structure - Platform.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var property, newValue; 16 | var ocf = require( process.argv[ 3 ] ); 17 | 18 | console.log( JSON.stringify( { assertionCount: 14 } ) ); 19 | 20 | function assertPlatformStructure( prefix ) { 21 | 22 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 23 | typeof ocf.platform.manufacturerName, "string", 24 | prefix + ": ocf.platform.manufacturerName is a string" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { assertion: "notStrictEqual", arguments: [ 28 | ocf.platform.manufacturerName, "", 29 | prefix + ": ocf.platform.manufacturerName is not an empty string" 30 | ] } ) ); 31 | 32 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 33 | typeof ocf.platform.id, "string", prefix + ": ocf.platform.id is a string" 34 | ] } ) ); 35 | 36 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 37 | !!ocf.platform.id.match( /[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}/ ), true, 38 | prefix + ": ocf.platform.id is a UUID" 39 | ] } ) ); 40 | 41 | } 42 | 43 | assertPlatformStructure( "Initially" ); 44 | 45 | ocf.platform.manufacturerName = "Test Name"; 46 | 47 | assertPlatformStructure( "Set individual platform info member" ); 48 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 49 | ocf.platform.manufacturerName, "Test Name", 50 | "Set individual platform info member: ocf.platform.manufacturerName has the expected value" 51 | ] } ) ); 52 | 53 | newValue = {}; 54 | for ( property in ocf.platform ) { 55 | newValue[ property ] = ocf.platform[ property ]; 56 | } 57 | newValue.manufacturerName = "Another Name"; 58 | ocf.platform = newValue; 59 | 60 | assertPlatformStructure( "Set entire platform info" ); 61 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 62 | ocf.platform.manufacturerName, "Another Name", 63 | "Set entire platform info: ocf.platform.manufacturerName has the expected value" 64 | ] } ) ); 65 | 66 | console.log( JSON.stringify( { finished: 0 } ) ); 67 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Structure - Server.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var server = require( process.argv[ 3 ] ).server; 16 | 17 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 18 | 19 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 20 | typeof server.register, "function", "server.register is a function" 21 | ] } ) ); 22 | 23 | console.log( JSON.stringify( { assertion: "strictEqual", arguments: [ 24 | typeof server.oncreate, "function", "server.oncreate is a function" 25 | ] } ) ); 26 | 27 | console.log( JSON.stringify( { finished: 0 } ) ); 28 | -------------------------------------------------------------------------------- /ocf/tests/oic1.1.0-1/Update - Resource/client.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var client = require( process.argv[ 3 ] ).client; 16 | var desiredValue = { 17 | value: 42, 18 | anotherValue: "something", 19 | childValues: { 20 | nullValue: null, 21 | booleanValue: true 22 | } 23 | }; 24 | 25 | function pickEndpoint( endpoints ) { 26 | var index, isSecureEndpoint; 27 | 28 | for ( index in endpoints ) { 29 | isSecureEndpoint = endpoints[ index ].origin.substr( 0, 5 ) === "coaps"; 30 | if ( isSecureEndpoint && process.argv[ 4 ] === "true" ) { 31 | return endpoints[ index ]; 32 | } else if ( !isSecureEndpoint && process.argv[ 4 ] === "false" ) { 33 | return endpoints[ index ]; 34 | } 35 | } 36 | } 37 | 38 | console.log( JSON.stringify( { assertionCount: 2 } ) ); 39 | 40 | function resourcefound( resource ) { 41 | client.removeListener( "resourcefound", resourcefound ); 42 | resource.properties = desiredValue; 43 | resource.endpoint = pickEndpoint( resource.endpoints ); 44 | client.update( resource ) 45 | .then( 46 | function( updatedResource ) { 47 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 48 | updatedResource === resource, 49 | "Client: Updated resource is the discovered resource" 50 | ] } ) ); 51 | }, 52 | function( error ) { 53 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 54 | false, "Client: update() failed unexpectedly: " + 55 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 56 | ] } ) ); 57 | } ) 58 | .then( function() { 59 | 60 | // Retrieve the resource to see if the properties were applied 61 | return client.retrieve( resource ); 62 | } ) 63 | .then( 64 | function( retrievedResource ) { 65 | console.log( JSON.stringify( { assertion: "deepEqual", arguments: [ 66 | retrievedResource.properties, desiredValue, 67 | "Client: Retrieved resouce properties are as expected" 68 | ] } ) ); 69 | }, 70 | function( error ) { 71 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 72 | false, "Client: retrieve() failed unexpectedly: " + 73 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 74 | ] } ) ); 75 | } ) 76 | .then( function() { 77 | console.log( JSON.stringify( { finished: 0 } ) ); 78 | } ); 79 | } 80 | 81 | client 82 | .on( "resourcefound", resourcefound ) 83 | .findResources( { resourcePath: "/a/" + process.argv[ 2 ] } ) 84 | .catch( function( error ) { 85 | console.log( JSON.stringify( { assertion: "ok", arguments: [ 86 | false, "Client: Starting device discovery failed: " + 87 | ( "" + error ) + "\n" + JSON.stringify( error, null, 4 ) 88 | ] } ) ); 89 | } ); 90 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iot-js-api", 3 | "description": "OCF JS API specifications and test suites", 4 | "main": "scripts/index.js", 5 | "version": "1.0.0", 6 | "versions": { 7 | "ocf": "oic1.1.0-1", 8 | "ble": "1.0", 9 | "board": "1.0", 10 | "sensor": "1.0" 11 | }, 12 | "license": "Apache-2.0", 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/01org/iot-js-api.git" 16 | }, 17 | "bugs": { 18 | "url": "https://github.com/01org/iot-js-api/issues" 19 | }, 20 | "devDependencies": { 21 | "eslint-config-jquery": "0.1.2", 22 | "grunt": "^0.4.5", 23 | "grunt-eslint": "18.1.0", 24 | "load-grunt-config": "^0.17.2", 25 | "load-grunt-tasks": "^3.2.0" 26 | }, 27 | "dependencies": { 28 | "async": "^2.0.0-rc.4", 29 | "glob": "^7.0.3", 30 | "lodash": "^4.12.0", 31 | "qunitjs": "^2.0.0-rc1", 32 | "tmp": "0.0.28", 33 | "uuid": "^2.0.2" 34 | }, 35 | "homepage": "https://github.com/01org/iot-js-api#readme" 36 | } 37 | -------------------------------------------------------------------------------- /scripts/build/tasks/alias.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | module.exports = function( grunt ) { 16 | 17 | grunt.registerTask( "default", [ "eslint" ] ); 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /scripts/build/tasks/options/eslint.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | module.exports = { 16 | build: { 17 | options: { 18 | rules: { 19 | "no-restricted-globals": [ 2, "console" ] 20 | } 21 | }, 22 | src: [ "Gruntfile.js", "build/**/*.js" ] 23 | }, 24 | lib: { 25 | src: [ "scripts/**/*.js" ] 26 | }, 27 | tests: { 28 | src: Object.keys( require( "../../../../package.json" ).versions ) 29 | .map( function( item ) { 30 | return require( "path" ).join( item, "tests", "**", "*" ); 31 | } ) 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /scripts/lib/callbacks.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var success = "\x1b[42;30m✓\x1b[0m", 16 | failure = "\x1b[41;30m✗\x1b[0m"; 17 | 18 | // Right-align runtime in a field that's 10 columns wide 19 | function formatRuntime( runtime ) { 20 | var index, 21 | str = "" + runtime, 22 | indent = ""; 23 | 24 | for ( index = 0; index < Math.max( 0, 10 - str.length ); index++ ) { 25 | indent += " "; 26 | } 27 | 28 | return indent + str; 29 | } 30 | 31 | module.exports = { 32 | moduleStart: function( status ) { 33 | 34 | // Parameters: status: { name, tests } 35 | 36 | if ( status.name ) { 37 | console.log( "\n### " + status.name ); 38 | } 39 | }, 40 | testStart: function( status ) { 41 | 42 | // Parameters: status: { name, module, testId } 43 | 44 | if ( status.name ) { 45 | console.log( "\n" + status.name ); 46 | } 47 | }, 48 | log: function( status ) { 49 | 50 | // Parameters: status: { module, result(t/f), message, actual, expected, testId, runtime } 51 | 52 | console.log( 53 | ( status.result ? success : failure ) + 54 | " @" + formatRuntime( status.runtime ) + ": " + 55 | status.message ); 56 | if ( !status.result ) { 57 | console.log( "Actual: " ); 58 | console.log( this.dump.parse( status.actual ) ); 59 | console.log( "Expected: " ); 60 | console.log( this.dump.parse( status.expected ) ); 61 | } 62 | }, 63 | 64 | done: function( status ) { 65 | var passed = "\x1b[42;30m " + status.passed + " \x1b[0m", 66 | failed = "\x1b[41;30m " + status.failed + " \x1b[0m"; 67 | 68 | console.log( "Total assertions: " + 69 | "(" + passed + ( status.failed > 0 ? "+" + failed : "" ) + ") / " + status.total ); 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /scripts/lib/setup.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var QUnit = require( "qunitjs" ), 16 | _ = require( "lodash" ), 17 | callbacks = require( "./callbacks" ); 18 | 19 | QUnit.load(); 20 | QUnit.config.requireExpects = true; 21 | QUnit.config.testTimeout = 30000; 22 | 23 | _.forEach( callbacks, function( value, key ) { 24 | if ( QUnit.config.callbacks[ key ] ) { 25 | QUnit.config.callbacks[ key ].push( _.bind( value, QUnit ) ); 26 | } 27 | } ); 28 | 29 | module.exports = QUnit; 30 | -------------------------------------------------------------------------------- /tasks/iot-js-api.js: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | module.exports = function( grunt ) { 16 | 17 | var _ = require( "lodash" ); 18 | var path = require( "path" ); 19 | var testSuite = require( "../scripts/index" ); 20 | 21 | grunt.task.registerMultiTask( "iot-js-api", "Run a test suite", function() { 22 | var done = this.async(); 23 | 24 | testSuite.defaultCallbacks.done = ( function( originalDone ) { 25 | return function( status ) { 26 | if ( originalDone ) { 27 | originalDone.apply( this, arguments ); 28 | } 29 | done( status.failed === 0 ); 30 | testSuite.defaultCallbacks.done = originalDone; 31 | }; 32 | } )( testSuite.defaultCallbacks.done ); 33 | 34 | testSuite( this.data ); 35 | } ); 36 | 37 | }; 38 | --------------------------------------------------------------------------------