Skip to content

Commit

Permalink
Merge pull request #704 from FIWARE/bug/location-in-subscriptions
Browse files Browse the repository at this point in the history
Bug/location in subscriptions
  • Loading branch information
kzangeli committed Jan 27, 2021
2 parents 2fa8552 + ff30022 commit 8eb3b30
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/orionld/kjTree/kjTreeToStringList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ bool kjTreeToStringList(KjNode* kNodeP, std::vector<std::string>* stringListP)
char* expanded;

STRING_CHECK(attributeP, "String-List item");
expanded = orionldContextItemExpand(orionldState.contextP, attributeP->value.s, true, NULL);

//
// Special attributes are not expanded
//
if (strcmp(attributeP->value.s, "location") == 0)
expanded = attributeP->value.s;
else
expanded = orionldContextItemExpand(orionldState.contextP, attributeP->value.s, true, NULL);

stringListP->push_back(expanded);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Copyright 2021 FIWARE Foundation e.V.
#
# This file is part of Orion-LD Context Broker.
#
# Orion-LD 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-LD 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-LD Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# orionld at fiware dot org

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
Subscription over a location attribute

--SHELL-INIT--
export BROKER=orionld
dbInit CB
brokerStart CB 0-255
accumulatorStart --pretty-print 127.0.0.1 ${LISTENER_PORT}

--SHELL--

#
# 01. Create a subscription with location in notification::attrs
# 02. Create a matching entity
# 03. Dump the accumulator - see the notification
#

echo "01. Create a subscription with location in notification::attrs"
echo "=============================================================="
payload='{
"id": "urn:ngsi-ld:Subscription:mySubscription123",
"type": "Subscription",
"entities": [
{
"type": "T"
}
],
"watchedAttributes": ["location"],
"notification": {
"attributes": ["location"],
"endpoint": {
"uri": "http://127.0.0.1:'${LISTENER_PORT}'/notify"
}
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "02. Create a matching entity"
echo "============================"
payload='{
"id": "urn:ngsi-ld:entities:E1",
"type": "T",
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [ 1, 2 ]
}
}
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload"
echo
echo


echo "03. Dump the accumulator - see the notification"
echo "==============================================="
accumulatorDump
echo
echo


--REGEXPECT--
01. Create a subscription with location in notification::attrs
==============================================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:mySubscription123
Date: REGEX(.*)



02. Create a matching entity
============================
HTTP/1.1 201 Created
Content-Length: 0
Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:E1
Date: REGEX(.*)



03. Dump the accumulator - see the notification
===============================================
POST http:REGEX(.*)
Fiware-Servicepath: /
Content-Length: 314
User-Agent: REGEX(.*)
Ngsiv2-Attrsformat: normalized
Host: REGEX(.*)
Accept: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Content-Type: application/json; charset=utf-8

{
"data": [
{
"id": "urn:ngsi-ld:entities:E1",
"location": {
"type": "GeoProperty",
"value": {
"coordinates": [
1,
2
],
"type": "Point"
}
},
"type": "T"
}
],
"id": "urn:ngsi-ld:Notification:REGEX(.*)",
"notifiedAt": "REGEX(.*)",
"subscriptionId": "urn:ngsi-ld:Subscription:mySubscription123",
"type": "Notification"
}
=======================================


--TEARDOWN--
brokerStop CB
accumulatorStop
#dbDrop CB

0 comments on commit 8eb3b30

Please sign in to comment.