Skip to content

Commit

Permalink
Merge pull request #4474 from telefonicaid/hardening/batch_delete_rem…
Browse files Browse the repository at this point in the history
…oving_attrs_and_entity_in_same_request

FIX batch delete logic
  • Loading branch information
AlvaroVega authored Jan 15, 2024
2 parents 9535bef + b85af8f commit 4dbb1fa
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4471,7 +4471,9 @@ unsigned int processContextElement
responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE);
}

if (updateCoverageP != NULL)
// The following check makes sense only when there are at least one attribute in the request
// (e.g. not for entity deletion, which doesn't include attributes)
if ((updateCoverageP != NULL) && (eP->attributeVector.size() > 0))
{
if ((action == ActionTypeUpdate) || (action == ActionTypeDelete))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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--
Removing attributes and etity itself in same entity batch delete

--SHELL-INIT--
dbInit CB
brokerStart CB

--SHELL--

#
# 01. Create entities room1 and room2
# 02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204
#

echo "01. Create entities room1 and room2"
echo "==================================="
payload='{
"entities": [
{
"type": "house",
"id": "room1",
"temperature": 34
},
{
"type": "home",
"id": "room2",
"temperature": 44
}
],
"actionType": "append"
}'
orionCurl --url /v2/op/update?options=keyValues --payload "$payload"
echo
echo


echo "02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204"
echo "=========================================================================================================="
payload='{
"entities": [
{
"type": "house",
"id": "room1",
"temperature": 34
},
{
"type": "home",
"id": "room2",
"temperature": 44
},
{
"type": "house",
"id": "room1"
},
{
"type": "home",
"id": "room2"
}
],
"actionType": "delete"
}'
orionCurl --url /v2/op/update?options=keyValues --payload "$payload"
echo
echo




--REGEXPECT--
01. Create entities room1 and room2
===================================
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204
==========================================================================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit 4dbb1fa

Please sign in to comment.