diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test index 12646463e7..10ba03a673 100644 --- a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_full.test @@ -81,7 +81,10 @@ payload='{ "AA", "AB", "AC", - "AD" + "AD", + "AE", + "AF", + "AG" ], "httpCustom": { "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", @@ -205,6 +208,18 @@ payload='{ "AD": { "type": "Number", "value": "${AD|len}" + }, + "AE": { + "type": "Number", + "value": "${AE|now}" + }, + "AF": { + "type": "Text", + "value": "${AF|toIsoString}" + }, + "AG": { + "type": "Number", + "value": "${AG|getTime}" } } } @@ -344,6 +359,18 @@ payload='{ "AD": { "type": "StructuredValue", "value": [1, 2, 3] + }, + "AE": { + "type": "Number", + "value": 0 + }, + "AF": { + "type": "Number", + "value": 1722500129 + }, + "AG": { + "type": "Number", + "value": "1979-11-13T18:01:14+00:00" } }' orionCurl --url /v2/entities --payload "$payload" @@ -383,7 +410,7 @@ Content-Length: 0 ================================================== POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: 1627 +Content-Length: 1809 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) @@ -422,6 +449,21 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 "type": "Number", "value": 3 }, + "AE": { + "metadata": {}, + "type": "Number", + "value": REGEX(\d+) + }, + "AF": { + "metadata": {}, + "type": "Text", + "value": "2024-08-01T08:15:29+00:00" + }, + "AG": { + "metadata": {}, + "type": "Number", + "value": 311364074 + }, "B": { "metadata": {}, "type": "Text", diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test index bd9f96db3e..d2e40950f3 100644 --- a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_substring.test @@ -148,7 +148,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) ================================================================= POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: x +Content-Length: 288 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) @@ -188,7 +188,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 ======================================= POST http://127.0.0.1:REGEX(\d+)/notify Fiware-Servicepath: / -Content-Length: x +Content-Length: 288 User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) Ngsiv2-Attrsformat: normalized Host: 127.0.0.1:REGEX(\d+) diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test new file mode 100644 index 0000000000..e5aedcdf6f --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations.test @@ -0,0 +1,214 @@ +# 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 expression time transformation specific cases + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +# 02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +# 03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +# 04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +# + + +echo "01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime" +echo "=============================================================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "S": { + "value": "${A|getTime|toIsoString}", + "type": "Calculated" + }, + "T": { + "value": "${B|toIsoString|getTime}", + "type": "Calculated" + } + } + }, + "attrs": [ "S", "T" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038" +echo "==================================================================" +payload='{ + "id": "E", + "type": "T", + "A": { + "value": "2060-02-04T23:28:10+00:00", + "type": "Text" + }, + "B": { + "value": 1722501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038" +echo "=================================================================" +payload='{ + "A": { + "value": "2040-03-12T21:04:13+00:00", + "type": "Text" + }, + "B": { + "value": 122501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities/E/attrs --payload "$payload" +echo +echo + + +echo "04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038)" +echo "=================================================================================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +============================================================================================= +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 E with A=2060-02-04T23:28:10+00:00, B=1722501038 +================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +================================================================= +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +================================================================================================================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 211 +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": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2060-02-04T23:28:10+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 1722501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 210 +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": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2040-03-12T21:04:13+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 122501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop diff --git a/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test new file mode 100644 index 0000000000..4166851546 --- /dev/null +++ b/test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_transformation_time_transformations_datetimes.test @@ -0,0 +1,215 @@ +# 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 expression time transformation specific cases + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# Same test as jexl_transformation_time_transformations but using "DateTime" instead of "Text" for A attribute +# +# 01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +# 02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038 +# 03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +# 04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +# + + +echo "01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime" +echo "=============================================================================================" +payload='{ + "subject": { + "entities": [ + { + "id" : "E", + "type": "T" + } + ] + }, + "notification": { + "httpCustom": { + "url": "http://127.0.0.1:'${LISTENER_PORT}'/notify", + "ngsi": { + "S": { + "value": "${A|getTime|toIsoString}", + "type": "Calculated" + }, + "T": { + "value": "${B|toIsoString|getTime}", + "type": "Calculated" + } + } + }, + "attrs": [ "S", "T" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "02. Create entity E with A=2060-02-04T23:28:10+00:00, B=1722501038" +echo "==================================================================" +payload='{ + "id": "E", + "type": "T", + "A": { + "value": "2060-02-04T23:28:10+00:00", + "type": "DateTime" + }, + "B": { + "value": 1722501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038" +echo "=================================================================" +payload='{ + "A": { + "value": "2040-03-12T21:04:13+00:00", + "type": "DateTime" + }, + "B": { + "value": 122501038, + "type": "Number" + } +}' +orionCurl --url /v2/entities/E/attrs --payload "$payload" +echo +echo + + +echo "04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038)" +echo "=================================================================================================================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create custom sub with custom expression S=A|getTime|toIsoString, T=B|toIsoString|getTime +============================================================================================= +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 E with A=2060-02-04T23:28:10+00:00, B=1722501038 +================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +03. Update entity E with A=2040-03-12T21:04:13+00:00, B=122501038 +================================================================= +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see notifications (S=2060-02-04T23:28:10+00:00, T=1722501038) (S=2040-03-12T21:04:13+00:00, T=122501038) +================================================================================================================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 211 +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": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2060-02-04T23:28:10+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 1722501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= +POST http://127.0.0.1:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 210 +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": [ + { + "S": { + "metadata": {}, + "type": "Calculated", + "value": "2040-03-12T21:04:13+00:00" + }, + "T": { + "metadata": {}, + "type": "Calculated", + "value": 122501038 + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop