Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit f08dc76

Browse files
author
Gabriel Schulhof
committed
OCF: Use endpoints in more tests
1 parent 397b697 commit f08dc76

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

Diff for: ocf/tests/oic1.1.0-1/Observe - Resource (Failure)/client.js

+14
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ var client = require( process.argv[ 3 ] ).client;
1616

1717
console.log( JSON.stringify( { assertionCount: 1 } ) );
1818

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+
1932
function dummyListener() {}
2033

2134
function performObservation( resource ) {
35+
resource.endpoint = pickEndpoint( resource.endpoints );
2236
resource
2337
.on( "error", function( error ) {
2438
console.log( JSON.stringify( { assertion: "strictEqual", arguments: [

Diff for: ocf/tests/oic1.1.0-1/Observe - Resource (Repeated)/client.js

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ var client = require( process.argv[ 3 ] ).client;
1616

1717
console.log( JSON.stringify( { assertionCount: 2 } ) );
1818

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+
1932
function observeResource( resource ) {
2033
return new Promise( function( fulfill ) {
2134
var updateCount = 0;
@@ -28,6 +41,7 @@ function observeResource( resource ) {
2841
fulfill();
2942
}
3043
}
44+
resource.endpoint = pickEndpoint( resource.endpoints );
3145
resource.on( "update", update );
3246
} );
3347
}

Diff for: ocf/tests/oic1.1.0-1/Observe - Resource/client.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ function pickEndpoint( endpoints ) {
4545
function secondPositiveListener( resource ) {
4646
secondPositiveCount++;
4747
console.log( JSON.stringify( { assertion: "ok", arguments: [
48-
resource.properties.value > 0, "Client: Second listener: sensor value is positive"
48+
resource.properties.value > 0,
49+
"Client: Second listener: sensor value is positive at observation " + secondPositiveCount
4950
] } ) );
50-
if ( secondNegativeCount >= 4 ) {
51+
if ( secondPositiveCount >= 4 ) {
5152
resource.removeListener( "update", secondPositiveListener );
5253
}
5354
}
5455

5556
function positiveListener( resource ) {
5657
positiveCount++;
5758
console.log( JSON.stringify( { assertion: "ok", arguments: [
58-
resource.properties.value > 0, "Client: sensor value is positive"
59+
resource.properties.value > 0,
60+
"Client: sensor value is positive at observation " + positiveCount
5961
] } ) );
6062

6163
// After three notifications, hand over to the second listener, with two notifications where
@@ -86,7 +88,8 @@ function positiveListener( resource ) {
8688
function secondNegativeListener( resource ) {
8789
secondNegativeCount++;
8890
console.log( JSON.stringify( { assertion: "ok", arguments: [
89-
resource.properties.value < 0, "Client: Second listener: sensor value is negative"
91+
resource.properties.value < 0,
92+
"Client: Second listener: sensor value is negative at observation " + secondNegativeCount
9093
] } ) );
9194
if ( secondNegativeCount >= 5 ) {
9295
resource.removeListener( "update", secondNegativeListener );
@@ -96,13 +99,15 @@ function secondNegativeListener( resource ) {
9699
function negativeListener( resource ) {
97100
negativeCount++;
98101
console.log( JSON.stringify( { assertion: "ok", arguments: [
99-
resource.properties.value < 0, "Client: sensor value is negative"
102+
resource.properties.value < 0,
103+
"Client: sensor value is negative at observation " + negativeCount
100104
] } ) );
101105

102106
// After two notifications, hand over to the second listener, with three notifications where
103107
// both listeners are attached
104108
if ( negativeCount > 1 && addSecondNegativeListener ) {
105109
addSecondNegativeListener = false;
110+
resource.endpoint = pickEndpoint( resource.endpoints );
106111
client.retrieve( resource, { scale: -1 }, secondNegativeListener )
107112
.then(
108113
function( secondResource ) {
@@ -123,6 +128,7 @@ function negativeListener( resource ) {
123128
}
124129

125130
function performObservation( resource ) {
131+
resource.endpoint = pickEndpoint( resource.endpoints );
126132
resource.on( "update", positiveListener );
127133

128134
client

Diff for: ocf/tests/oic1.1.0-1/Observe - Resource/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function fakeSensorLoop( resource ) {
4545
.then(
4646
function() {
4747
console.log( JSON.stringify( { assertion: "ok", arguments: [
48-
true, "Server: Notification successful"
48+
true, "Server: Notification " + notificationCount + " successful"
4949
] } ) );
5050
},
5151
function( error ) {

0 commit comments

Comments
 (0)