Skip to content

Commit

Permalink
Merge pull request #4204 from telefonicaid/hardening/sub_attrs_deleti…
Browse files Browse the repository at this point in the history
…on_test_cases

ADD test cases for attribute deletion for subscription triggering
  • Loading branch information
mrutid authored Aug 31, 2022
2 parents b23bfe9 + c8f259f commit 05e8a0c
Show file tree
Hide file tree
Showing 4 changed files with 643 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 05e8a0c

Please sign in to comment.