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 onlyChagnedAttrs true with alterationType for entityDelete case #4486

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 src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3533,7 +3533,7 @@ static unsigned int updateEntity
attrNames.push_back(eP->attributeVector[ix]->name);
}

// Note we cannot usse eP->type for the type, as it may be blank in the request
// Note we cannot use eP->type for the type, as it may be blank in the request
// (that would break the cases/1494_subscription_alteration_types/sub_alteration_type_entity_delete2.test case)
if (!addTriggeredSubscriptions(notifyCerP->entity.id,
notifyCerP->entity.type,
Expand Down
20 changes: 14 additions & 6 deletions src/lib/mongoBackend/MongoGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2292,14 +2292,22 @@ static void getCommonAttributes
std::vector<std::string>& resultVector
)
{
for (unsigned int cavOc = 0; cavOc < fVector.size(); ++cavOc)
for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc)
{
for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc)
// some builtin attributes are always include (even when onlyChangedAttrs is true)
if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED))
{
// some builtin attributes are always include (even when onlyChangedAttrs is true)
if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED) || (fVector[cavOc] == sVector[avOc]))
{
resultVector.push_back(sVector[avOc]);
resultVector.push_back(sVector[avOc]);
}
else
{
for (unsigned int cavOc = 0; cavOc < fVector.size(); ++cavOc)
{
if (fVector[cavOc] == sVector[avOc])
{
resultVector.push_back(sVector[avOc]);
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Copyright 2019 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--
Notify only attributes that change get with alterationType on entityDelete

--SHELL-INIT--
dbInit CB
brokerStart CB
accumulatorStart --pretty-print


--SHELL--

#
# 01. Create entity E-A,B,C
# 02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType
# 03. Delete E
# 04. Dump notification get E with alterationType entityDelete
#


echo '01. Create entity E-A,B,C'
echo '========================='
payload='{
"id": "E",
"type": "T",
"A": {
"value": 1,
"type": "Number"
},
"B": {
"value": 1,
"type": "Number"
},
"C": {
"value": 1,
"type": "Number"
}
}'
orionCurl --url /v2/entities --payload "$payload"
echo
echo


echo '02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType'
echo '==============================================================================================================='
payload='{
"subject": {
"entities": [
{
"id": "E",
"type": "T"
}
],
"condition": {
"alterationTypes": [ "entityDelete" ]
}
},
"notification": {
"http": {
"url": "http://localhost:'$LISTENER_PORT'/notify"
},
"attrs": [ "alterationType" ],
"onlyChangedAttrs": true
}
}'
orionCurl --url /v2/subscriptions --payload "$payload"
echo
echo


echo '03. Delete E'
echo '============'
orionCurl --url /v2/entities/E -X DELETE
echo
echo


echo '04. Dump notification get E with alterationType entityDelete'
echo '============================================================'
accumulatorDump
echo
echo


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



02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType
===============================================================================================================
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. Delete E
============
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



04. Dump notification get E with alterationType entityDelete
============================================================
POST http://localhost:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 146
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
Ngsiv2-Attrsformat: normalized
Host: localhost:REGEX(\d+)
Accept: application/json
Content-Type: application/json; charset=utf-8
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1

{
"data": [
{
"alterationType": {
"metadata": {},
"type": "Text",
"value": "entityDelete"
},
"id": "E",
"type": "T"
}
],
"subscriptionId": "REGEX([0-9a-f]{24})"
}
=======================================


--TEARDOWN--
brokerStop CB
dbDrop CB
accumulatorStop
Loading