-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
310 additions
and
0 deletions.
There are no files selected for viewing
310 changes: 310 additions & 0 deletions
310
test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_extra_case.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U | ||
# | ||
# This file is part of Orion Context Broker. | ||
# | ||
# Orion Context Broker is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Orion Context Broker is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. | ||
# | ||
# For those usages not covered by this license please contact with | ||
# iot_support at tid dot es | ||
|
||
# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh | ||
# JEXL_EXPR_FLAVOUR - to mark the test has to execute only when contextBroker includes jexl-expr flavour | ||
|
||
--NAME-- | ||
JEXL basic expression in custom notification (extra case) | ||
|
||
--SHELL-INIT-- | ||
dbInit CB | ||
brokerStart CB | ||
accumulatorStart --pretty-print | ||
|
||
--SHELL-- | ||
|
||
# | ||
# 01. Create custom sub with jexl expression | ||
# 02. Create entity E1 (inactive true, status noData, spots 2344) | ||
# 03. Update entity E1 (inactive false, status noData, spots 2344) | ||
# 04. Update entity E1 (inactive false, status ok, spots 2344) | ||
# 05. Dump accumulator and see three expected notifications (-1, -2 and 2344) | ||
# | ||
|
||
|
||
echo "01. Create custom sub with several attributes with transformations" | ||
echo "==================================================================" | ||
# NOTE: '\'' is the way of scaping a ' in the payload variable below (see https://stackoverflow.com/a/1250279/1485926) | ||
payload='{ | ||
"subject": { | ||
"entities": [ | ||
{ | ||
"id" : "E1", | ||
"type": "T" | ||
} | ||
] | ||
}, | ||
"notification": { | ||
"httpCustom": { | ||
"url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", | ||
"ngsi": { | ||
"address": { | ||
"type": "Text", | ||
"value": "${address||'\'''\''}" | ||
}, | ||
"humidity": { | ||
"type": "Float", | ||
"value": "${humidity||0-1}" | ||
}, | ||
"free": { | ||
"type": "Number", | ||
"value": "${(inactive==true)?(0-1) : ((status == '\''noData'\'')?(0-2) : spots)}" | ||
} | ||
} | ||
}, | ||
"attrs": [ "address", "humidity", "free" ] | ||
} | ||
}' | ||
orionCurl --url /v2/subscriptions --payload "$payload" | ||
echo | ||
echo | ||
|
||
|
||
echo "02. Create entity E1 (inactive true, status noData, spots 2344)" | ||
echo "===============================================================" | ||
payload='{ | ||
"id": "E1", | ||
"type": "T", | ||
"spots": { | ||
"type": "Number", | ||
"value": 2344 | ||
}, | ||
"inactive": { | ||
"type": "Boolean", | ||
"value": true | ||
}, | ||
"status": { | ||
"type": "Text", | ||
"value": "noData" | ||
} | ||
}' | ||
orionCurl --url /v2/entities --payload "$payload" | ||
echo | ||
echo | ||
|
||
|
||
echo "03. Update entity E1 (inactive false, status noData, spots 2344)" | ||
echo "================================================================" | ||
payload='{ | ||
"address": { | ||
"type": "Text", | ||
"value": "test5" | ||
}, | ||
"spots": { | ||
"type": "Number", | ||
"value": 2344 | ||
}, | ||
"inactive": { | ||
"type": "Boolean", | ||
"value": false | ||
}, | ||
"status": { | ||
"type": "Text", | ||
"value": "noData" | ||
} | ||
}' | ||
orionCurl --url /v2/entities/E1/attrs -X POST --payload "$payload" | ||
echo | ||
echo | ||
|
||
|
||
echo "04. Update entity E1 (inactive true, status ok, spots 2344)" | ||
echo "===========================================================" | ||
payload='{ | ||
"humidity": { | ||
"type": "Number", | ||
"value": 3 | ||
}, | ||
"spots": { | ||
"type": "Number", | ||
"value": 2344 | ||
}, | ||
"inactive": { | ||
"type": "Boolean", | ||
"value": false | ||
}, | ||
"status": { | ||
"type": "Text", | ||
"value": "ok" | ||
} | ||
}' | ||
orionCurl --url /v2/entities/E1/attrs -X POST --payload "$payload" | ||
echo | ||
echo | ||
|
||
|
||
echo "05. Dump accumulator and see three expected notifications (-1, -2 and 2344)" | ||
echo "===========================================================================" | ||
accumulatorDump | ||
echo | ||
echo | ||
|
||
|
||
--REGEXPECT-- | ||
01. Create custom sub with several attributes with transformations | ||
================================================================== | ||
HTTP/1.1 201 Created | ||
Date: REGEX(.*) | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}) | ||
Location: /v2/subscriptions/REGEX([0-9a-f]{24}) | ||
Content-Length: 0 | ||
|
||
|
||
|
||
02. Create entity E1 (inactive true, status noData, spots 2344) | ||
=============================================================== | ||
HTTP/1.1 201 Created | ||
Date: REGEX(.*) | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}) | ||
Location: /v2/entities/E1?type=T | ||
Content-Length: 0 | ||
|
||
|
||
|
||
03. Update entity E1 (inactive false, status noData, spots 2344) | ||
================================================================ | ||
HTTP/1.1 204 No Content | ||
Date: REGEX(.*) | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}) | ||
|
||
|
||
|
||
04. Update entity E1 (inactive true, status ok, spots 2344) | ||
=========================================================== | ||
HTTP/1.1 204 No Content | ||
Date: REGEX(.*) | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}) | ||
|
||
|
||
|
||
05. Dump accumulator and see three expected notifications (-1, -2 and 2344) | ||
=========================================================================== | ||
POST http://127.0.0.1:REGEX(\d+)/notify | ||
Fiware-Servicepath: / | ||
Content-Length: 231 | ||
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) | ||
Ngsiv2-Attrsformat: normalized | ||
Host: 127.0.0.1:REGEX(\d+) | ||
Accept: application/json | ||
Content-Type: application/json; charset=utf-8 | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 | ||
|
||
{ | ||
"data": [ | ||
{ | ||
"address": { | ||
"metadata": {}, | ||
"type": "Text", | ||
"value": "" | ||
}, | ||
"free": { | ||
"metadata": {}, | ||
"type": "Number", | ||
"value": -1 | ||
}, | ||
"humidity": { | ||
"metadata": {}, | ||
"type": "Float", | ||
"value": -1 | ||
}, | ||
"id": "E1", | ||
"type": "T" | ||
} | ||
], | ||
"subscriptionId": "REGEX([0-9a-f]{24})" | ||
} | ||
======================================= | ||
POST http://127.0.0.1:REGEX(\d+)/notify | ||
Fiware-Servicepath: / | ||
Content-Length: 236 | ||
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) | ||
Ngsiv2-Attrsformat: normalized | ||
Host: 127.0.0.1:REGEX(\d+) | ||
Accept: application/json | ||
Content-Type: application/json; charset=utf-8 | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 | ||
|
||
{ | ||
"data": [ | ||
{ | ||
"address": { | ||
"metadata": {}, | ||
"type": "Text", | ||
"value": "test5" | ||
}, | ||
"free": { | ||
"metadata": {}, | ||
"type": "Number", | ||
"value": -2 | ||
}, | ||
"humidity": { | ||
"metadata": {}, | ||
"type": "Float", | ||
"value": -1 | ||
}, | ||
"id": "E1", | ||
"type": "T" | ||
} | ||
], | ||
"subscriptionId": "REGEX([0-9a-f]{24})" | ||
} | ||
======================================= | ||
POST http://127.0.0.1:REGEX(\d+)/notify | ||
Fiware-Servicepath: / | ||
Content-Length: 237 | ||
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) | ||
Ngsiv2-Attrsformat: normalized | ||
Host: 127.0.0.1:REGEX(\d+) | ||
Accept: application/json | ||
Content-Type: application/json; charset=utf-8 | ||
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 | ||
|
||
{ | ||
"data": [ | ||
{ | ||
"address": { | ||
"metadata": {}, | ||
"type": "Text", | ||
"value": "test5" | ||
}, | ||
"free": { | ||
"metadata": {}, | ||
"type": "Number", | ||
"value": 2344 | ||
}, | ||
"humidity": { | ||
"metadata": {}, | ||
"type": "Float", | ||
"value": 3 | ||
}, | ||
"id": "E1", | ||
"type": "T" | ||
} | ||
], | ||
"subscriptionId": "REGEX([0-9a-f]{24})" | ||
} | ||
======================================= | ||
|
||
|
||
--TEARDOWN-- | ||
brokerStop CB | ||
dbDrop CB | ||
accumulatorStop |