Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/location in subscriptions #704

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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