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

actionType delete additional testCases #4445

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4406,7 +4406,7 @@ regular non-batch operations can be done:
* `appendStrict`: maps to `POST /v2/entities` (if the entity does not already exist) or
`POST /v2/entities/<id>/attrs?options=append` (if the entity already exists).
* `update`: maps to `PATCH /v2/entities/<id>/attrs`.
* `delete`: maps to `DELETE /v2/entities/<id>/attrs/<attrName>` on every attribute included in the entity or
* `delete`: maps to `DELETE /v2/entities/<id>/attrs/<attrName>` on every attribute included in the entity (in this case the actual value of the attribute is not relevant) or
to `DELETE /v2/entities/<id>` if no attribute were included in the entity.
* `replace`: maps to `PUT /v2/entities/<id>/attrs`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
V2 batch update REPLACE
V2 batch update DELETE

--SHELL-INIT--
dbInit CB
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
# 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--
V2 batch update DELETE in non existing and existing attribute

--SHELL-INIT--
dbInit CB
brokerStart CB 0

--SHELL--

#
# 01. Create E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3 using POST /v2/op/update with append
# 02. GET /v2/entities to see E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3
# 03. Delete E1-A1/A2=null, E2-A1/A2=null (A2 not existing) and E3-A1/A2=null using POST /v2/op/update with delete, get error
# 04. GET /v2/entities to see E1/T/A3, E2/T/A1-A3 and E3/T/A3 in entities
#

echo "01. Create E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3 using POST /v2/op/update with append"
echo "==========================================================================================="
payload='{
"actionType": "append",
"entities": [
{
"id": "E1",
"type": "T",
"A1": {
"type": "Number",
"value": 11
},
"A2": {
"type": "Number",
"value": 12
},
"A3": {
"type": "Number",
"value": 13
}
},
{
"id": "E2",
"type": "T",
"A1": {
"type": "Number",
"value": 21
},
"A3": {
"type": "Number",
"value": 23
}
},
{
"id": "E3",
"type": "T",
"A1": {
"type": "Number",
"value": 31
},
"A2": {
"type": "Number",
"value": 32
},
"A3": {
"type": "Number",
"value": 33
}
}
]
}'
orionCurl --url /v2/op/update --payload "$payload"
echo
echo


echo "02. GET /v2/entities to see E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3"
echo "======================================================================="
orionCurl --url /v2/entities
echo
echo


echo "03. Delete E1-A1/A2=null, E2-A1/A2=null (A2 not existing) and E3-A1/A2=null using POST /v2/op/update with delete, get error"
echo "==========================================================================================================================="
payload='{
"actionType": "delete",
"entities": [
{
"id": "E1",
"type": "T",
"A1": {
"type": "Number",
"value": null
},
"A2": {
"type": "Number",
"value": null
}
},
{
"id": "E2",
"type": "T",
"A1": {
"type": "Number",
"value": null
},
"A2": {
"type": "Number",
"value": null
}
},
{
"id": "E3",
"type": "T",
"A1": {
"type": "Number",
"value": null
},
"A2": {
"type": "Number",
"value": null
}
}
]
}'
orionCurl --url /v2/op/update --payload "$payload"
echo
echo


echo "04. GET /v2/entities to see E1/T/A3, E2/T/A1-A3 and E3/T/A3 in entities"
echo "======================================================================="
orionCurl --url /v2/entities
echo
echo


--REGEXPECT--
01. Create E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3 using POST /v2/op/update with append
===========================================================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



02. GET /v2/entities to see E1/T/A1-A2-A3, E2/T/A1-A3 and E3/T/A1-A2-A3
=======================================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 454

[
{
"A1": {
"metadata": {},
"type": "Number",
"value": 11
},
"A2": {
"metadata": {},
"type": "Number",
"value": 12
},
"A3": {
"metadata": {},
"type": "Number",
"value": 13
},
"id": "E1",
"type": "T"
},
{
"A1": {
"metadata": {},
"type": "Number",
"value": 21
},
"A3": {
"metadata": {},
"type": "Number",
"value": 23
},
"id": "E2",
"type": "T"
},
{
"A1": {
"metadata": {},
"type": "Number",
"value": 31
},
"A2": {
"metadata": {},
"type": "Number",
"value": 32
},
"A3": {
"metadata": {},
"type": "Number",
"value": 33
},
"id": "E3",
"type": "T"
}
]


03. Delete E1-A1/A2=null, E2-A1/A2=null (A2 not existing) and E3-A1/A2=null using POST /v2/op/update with delete, get error
===========================================================================================================================
HTTP/1.1 404 Not Found
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 79

{
"description": "The entity does not have such an attribute",
"error": "NotFound"
}


04. GET /v2/entities to see E1/T/A3, E2/T/A1-A3 and E3/T/A3 in entities
=======================================================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 262

[
{
"A3": {
"metadata": {},
"type": "Number",
"value": 13
},
"id": "E1",
"type": "T"
},
{
"A1": {
"metadata": {},
"type": "Number",
"value": 21
},
"A3": {
"metadata": {},
"type": "Number",
"value": 23
},
"id": "E2",
"type": "T"
},
{
"A3": {
"metadata": {},
"type": "Number",
"value": 33
},
"id": "E3",
"type": "T"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB
Loading
Loading