Skip to content

Commit

Permalink
Fixed issue #1649
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Sep 6, 2024
1 parent e8b09d6 commit 850fc7b
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/mongoBackend/mongoGetSubscriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ using ngsiv2::EntID;
*/
static void extractSubscriptionId(Subscription* s, const BSONObj* rP)
{
s->id = getFieldF(rP, "_id").OID().toString();
mongo::BSONElement bsonElement = rP->getField("_id");
mongo::BSONType bsonType = bsonElement.type();

if (bsonType == mongo::jstOID)
s->id = bsonElement.OID().toString();
else
s->id = bsonElement.String();
}


Expand Down
117 changes: 117 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_issue_1649.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright 2024 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--
Issue #1649 - Subscription created with NGSI-LD and retrieved with NGSIv2

--SHELL-INIT--
dbInit CB
dbInit CB test
orionldStart CB -multiservice

--SHELL--

#
# 01. Create a subscription using NGSI-LD
# 02. Retrieve it using NGSIv2
#

echo "01. Create a subscription using NGSI-LD"
echo "======================================="
payload='{
"description": "Notify me of all product price changes",
"type": "Subscription",
"entities": [{"type": "Product"}],
"watchedAttributes": ["price"],
"notification": {
"format": "keyValues",
"endpoint": {
"uri": "http://tutorial:3000/subscription/price-change",
"accept": "application/json"
}
},
"@context": "https://smartdatamodels.org/context.jsonld"
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload" -H "Content-Type: application/ld+json" -H 'fiware-service: test' -H 'fiware-servicepath: /#'
echo
echo


echo "02. Retrieve it using NGSIv2"
echo "============================"
orionCurl --url /v2/subscriptions -H 'fiware-service: test'
echo
echo


--REGEXPECT--
01. Create a subscription using NGSI-LD
=======================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:REGEX(.*)
NGSILD-Tenant: test



02. Retrieve it using NGSIv2
============================
HTTP/1.1 200 OK
Content-Length: 467
Content-Type: application/json
Date: REGEX(.*)
Fiware-Correlator: REGEX(.*)

[
{
"description": "Notify me of all product price changes",
"expires": "REGEX(.*)",
"id": "urn:ngsi-ld:Subscription:REGEX(.*)",
"notification": {
"attrs": [],
"attrsFormat": "keyValues",
"http": {
"url": "http://tutorial:3000/subscription/price-change"
}
},
"status": "expired",
"subject": {
"condition": {
"attrs": [
"https://uri.etsi.org/ngsi-ld/default-context/price"
]
},
"entities": [
{
"type": "https://uri.etsi.org/ngsi-ld/default-context/Product"
}
]
}
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB
dbDrop CB test

0 comments on commit 850fc7b

Please sign in to comment.