Skip to content

Commit

Permalink
Merge branch 'develop' into restructure-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli authored Jun 5, 2024
2 parents 262cbff + 722ba0c commit cb2a441
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Functional Test

on:
pull_request:
workflow_dispatch:


env:
IMAGE_NAME: localhost:5000/orion-ld-test:latest
Expand Down
5 changes: 5 additions & 0 deletions src/lib/orionld/legacyDriver/legacyPostBatchUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern "C"
#include "orionld/common/typeCheckForNonExistingEntities.h" // typeCheckForNonExistingEntities
#include "orionld/common/duplicatedInstances.h" // duplicatedInstances
#include "orionld/common/performance.h" // PERFORMANCE
#include "orionld/notifications/previousValues.h" // previousValues
#include "orionld/service/orionldServiceInit.h" // orionldHostName, orionldHostNameLen
#include "orionld/context/orionldCoreContext.h" // orionldDefaultUrl, orionldCoreContext
#include "orionld/context/orionldContextPresent.h" // orionldContextPresent
Expand Down Expand Up @@ -188,6 +189,8 @@ bool legacyPostBatchUpdate(void)

// Not existing entities cannot be updated
KjNode* dbEntityP = entityLookupById(idTypeAndCreDateFromDb, entityId);
KjNode* dbAttrsP = (dbEntityP != NULL)? kjLookup(dbEntityP, "attrs") : NULL;

if (dbEntityP == NULL)
{
entityErrorPush(errorsArrayP, entityId, OrionldBadRequestData, "entity does not exist", NULL, 400);
Expand All @@ -207,6 +210,8 @@ bool legacyPostBatchUpdate(void)
kjChildRemove(incomingTree, entityP);
}

previousValues(entityP, dbAttrsP);

char* newType;
if (entityTypeChange(entityP, dbEntityP, &newType) == true)
{
Expand Down
6 changes: 6 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldPostBatchUpsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern "C"
#include "orionld/mongoc/mongocEntitiesUpsert.h" // mongocEntitiesUpsert
#include "orionld/legacyDriver/legacyPostBatchUpsert.h" // legacyPostBatchUpsert
#include "orionld/notifications/alteration.h" // alteration
#include "orionld/notifications/previousValues.h" // previousValues
#include "orionld/serviceRoutines/orionldPostBatchUpsert.h" // Own interface


Expand Down Expand Up @@ -274,7 +275,12 @@ bool orionldPostBatchUpsert(void)
finalDbEntityP = batchReplaceEntity(inEntityP, entityId, entityType, entityCreDate);
}
else
{
KjNode* dbAttrsP = kjLookup(originalDbEntityP, "attrs");

previousValues(inEntityP, dbAttrsP);
finalDbEntityP = batchUpdateEntity(inEntityP, originalDbEntityP, false);
}

if (finalDbEntityP != NULL)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Copyright 2023 FIWARE Foundation e.V.
#
# This file is part of Orion-LD Context Broker.
#
# Orion-LD 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-LD 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-LD Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# orionld at fiware dot org

# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh

--NAME--
showChanges in Subscription - provoke a notification and see the previousValue

--SHELL-INIT--
dbInit CB
orionldStart CB -experimental -triggerOperation
accumulatorStart --pretty-print

--SHELL--

#
# 01. Create E1 with an attribute A1 == 1
# 02. Create a matching subscription S1, with showChanges set to true
# 03. See S1 in the database - make sure showChanges is there
# 04. Update urn:E1/attrs/A1, using upsert update, setting its value to 4
# 05. Dump/Reset accumulator, see A1's value and previousValue
#

echo "01. Create E1 with an attribute A1 == 1"
echo "======================================="
payload='{
"id": "urn:E1",
"type": "Device",
"A1": 1
}'
orionCurl --url /ngsi-ld/v1/entities --payload "$payload"
echo
echo


echo "02. Create a matching subscription S1, with showChanges set to true"
echo "==================================================================="
payload='{
"id": "urn:ngsi-ld:subs:S1",
"type": "Subscription",
"entities": [
{
"id": "urn:E1",
"type": "Device"
}
],
"notification": {
"endpoint": {
"uri": "http://127.0.0.1:'${LISTENER_PORT}'/notify"
},
"showChanges": true
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "03. See S1 in the database - make sure showChanges is there"
echo "==========================================================="
mongoCmd2 ftest "db.csubs.findOne()"
echo
echo


echo "04. Update urn:E1/attrs/A1, using upsert update, setting its value to 4"
echo "======================================================================="
payload='[{
"id": "urn:E1",
"A1":{
"value": 4
}
}]'
orionCurl --url /ngsi-ld/v1/entityOperations/upsert/?options=update --payload "$payload" -X POST
echo
echo


echo "05. Dump/Reset accumulator, see A1's value and previousValue"
echo "============================================================"
accumulatorDump
accumulatorReset
echo
echo




--REGEXPECT--
01. Create E1 with an attribute A1 == 1
=======================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/entities/urn:E1



02. Create a matching subscription S1, with showChanges set to true
===================================================================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:ngsi-ld:subs:S1



03. See S1 in the database - make sure showChanges is there
===========================================================
MongoDB shell version REGEX(.*)
connecting to: REGEX(.*)
MongoDB server version: REGEX(.*)
{
"_id" : "urn:ngsi-ld:subs:S1",
"entities" : [
{
"id" : "urn:E1",
"type" : "https://uri.etsi.org/ngsi-ld/default-context/Device",
"isPattern" : "false",
"isTypePattern" : false
}
],
"createdAt" : REGEX(.*),
"modifiedAt" : REGEX(.*),
"throttling" : 0,
"expression" : {
"geometry" : "",
"coords" : "",
"georel" : "",
"geoproperty" : "",
"q" : "",
"mq" : ""
},
"reference" : "http://REGEX(.*)/notify",
"mimeType" : "application/json",
"showChanges" : true,
"attrs" : [ ],
"format" : "normalized",
"conditions" : [ ],
"status" : "active",
"custom" : false,
"servicePath" : "/#",
"blacklist" : false,
"ldContext" : "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld"
}
bye


04. Update urn:E1/attrs/A1, using upsert update, setting its value to 4
=======================================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



05. Dump/Reset accumulator, see A1's value and previousValue
============================================================
POST http://REGEX(.*)/notify?subscriptionId=urn:ngsi-ld:subs:S1
Content-Length: 318
User-Agent: orionld/REGEX(.*)
Host: REGEX(.*)
Accept: application/json
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)
Ngsild-Attribute-Format: Normalized

{
"data": [
{
"A1": {
"previousValue": 1,
"type": "Property",
"value": 4
},
"id": "urn:E1",
"type": "Device"
}
],
"id": "urn:ngsi-ld:Notification:REGEX(.*)",
"notifiedAt": "20REGEX(.*)Z",
"subscriptionId": "urn:ngsi-ld:subs:S1",
"trigger": "POST /ngsi-ld/v1/entityOperations/upsert",
"type": "Notification"
}
=======================================


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit cb2a441

Please sign in to comment.