diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 528af55d4c..f85bfe8d8f 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ +- Add: servicePath field to builtin attributes (#2877) - Fix: logDeprecate not working correctly (`geo:json` wrongly considered as deprecated) diff --git a/src/lib/common/globals.h b/src/lib/common/globals.h index 5060a11d1d..73c68c7187 100644 --- a/src/lib/common/globals.h +++ b/src/lib/common/globals.h @@ -95,6 +95,7 @@ #define DATE_MODIFIED "dateModified" #define DATE_EXPIRES "dateExpires" #define ALTERATION_TYPE "alterationType" +#define SERVICE_PATH "servicePath" #define ALL_ATTRS "*" diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 876a8daeec..e996aba9e2 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -836,6 +836,11 @@ static std::string sortCriteria(const std::string& sortToken) return ENT_MODIFICATION_DATE; } + if (sortToken == SERVICE_PATH) + { + return std::string("_id.") + ENT_SERVICE_PATH; + } + if (sortToken == ENT_ENTITY_ID) { return std::string("_id.") + ENT_ENTITY_ID; @@ -1313,6 +1318,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++) { diff --git a/src/lib/rest/StringFilter.cpp b/src/lib/rest/StringFilter.cpp index 52da7d858b..9ac0a26c76 100644 --- a/src/lib/rest/StringFilter.cpp +++ b/src/lib/rest/StringFilter.cpp @@ -1835,6 +1835,10 @@ bool StringFilter::mongoFilterPopulate(std::string* errorStringP) { k = ENT_MODIFICATION_DATE; } + else if (left == SERVICE_PATH) + { + k = std::string("_id.") + ENT_SERVICE_PATH; + } else if (left == itemP->attributeName + "." + ENT_ATTRS_MD "." + NGSI_MD_DATECREATED) { k = std::string(ENT_ATTRS) + "." + itemP->attributeName + "." + ENT_ATTRS_CREATION_DATE; diff --git a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/get_entities_with_servicepath_as_a_wildcard_and_multiple_elements.test b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/get_entities_with_servicepath_as_a_wildcard_and_multiple_elements.test new file mode 100644 index 0000000000..ca01185745 --- /dev/null +++ b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/get_entities_with_servicepath_as_a_wildcard_and_multiple_elements.test @@ -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 diff --git a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_as_a_builtin_attribute_return_in_notifications.test b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_as_a_builtin_attribute_return_in_notifications.test new file mode 100644 index 0000000000..6996c26a54 --- /dev/null +++ b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_as_a_builtin_attribute_return_in_notifications.test @@ -0,0 +1,184 @@ +# 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-- +return servicePath as a builtin attribute in notifications + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# 01. POST /v2/entities, to create entity E1 +# 02. POST /v2/subscriptions, to create a subscription for E1 with notification.attrs as [ "*", "servicePath"] +# 03. Update entity E1 +# 04. Dump accumulator and see two notifications +# + + +echo "01. POST /v2/entities, to create entity E1" +echo "==========================================" +payload='{ + "id": "E1", + "type": "Thing", + "A1": { + "value": 26.5, + "type": "Float" + }, + "B1": { + "value": 720, + "type": "Integer" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath /Madrid/A +echo +echo + + +echo "02. POST /v2/subscriptions, to create a subscription for E1 with notification.attrs as [ "*", "servicePath"]" +echo "============================================================================================================" +payload='{ + "description": "A subscription to get info about E1", + "subject": { + "entities": [ + { + "id": "E1", + "type": "Thing" + } + ], + "condition": { + "attrs": [ + "A1" + ] + } + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ + "*", + "servicePath" + ] + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +subId=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") +echo +echo + + +echo "03. Update entity E1" +echo "====================" +payload='{ + "A1": { + "value": 31.7, + "type": "Float" + } +}' +orionCurl --url /v2/entities/E1/attrs --payload "$payload" -X PATCH --servicePath /Madrid/A +echo +echo + + +echo "04. Dump accumulator and see two notifications" +echo "==============================================" +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. POST /v2/entities, to create entity E1 +========================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E1?type=Thing +Content-Length: 0 + + + +02. POST /v2/subscriptions, to create a subscription for E1 with notification.attrs as [ *, servicePath] +============================================================================================================ +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Content-Length: 0 + + + +03. Update entity E1 +==================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump accumulator and see two notifications +============================================== +POST http://localhost:REGEX(\d+)/notify +Fiware-Servicepath: /Madrid/A +Content-Length: 244 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: localhost:9997 +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "A1": { + "metadata": {}, + "type": "Float", + "value": 31.7 + }, + "B1": { + "metadata": {}, + "type": "Integer", + "value": 720 + }, + "id": "E1", + "servicePath": { + "metadata": {}, + "type": "Text", + "value": "/Madrid/A" + }, + "type": "Thing" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop diff --git a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test new file mode 100644 index 0000000000..dd55accdfa --- /dev/null +++ b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_behave_with_q_and_orderBy.test @@ -0,0 +1,293 @@ +# 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-- +servicepath behave with q and orderBy + +--SHELL-INIT-- +dbInit CB +brokerStart CB + +--SHELL-- + +# +# 01. Create entity E1 with temperature = 35 in servicePath /Madrid/A +# 02. Create entity E2 with temperature = 25 in servicePath /Barcelona/B +# 03. Create entity E3 with temperature = 30 in servicePath /Madrid/A +# 04. Create entity E4 with temperature = 40 in servicePath /Barcelona/B +# 05. GET entities with q parameter and servicePath /Madrid/A +# 06. GET entities with orderBy servicePath +# 07. GET entities with orderBy !servicePath +# + + +echo "01. Create entity E1 with temperature = 35 in servicePath /Madrid/A" +echo "===================================================================" +payload='{ + "id": "E1", + "type": "T", + "temperature": { + "value":35, + "type": "Integer" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath /Madrid/A +echo +echo + + +echo "02. Create entity E2 with temperature = 25 in servicePath /Barcelona/B" +echo "======================================================================" +payload='{ + "id": "E2", + "type": "T", + "temperature": { + "value": 25, + "type": "Integer" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath /Barcelon/B +echo +echo + + +echo "03. Create entity E3 with temperature = 30 in servicePath /Madrid/A" +echo "===================================================================" +payload='{ + "id": "E3", + "type": "T", + "temperature": { + "value": 30, + "type": "Integer" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath /Madrid/A +echo +echo + + +echo "04. Create entity E4 with temperature = 40 in servicePath /Barcelona/B" +echo "======================================================================" +payload='{ + "id": "E4", + "type": "T", + "temperature": { + "value": 40, + "type": "Integer" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath /Barcelona/B +echo +echo + + +echo "05. GET entities with q parameter and servicePath /Madrid/A" +echo "===========================================================" +orionCurl --url /v2/entities?q=servicePath:/Madrid/A +echo +echo + + +echo "06. GET entities with orderBy servicePath" +echo "=========================================" +orionCurl --url /v2/entities?orderBy=servicePath +echo +echo + + +echo "07. GET entities with orderBy !servicePath" +echo "==========================================" +orionCurl --url /v2/entities?orderBy=!servicePath +echo +echo + + +--REGEXPECT-- +01. Create entity E1 with temperature = 35 in servicePath /Madrid/A +=================================================================== +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 with temperature = 25 in servicePath /Barcelona/B +====================================================================== +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 with temperature = 30 in servicePath /Madrid/A +=================================================================== +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 with temperature = 40 in servicePath /Barcelona/B +====================================================================== +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 q parameter and servicePath /Madrid/A +=========================================================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 163 + +[ + { + "id": "E1", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 35 + }, + "type": "T" + }, + { + "id": "E3", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 30 + }, + "type": "T" + } +] + + +06. GET entities with orderBy servicePath +========================================= +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 325 + +[ + { + "id": "E2", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 25 + }, + "type": "T" + }, + { + "id": "E4", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 40 + }, + "type": "T" + }, + { + "id": "E1", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 35 + }, + "type": "T" + }, + { + "id": "E3", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 30 + }, + "type": "T" + } +] + + +07. GET entities with orderBy !servicePath +========================================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 325 + +[ + { + "id": "E1", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 35 + }, + "type": "T" + }, + { + "id": "E3", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 30 + }, + "type": "T" + }, + { + "id": "E4", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 40 + }, + "type": "T" + }, + { + "id": "E2", + "temperature": { + "metadata": {}, + "type": "Integer", + "value": 25 + }, + "type": "T" + } +] + + +--TEARDOWN-- +brokerStop CB +dbDrop CB diff --git a/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_in_entity_response.test b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_in_entity_response.test new file mode 100644 index 0000000000..1ac4a3247c --- /dev/null +++ b/test/functionalTest/cases/2877_return_ServicePath_in_entity_response/servicePath_in_entity_response.test @@ -0,0 +1,141 @@ +# 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-- +return ServicePath in entity response + +--SHELL-INIT-- +dbInit CB +brokerStart CB + +--SHELL-- + +# +# 01. POST /v2/entities, to create entity E1 with attr A1 and metadata M1 +# 02. POST /v2/entities, to create entity E2 with attr A2 and metadata M2 +# 03. GET all entities, with service path +# + + +echo "01. POST /v2/entities, to create entity E1 with attr A1 and metadata M1" +echo "=======================================================================" +payload='{ + "id": "E1", + "type": "Thing", + "A1": { + "value": 26.5, + "type": "Float", + "metadata": { + "M1": { + "value": 0.77, + "type": "Float" + } + } + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "02. POST /v2/entities, to create entity E2 with attr A2 and metadata M2" +echo "=======================================================================" +payload='{ + "id": "E2", + "type": "Thing", + "A2": { + "value": 21.5, + "type": "Float", + "metadata": { + "M2": { + "value": 11.5, + "type": "Float" + } + } + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. GET all entities, with service path" +echo "====================================================" +orionCurl --url /v2/entities?attrs=servicePath +echo +echo + + +--REGEXPECT-- +01. POST /v2/entities, to create entity E1 with attr A1 and metadata M1 +======================================================================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E1?type=Thing +Content-Length: 0 + + + +02. POST /v2/entities, to create entity E2 with attr A2 and metadata M2 +======================================================================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E2?type=Thing +Content-Length: 0 + + + +03. GET all entities, with service path +==================================================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 167 + +[ + { + "id": "E1", + "servicePath": { + "metadata": {}, + "type": "Text", + "value": "/" + }, + "type": "Thing" + }, + { + "id": "E2", + "servicePath": { + "metadata": {}, + "type": "Text", + "value": "/" + }, + "type": "Thing" + } +] + + +--TEARDOWN-- +brokerStop CB +dbDrop CB