Skip to content

Commit

Permalink
Adding idPattern to forwarded requests
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Oct 7, 2024
1 parent a542986 commit b42458b
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#1621: URL-Encoding single quote in attribute values in TRoE DB
#1649: Crash when using subscriptions in a mixed environment (LD and V2)
#1682: Default User Context
#1688: Forward of idPattern URL parameter

## New Features:
* Distributed subscriptions: subordinate subscriptions are DELETED when their "father" is deleted.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/orionld/distOp/distOpSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
uriParamAdd(&urlParts, "id", entityIds, -1);
else if (distOpP->entityId != NULL)
uriParamAdd(&urlParts, "id", distOpP->entityId, -1);
else if (orionldState.uriParams.idPattern != NULL)
uriParamAdd(&urlParts, "idPattern", orionldState.uriParams.idPattern, -1);
}

if (distOpP->qNode != NULL)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# 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--
GET /entities with two brokers all connected via registrations

--SHELL-INIT--
dbInit CB
dbInit CP1
orionldStart CB -experimental -forwarding -wip entityMaps
orionldStart CP1 -experimental

--SHELL--

#
# 01. In CP1, create an entity urn:E1 with attributes P1+R1
# 02. In CP1, create an entity urn:E2 with attributes P1+R1
# 03. In CP1, create an entity urn:F1 with attributes P1+R1
# 04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1
# 05. GET entities in CB with idPattern urn:E.* - see E1 and E2, not urn:F1
#

echo "01. In CP1, create an entity urn:E1 with attributes P1+R1"
echo "========================================================="
payload='{
"id": "urn:E1",
"type": "T",
"P1": "Entity E1 in CP1",
"R1": { "object": "urn:E2" }
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT
echo
echo


echo "02. In CP1, create an entity urn:E2 with attributes P1+R1"
echo "========================================================="
payload='{
"id": "urn:E2",
"type": "T",
"P1": "Entity E2 in CP1",
"R1": { "object": "urn:E2" }
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT
echo
echo


echo "03. In CP1, create an entity urn:F1 with attributes P1+R1"
echo "========================================================="
payload='{
"id": "urn:F1",
"type": "T",
"P1": "Entity F1 in CP1",
"R1": { "object": "urn:E2" }
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT
echo
echo


echo "04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1"
echo "==================================================================================="
payload='{
"id": "urn:R1",
"type": "ContextSourceRegistration",
"information": [
{
"entities": [
{
"type": "T"
}
]
}
],
"mode": "inclusive",
"operations": [ "retrieveOps" ],
"endpoint": "http://'$(hostname)':'$CP1_PORT'"
}'
orionCurl --url /ngsi-ld/v1/csourceRegistrations --payload "$payload"
echo
echo


echo "05. GET entities in CB with idPattern urn:E.* - see E1 and E2"
echo "============================================================="
orionCurl --url "/ngsi-ld/v1/entities?idPattern=urn:E.*"
echo
echo


--REGEXPECT--
01. In CP1, create an entity urn:E1 with attributes P1+R1
=========================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:E1



02. In CP1, create an entity urn:E2 with attributes P1+R1
=========================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:E2



03. In CP1, create an entity urn:F1 with attributes P1+R1
=========================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:F1



04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1
===================================================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/csourceRegistrations/urn:R1



05. GET entities in CB with idPattern urn:E.* - see E1 and E2
=============================================================
HTTP/1.1 200 OK
Content-Length: 253
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
NGSILD-EntityMap: urn:ngsi-ld:entity-map:REGEX(.*)

[
{
"P1": {
"type": "Property",
"value": "Entity E1 in CP1"
},
"R1": {
"object": "urn:E2",
"type": "Relationship"
},
"id": "urn:E1",
"type": "T"
},
{
"P1": {
"type": "Property",
"value": "Entity E2 in CP1"
},
"R1": {
"object": "urn:E2",
"type": "Relationship"
},
"id": "urn:E2",
"type": "T"
}
]


--TEARDOWN---
brokerStop CB
brokerStop CP1
dbDrop CB
dbDrop CP1

0 comments on commit b42458b

Please sign in to comment.