diff --git a/doc/manuals/orion-api.md b/doc/manuals/orion-api.md index af4aaa8fb6..ce6f4929b4 100644 --- a/doc/manuals/orion-api.md +++ b/doc/manuals/orion-api.md @@ -1932,13 +1932,13 @@ Based on the [`condition` subscription field](#subscriptionsubjectcondition), up entity update, the notification triggering rules are as follow: * If `attrs` and `expression` are used, a notification is sent whenever one of the attributes in - the `attrs` list changes and at the same time `expression` matches. + the `attrs` list changes (or is deleted) and at the same time `expression` matches. * If `attrs` is used and `expression` is not used, a notification is sent whenever any of the - attributes in the `attrs` list changes. + attributes in the `attrs` list changes (or is deleted). * If `attrs` is not used and `expression` is used, a notification is sent whenever any of the - attributes of the entity changes and at the same time `expression` matches. + attributes of the entity changes (or is deleted) and at the same time `expression` matches. * If neither `attrs` nor `expression` are used, a notification is sent whenever any of the - attributes of the entity changes. + attributes of the entity changes (or is deleted). Note that changing the metadata of a given attribute is considered a change even though the attribute value itself hasn't changed. diff --git a/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_condition.test b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_condition.test new file mode 100644 index 0000000000..691e26bd32 --- /dev/null +++ b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_condition.test @@ -0,0 +1,226 @@ +# Copyright 2022 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-- +Delete attribute (when attribute is in subject.condition) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create entity E1 with attributes A:1, B:2, C:3 +# 02. Subscribe to E.* for A, B and C; triggered by B, C +# 03. Delete attribute B +# 04. Dump accumulator: see notification with A and C (B has been deleted) +# 05. Get subscription and check timesSent is 1 +# + + +echo "01. Create entity E1 with attributes A:1, B:2, C:3" +echo "==================================================" +payload='{ + "type": "T", + "id": "E1", + "A": { + "type": "Number", + "value": 1 + }, + "B": { + "type": "Number", + "value": 2 + }, + "C": { + "type": "Number", + "value": 3 + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "02. Subscribe to E.* for A, B and C; triggered by B, C" +echo "======================================================" +payload='{ + "subject": { + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ], + "condition": { + "attrs": [ "B", "C" ] + } + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ "A", "B", "C" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "03. Delete attribute B" +echo "======================" +orionCurl --url /v2/entities/E1/attrs/B -X DELETE +echo +echo + + + +echo "04. Dump accumulator: see notification with A and C (B has been deleted)" +echo "========================================================================" +accumulatorDump +echo +echo + + +echo "05. Get subscription and check timesSent is 1" +echo "=============================================" +orionCurl --url /v2/subscriptions +echo +echo + + +--REGEXPECT-- +01. Create entity E1 with attributes A:1, B:2, C:3 +================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E1?type=T +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +02. Subscribe to E.* for A, B and C; triggered by B, C +====================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +03. Delete attribute B +====================== +HTTP/1.1 204 No Content +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +04. Dump accumulator: see notification with A and C (B has been deleted) +======================================================================== +POST http://localhost:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 169 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: localhost:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "A": { + "metadata": {}, + "type": "Number", + "value": 1 + }, + "C": { + "metadata": {}, + "type": "Number", + "value": 3 + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +05. Get subscription and check timesSent is 1 +============================================= +HTTP/1.1 200 OK +Content-Length: 417 +Content-Type: application/json +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + +[ + { + "id": "REGEX([0-9a-f]{24})", + "notification": { + "attrs": [ + "A", + "B", + "C" + ], + "attrsFormat": "normalized", + "covered": false, + "http": { + "url": "http://localhost:REGEX(\d+)/notify" + }, + "lastNotification": "REGEX(.*)", + "lastSuccess": "REGEX(.*)", + "lastSuccessCode": 200, + "onlyChangedAttrs": false, + "timesSent": 1 + }, + "status": "active", + "subject": { + "condition": { + "attrs": [ + "B", + "C" + ] + }, + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ] + } + } +] + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB diff --git a/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_empty_condition.test b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_empty_condition.test new file mode 100644 index 0000000000..ed1be9215e --- /dev/null +++ b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_in_empty_condition.test @@ -0,0 +1,220 @@ +# Copyright 2022 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-- +Delete attribute (when subject.condition.attrs is empty) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create entity E1 with attributes A:1, B:2, C:3 +# 02. Subscribe to E.* for A, B and C; triggered by any attribute +# 03. Delete attribute B +# 04. Dump accumulator: see notification with A and C (B has been deleted) +# 05. Get subscription and check timesSent is 1 +# + + +echo "01. Create entity E1 with attributes A:1, B:2, C:3" +echo "==================================================" +payload='{ + "type": "T", + "id": "E1", + "A": { + "type": "Number", + "value": 1 + }, + "B": { + "type": "Number", + "value": 2 + }, + "C": { + "type": "Number", + "value": 3 + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "02. Subscribe to E.* for A, B and C; triggered by any attribute" +echo "===============================================================" +payload='{ + "subject": { + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ] + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ "A", "B", "C" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "03. Delete attribute B" +echo "======================" +orionCurl --url /v2/entities/E1/attrs/B -X DELETE +echo +echo + + + +echo "04. Dump accumulator: see notification with A and C (B has been deleted)" +echo "========================================================================" +accumulatorDump +echo +echo + + +echo "05. Get subscription and check timesSent is 1" +echo "=============================================" +orionCurl --url /v2/subscriptions +echo +echo + + +--REGEXPECT-- +01. Create entity E1 with attributes A:1, B:2, C:3 +================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E1?type=T +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +02. Subscribe to E.* for A, B and C; triggered by any attribute +=============================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +03. Delete attribute B +====================== +HTTP/1.1 204 No Content +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +04. Dump accumulator: see notification with A and C (B has been deleted) +======================================================================== +POST http://localhost:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 169 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: localhost:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "A": { + "metadata": {}, + "type": "Number", + "value": 1 + }, + "C": { + "metadata": {}, + "type": "Number", + "value": 3 + }, + "id": "E1", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +05. Get subscription and check timesSent is 1 +============================================= +HTTP/1.1 200 OK +Content-Length: 410 +Content-Type: application/json +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + +[ + { + "id": "REGEX([0-9a-f]{24})", + "notification": { + "attrs": [ + "A", + "B", + "C" + ], + "attrsFormat": "normalized", + "covered": false, + "http": { + "url": "http://localhost:REGEX(\d+)/notify" + }, + "lastNotification": "REGEX(.*)", + "lastSuccess": "REGEX(.*)", + "lastSuccessCode": 200, + "onlyChangedAttrs": false, + "timesSent": 1 + }, + "status": "active", + "subject": { + "condition": { + "attrs": [] + }, + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ] + } + } +] + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB diff --git a/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_not_in_condition.test b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_not_in_condition.test new file mode 100644 index 0000000000..79c63fd17f --- /dev/null +++ b/test/functionalTest/cases/0000_subs_attrs_deletion/delete_attribute_not_in_condition.test @@ -0,0 +1,193 @@ +# Copyright 2022 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-- +Delete attribute (when attribute is *not* in subject.condition) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. Create entity E1 with attributes A:1, B:2, C:3 +# 02. Subscribe to E.* for A, B and C; triggered by B, C +# 03. Delete attribute A +# 04. Dump accumulator: no notification +# 05. Get subscription and check timesSent is 0 +# + + +echo "01. Create entity E1 with attributes A:1, B:2, C:3" +echo "==================================================" +payload='{ + "type": "T", + "id": "E1", + "A": { + "type": "Number", + "value": 1 + }, + "B": { + "type": "Number", + "value": 2 + }, + "C": { + "type": "Number", + "value": 3 + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + + +echo "02. Subscribe to E.* for A, B and C; triggered by B, C" +echo "======================================================" +payload='{ + "subject": { + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ], + "condition": { + "attrs": [ "B", "C" ] + } + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ "A", "B", "C" ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo "03. Delete attribute A" +echo "======================" +orionCurl --url /v2/entities/E1/attrs/A -X DELETE +echo +echo + + + +echo "04. Dump accumulator: no notification" +echo "=====================================" +accumulatorDump +echo +echo + + +echo "05. Get subscription and check timesSent is 0" +echo "=============================================" +orionCurl --url /v2/subscriptions +echo +echo + + +--REGEXPECT-- +01. Create entity E1 with attributes A:1, B:2, C:3 +================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E1?type=T +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +02. Subscribe to E.* for A, B and C; triggered by B, C +====================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +03. Delete attribute A +====================== +HTTP/1.1 204 No Content +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +04. Dump accumulator: no notification +===================================== + + +05. Get subscription and check timesSent is 0 +============================================= +HTTP/1.1 200 OK +Content-Length: 294 +Content-Type: application/json +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + +[ + { + "id": "REGEX([0-9a-f]{24})", + "notification": { + "attrs": [ + "A", + "B", + "C" + ], + "attrsFormat": "normalized", + "covered": false, + "http": { + "url": "http://localhost:REGEX(\d+)/notify" + }, + "onlyChangedAttrs": false + }, + "status": "active", + "subject": { + "condition": { + "attrs": [ + "B", + "C" + ] + }, + "entities": [ + { + "idPattern": "E.*", + "type": "T" + } + ] + } + } +] + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB