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

Fix return servicePath in the entity response #4329

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Add: servicePath field to builtin attributes (#2877)
- Fix: logDeprecate not working correctly (`geo:json` wrongly considered as deprecated)
1 change: 1 addition & 0 deletions src/lib/common/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#define DATE_MODIFIED "dateModified"
#define DATE_EXPIRES "dateExpires"
#define ALTERATION_TYPE "alterationType"
#define SERVICE_PATH "servicePath"
#define ALL_ATTRS "*"


Expand Down
5 changes: 5 additions & 0 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,11 @@ void addBuiltins(ContextElementResponse* cerP, const std::string& alterationType
addIfNotPresentAttr(&cerP->entity, ALTERATION_TYPE, DEFAULT_ATTR_STRING_TYPE, alterationType);
}

// servicePath
if (!cerP->entity.servicePath.empty())
{
addIfNotPresentAttr(&cerP->entity, SERVICE_PATH, DEFAULT_ATTR_STRING_TYPE, cerP->entity.servicePath);
}

for (unsigned int ix = 0; ix < cerP->entity.attributeVector.size(); ix++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
# Copyright 2023 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--
get entities with servicepath as a wildcard and multiple elements

--SHELL-INIT--
dbInit CB
brokerStart CB

--SHELL--

#
# 01. Create entity E1 in servicePath /Madrid/A
# 02. Create entity E2 in servicePath /Madrid/B
# 03. Create entity E3 in servicePath /Barcelona/C
# 04. Create entity E4 in servicePath /Barcelona/D
# 05. GET entities with servicePath /#
# 06. GET entities with servicePath /Madrid/#
# 07. GET entities with servicePath /Madrid/A,/Barcelona/C
# 08. GET entities with servicePath /Madrid/A,/Barcelona/#
# 09. GET entities with servicePath /Madrid/#,/Barcelona/#
#


echo "01. Create entity E1"
echo "===================="
payload='{
"id": "E1",
"type": "T",
"A": {
"value":11.5,
"type": "Float"
}
}'
orionCurl --url /v2/entities --payload "$payload" --servicePath /Madrid/A
echo
echo


echo "02. Create entity E2"
echo "===================="
payload='{
"id": "E2",
"type": "T",
"B": {
"value": 12.5,
"type": "Float"
}
}'
orionCurl --url /v2/entities --payload "$payload" --servicePath /Madrid/B
echo
echo


echo "03. Create entity E3"
echo "===================="
payload='{
"id": "E3",
"type": "T",
"C": {
"value": 13.5,
"type": "Float"
}
}'
orionCurl --url /v2/entities --payload "$payload" --servicePath /Barcelona/C
echo
echo


echo "04. Create entity E4"
echo "===================="
payload='{
"id": "E4",
"type": "T",
"D": {
"value": 14.5,
"type": "Float"
}
}'
orionCurl --url /v2/entities --payload "$payload" --servicePath /Barcelona/D
echo
echo


echo "05. GET entities with servicePath /#"
echo "===================================="
orionCurl --url /v2/entities?attrs=servicePath --servicePath /#
echo
echo


echo "06. GET entities with servicePath /Madrid/A"
echo "==========================================="
orionCurl --url /v2/entities?attrs=servicePath --servicePath /Madrid/A
echo
echo


echo "07. GET entities with servicePath /Madrid/A,/Barcelona/C"
echo "========================================================"
orionCurl --url /v2/entities?attrs=servicePath --servicePath /Madrid/A,/Barcelona/C
echo
echo


echo "08. GET entities with servicePath /Madrid/A,/Barcelona/#"
echo "========================================================"
orionCurl --url /v2/entities?attrs=servicePath --servicePath /Madrid/A,/Barcelona/#
echo
echo


echo "09. GET entities with servicePath /Madrid/#,/Barcelona/#"
echo "========================================================"
orionCurl --url /v2/entities?attrs=servicePath --servicePath /Madrid/#,/Barcelona/#
echo
echo


--REGEXPECT--
01. Create entity E1
====================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/E1?type=T
Content-Length: 0



02. Create entity E2
====================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/E2?type=T
Content-Length: 0



03. Create entity E3
====================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/E3?type=T
Content-Length: 0



04. Create entity E4
====================
HTTP/1.1 201 Created
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Location: /v2/entities/E4?type=T
Content-Length: 0



05. GET entities with servicePath /#
====================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 355

[
{
"id": "E1",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/A"
},
"type": "T"
},
{
"id": "E2",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/B"
},
"type": "T"
},
{
"id": "E3",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/C"
},
"type": "T"
},
{
"id": "E4",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/D"
},
"type": "T"
}
]


06. GET entities with servicePath /Madrid/A
===========================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 88

[
{
"id": "E1",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/A"
},
"type": "T"
}
]


07. GET entities with servicePath /Madrid/A,/Barcelona/C
========================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 178

[
{
"id": "E1",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/A"
},
"type": "T"
},
{
"id": "E3",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/C"
},
"type": "T"
}
]


08. GET entities with servicePath /Madrid/A,/Barcelona/#
========================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 268

[
{
"id": "E1",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/A"
},
"type": "T"
},
{
"id": "E3",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/C"
},
"type": "T"
},
{
"id": "E4",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/D"
},
"type": "T"
}
]


09. GET entities with servicePath /Madrid/#,/Barcelona/#
========================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 355

[
{
"id": "E1",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/A"
},
"type": "T"
},
{
"id": "E2",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Madrid/B"
},
"type": "T"
},
{
"id": "E3",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/C"
},
"type": "T"
},
{
"id": "E4",
"servicePath": {
"metadata": {},
"type": "Text",
"value": "/Barcelona/D"
},
"type": "T"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB
Loading