From e6f0e6bdcf328fd623d0feed38bd78d71728af77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Thu, 7 Mar 2024 12:46:27 +0100 Subject: [PATCH] ADD ftest for array filtering --- .../jexl_array_filtering.test | 297 ++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_array_filtering.test diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_array_filtering.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_array_filtering.test new file mode 100644 index 0000000000..c20beb102f --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_array_filtering.test @@ -0,0 +1,297 @@ +# 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 + +--NAME-- +JEXL expression in custom notification (array filtering) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create custom sub with custom expression sum: a[.b<5] +# 02. Create entity E1 with a=[{b:1},{b:34},{b:4}] +# 03. Update entity E1 with a=[{c:1},{b:-1},{b:2}] +# 04. Update entity E1 with a=[{b:-1},{b:foo}] +# 05. Update entity E1 with a=[{b:-1, c:1},{b:20, d:3}] +# 06. Dump accumulator and see notifications (cal=[{b:1},{b:4}], cal=null, cal=null, cal=[{b:-1, c:1}]) +# + + +echo "01. Create custom sub with custom expression sum: a[.b<5]" +echo "=========================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E1", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "cal": { + "value": "${a[.b<5]}", + "type": "TextUnrestricted" + } + } + }, + "attrs": [ "cal" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E1 with a=[{b:1},{b:34},{b:4}]" +echo "================================================" +payload='{ + "id": "E1", + "type": "T", + "a": { + "value": [{"b": 1}, {"b": 34}, {"b": 4}], + "type": "Array" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E1 with a=[{c:1},{b:-1},{b:2}]" +echo "================================================" +payload='{ + "a": { + "value": [{"c": 1}, {"b": -1}, {"b": 2}], + "type": "Text" + } +}' +orionCurl --url /v2/entities/E1/attrs -X POST --payload "$payload" +echo +echo + + +echo "04. Update entity E1 with a=[{b:-1},{b:foo}]" +echo "============================================" +payload='{ + "a": { + "value": [{"b": -1}, {"b": "foo"}], + "type": "Text" + } +}' +orionCurl --url /v2/entities/E1/attrs -X POST --payload "$payload" +echo +echo + + +echo "05. Update entity E1 with a=[{b:-1, c:1},{b:20, d:3}]" +echo "=====================================================" +payload='{ + "a": { + "value": [{"b": -1, "c": 1}, {"b": 20, "d": 3}], + "type": "Text" + } +}' +orionCurl --url /v2/entities/E1/attrs -X POST --payload "$payload" +echo +echo + + +echo "06. Dump accumulator and see notifications (cal=[{b:1},{b:4}], cal=null, cal=null, cal=[{b:-1, c:1}])" +echo "=====================================================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression sum: a[.b<5] +========================================================= +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 with a=[{b:1},{b:34},{b:4}] +================================================ +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 with a=[{c:1},{b:-1},{b:2}] +================================================ +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Update entity E1 with a=[{b:-1},{b:foo}] +============================================ +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +05. Update entity E1 with a=[{b:-1, c:1},{b:20, d:3}] +===================================================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +06. Dump accumulator and see notifications (cal=[{b:1},{b:4}], cal=null, cal=null, cal=[{b:-1, c:1}]) +===================================================================================================== +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 151 +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": [ + { + "cal": { + "metadata": {}, + "type": "TextUnrestricted", + "value": [ + { + "b": 1 + }, + { + "b": 4 + } + ] + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 138 +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": [ + { + "cal": { + "metadata": {}, + "type": "TextUnrestricted", + "value": null + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 138 +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": [ + { + "cal": { + "metadata": {}, + "type": "TextUnrestricted", + "value": null + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 150 +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": [ + { + "cal": { + "metadata": {}, + "type": "TextUnrestricted", + "value": [ + { + "b": -1, + "c": 1 + } + ] + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop