From 6219dbae09a7acf91c74a054351fb2e13ae8bb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 28 Sep 2022 15:36:59 +0200 Subject: [PATCH] FIX GET /v2/types and GET /v2/types/{type} wrong attribute types result --- CHANGES_NEXT_RELEASE | 1 + src/lib/mongoBackend/mongoQueryTypes.cpp | 2 +- .../get_types_miss_attr_types.test | 203 ++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 test/functionalTest/cases/4216_get_types_miss_attr_types/get_types_miss_attr_types.test diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index d48b4e7711..0f5371f1f8 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,6 +1,7 @@ - Add: json field in httpCustom and mqttCustom subscriptions (#2560) - Add: ${service}, ${servicePath} and ${authToken} macros in custom notifications (#4159) - Fix: conditions.alterationTypes not working properly when conditions.attributes is used in entityUpdate case (#1494, reopened) +- Fix: GET /v2/types and GET /v2/types/{type} wrong attribute types result (#4216) - Upgrade Debian version from 11.2 to 11.3 in Dockerfile - Deprecated: GET /v2 operation - Remove: RPM package stuff diff --git a/src/lib/mongoBackend/mongoQueryTypes.cpp b/src/lib/mongoBackend/mongoQueryTypes.cpp index b4da8658f1..7d67598d7a 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.cpp +++ b/src/lib/mongoBackend/mongoQueryTypes.cpp @@ -72,7 +72,7 @@ static void getAttributeTypes { orion::BSONObjBuilder bob; - if (entityType.empty()) + if (!entityType.empty()) { std::string idType = std::string("_id.") + ENT_ENTITY_TYPE; diff --git a/test/functionalTest/cases/4216_get_types_miss_attr_types/get_types_miss_attr_types.test b/test/functionalTest/cases/4216_get_types_miss_attr_types/get_types_miss_attr_types.test new file mode 100644 index 0000000000..b0987b919a --- /dev/null +++ b/test/functionalTest/cases/4216_get_types_miss_attr_types/get_types_miss_attr_types.test @@ -0,0 +1,203 @@ +# Copyright 2022 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 Entity Type misses attribute types + +--SHELL-INIT-- +dbInit CB +brokerStart CB 100 + +--SHELL-- + +# +# 01. Create E11/ET1/A-AT1 +# 02. Create E12/ET1/A-AT2 +# 03. Create E21/ET2/A-AT3 +# 04. Create E22/ET2/A-AT4 +# 05. GET /v2/types and get AT1 and AT2 attribute types in ET1 and AT3 and AT4 in ET2 +# 06. GET /v2/types/ET1 and get AT3 and AT4 attribute types +# + +echo "01. Create E11/ET1/A-AT1" +echo "========================" +payload='{ + "type": "ET1", + "id": "E11", + "A": { "type": "AT1", "value": "irrelevant" } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "02. Create E12/ET1/A-AT2" +echo "========================" +payload='{ + "type": "ET1", + "id": "E12", + "A": { "type": "AT2", "value": "irrelevant" } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Create E21/ET2/A-AT3" +echo "========================" +payload='{ + "type": "ET2", + "id": "E21", + "A": { "type": "AT3", "value": "irrelevant" } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "04. Create E22/ET2/A-AT4" +echo "=======================" +payload='{ + "type": "ET2", + "id": "E22", + "A": { "type": "AT4", "value": "irrelevant" } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "05. GET /v2/types and get AT1 and AT2 attribute types in ET1 and AT3 and AT4 in ET2" +echo "===================================================================================" +orionCurl --url /v2/types +echo +echo + + +echo "06. GET /v2/types/ET1 and get AT1 and AT2 attribute types" +echo "=========================================================" +orionCurl --url /v2/types/ET1 +echo +echo + + +--REGEXPECT-- +01. Create E11/ET1/A-AT1 +======================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E11?type=ET1 +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +02. Create E12/ET1/A-AT2 +======================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E12?type=ET1 +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +03. Create E21/ET2/A-AT3 +======================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E21?type=ET2 +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +04. Create E22/ET2/A-AT4 +======================= +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/E22?type=ET2 +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + + + +05. GET /v2/types and get AT1 and AT2 attribute types in ET1 and AT3 and AT4 in ET2 +=================================================================================== +HTTP/1.1 200 OK +Content-Length: 127 +Content-Type: application/json +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + +[ + { + "attrs": { + "A": { + "types": [ + "AT1", + "AT2" + ] + } + }, + "count": 2, + "type": "ET1" + }, + { + "attrs": { + "A": { + "types": [ + "AT3", + "AT4" + ] + } + }, + "count": 2, + "type": "ET2" + } +] + + +06. GET /v2/types/ET1 and get AT1 and AT2 attribute types +========================================================= +HTTP/1.1 200 OK +Content-Length: 49 +Content-Type: application/json +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Date: REGEX(.*) + +{ + "attrs": { + "A": { + "types": [ + "AT1", + "AT2" + ] + } + }, + "count": 2 +} + + +--TEARDOWN-- +brokerStop CB +dbDrop CB