diff --git a/src/lib/orionld/kjTree/kjTreeToMetadata.cpp b/src/lib/orionld/kjTree/kjTreeToMetadata.cpp index 03e652efb9..9ee1d084bf 100644 --- a/src/lib/orionld/kjTree/kjTreeToMetadata.cpp +++ b/src/lib/orionld/kjTree/kjTreeToMetadata.cpp @@ -41,12 +41,61 @@ extern "C" // ----------------------------------------------------------------------------- // -// metadataAdd - from kjTreeToContextAttribute.cpp - needs its own module under orionld/common +// metadataAdd - from kjTreeToContextAttribute.cpp +// +// FIXME: needs its own module under orionld/common // extern bool metadataAdd(ContextAttribute* caP, KjNode* nodeP, char* caName); +// ----------------------------------------------------------------------------- +// +// orionldSubAttributeExpand - expand the name of a sub-attribute +// +// FIXME: needs its own module under orionld/context +// +char* orionldSubAttributeExpand +( + OrionldContext* contextP, + char* shortName, + bool useDefaultUrlIfNotFound, + OrionldContextItem** contextItemPP +) +{ + if (strcmp(shortName, "location") == 0) return shortName; + else if (strcmp(shortName, "observedAt") == 0) return shortName; + else if (strcmp(shortName, "unitCode") == 0) return shortName; + else if (strcmp(shortName, "datasetId") == 0) return shortName; + + return orionldContextItemExpand(contextP, shortName, useDefaultUrlIfNotFound, contextItemPP); +} + + + +// ----------------------------------------------------------------------------- +// +// orionldAttributeExpand - expand the name of an attribute +// +// FIXME: needs its own module under orionld/context +// +char* orionldAttributeExpand +( + OrionldContext* contextP, + char* shortName, + bool useDefaultUrlIfNotFound, + OrionldContextItem** contextItemPP +) +{ + if (strcmp(shortName, "location") == 0) return shortName; + else if (strcmp(shortName, "observationSpace") == 0) return shortName; + else if (strcmp(shortName, "operationSpace") == 0) return shortName; + + return orionldContextItemExpand(contextP, shortName, useDefaultUrlIfNotFound, contextItemPP); +} + + + // ----------------------------------------------------------------------------- // // kjTreeToMetadata - @@ -64,11 +113,10 @@ bool kjTreeToMetadata(ContextAttribute* caP, KjNode* nodeP, char* caName, char** return false; } - // // Expand sub-attribute name // - nodeP->name = orionldContextItemExpand(orionldState.contextP, nodeP->name, true, NULL); + nodeP->name = orionldSubAttributeExpand(orionldState.contextP, nodeP->name, true, NULL); if (caP->metadataVector.lookupByName(nodeP->name) != NULL) { diff --git a/src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp b/src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp index 9177aac024..291ec8b096 100644 --- a/src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp +++ b/src/lib/orionld/serviceRoutines/orionldPatchEntity.cpp @@ -163,6 +163,12 @@ bool orionldPatchEntity(ConnectionInfo* ciP) char* entityId = orionldState.wildcard[0]; char* detail; + // + char buf[1024 * 4]; + kjFastRender(orionldState.kjsonP, orionldState.requestTree, buf, sizeof(buf)); + LM_TMP(("PATCH: incoming: %s", buf)); + // + // 1. Is the Entity ID in the URL a valid URI? if (pcheckUri(entityId, &detail) == false) { @@ -221,6 +227,11 @@ bool orionldPatchEntity(ConnectionInfo* ciP) return false; } + // + kjFastRender(orionldState.kjsonP, inDbAttrsP, buf, sizeof(buf)); + LM_TMP(("PATCH: From DB: %s", buf)); + // + // // 5. Loop over the incoming payload data // Those attrs that don't exist in the DB (dbEntityP) are discarded and added to the 'notUpdated' array @@ -244,19 +255,19 @@ bool orionldPatchEntity(ConnectionInfo* ciP) if ((strcmp(newAttrP->name, "createdAt") == 0) || (strcmp(newAttrP->name, "modifiedAt") == 0)) { - attributeNotUpdated(notUpdatedP, newAttrP->name, "built-in timestamps are ignored"); + attributeNotUpdated(notUpdatedP, shortName, "built-in timestamps are ignored"); newAttrP = next; continue; } else if ((strcmp(newAttrP->name, "id") == 0) || (strcmp(newAttrP->name, "@id") == 0)) { - attributeNotUpdated(notUpdatedP, newAttrP->name, "the ID of an entity cannot be altered"); + attributeNotUpdated(notUpdatedP, shortName, "the ID of an entity cannot be altered"); newAttrP = next; continue; } else if ((strcmp(newAttrP->name, "type") == 0) || (strcmp(newAttrP->name, "@type") == 0)) { - attributeNotUpdated(notUpdatedP, newAttrP->name, "the TYPE of an entity cannot be altered"); + attributeNotUpdated(notUpdatedP, shortName, "the TYPE of an entity cannot be altered"); newAttrP = next; continue; } @@ -298,7 +309,10 @@ bool orionldPatchEntity(ConnectionInfo* ciP) ++newAttrs; newAttrP = next; } - + // + kjFastRender(orionldState.kjsonP, inDbAttrsP, buf, sizeof(buf)); + LM_TMP(("PATCH: inDbAttrsP after processing: %s", buf)); + // if (newAttrs > 0) { diff --git a/src/lib/orionld/troe/pgEntityTreat.cpp b/src/lib/orionld/troe/pgEntityTreat.cpp index 302c7cdbe3..e88c208b0b 100644 --- a/src/lib/orionld/troe/pgEntityTreat.cpp +++ b/src/lib/orionld/troe/pgEntityTreat.cpp @@ -103,7 +103,19 @@ bool pgEntityTreat(PGconn* connectionP, KjNode* entityP, char* id, char* type, T } } else - LM_E(("Internal Error (The attribute '%s' is neither an Object nor an Array)", attrP->name)); + { + if ((strcmp(attrP->name, "id") == 0) || + (strcmp(attrP->name, "@id") == 0) || + (strcmp(attrP->name, "type") == 0) || + (strcmp(attrP->name, "@type") == 0) || + (strcmp(attrP->name, "createdAt") == 0) || + (strcmp(attrP->name, "modifiedAt") == 0)) + { + // If present, all these "attributes" are ignmoredd + } + else + LM_E(("Internal Error (The attribute '%s' is neither an Object nor an Array)", attrP->name)); + } } return true; diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_entity_timestamps.test b/test/functionalTest/cases/0000_ngsild/ngsild_entity_timestamps.test index 2156e4d00f..5a765a766b 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_entity_timestamps.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_entity_timestamps.test @@ -215,7 +215,7 @@ Date: REGEX(.*) 05. GET E1 and make sure all 6 createdAt,modifiedAt are as they should (modifiedAt for entity and A1 new - all others as in step 3) =================================================================================================================================== HTTP/1.1 200 OK -Content-Length: 481 +Content-Length: 441 Content-Type: application/json Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" Date: REGEX(.*) diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_patch_attributes.test b/test/functionalTest/cases/0000_ngsild/ngsild_patch_attributes.test new file mode 100644 index 0000000000..37baf383fa --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_patch_attributes.test @@ -0,0 +1,1001 @@ +# Copyright 2021 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-- +Patching attributes for an entity using different contexts => different longnames for same shortname + +--SHELL-INIT-- +export BROKER=orionld +dbInit CB +brokerStart CB + +--SHELL-- + +# +# 01. Create E1 with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +# 01b. See the entity E1 in mongo +# 02. PATCH E1, all 7 attributes - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +# 02b. See the entity E1 in mongo +# 03. GET E1 - make sure step 02 replaced the attributes +# 04. PATCH E1, all 7 attributes, and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 04b. See the entity E1 in mongo +# 05. GET E1 - make sure step 04 replaced 3 attributes and ignored the other four +# 06. PATCH E1, all 7 attributes, and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 06b. See the entity E1 in mongo +# 07. GET E1 - make sure step 06 replaced 3 attributes and ignored the other four +# + +echo "01. Create E1 with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored)" +echo "===========================================================================================================================" +payload='[ + { + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11, 12 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11, 13 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11, 14 ] + } + }, + "weight": { + "type": "Property", + "value": 100, + "unitCode": "kg", + "observedAt": "2021-03-07T08:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:1", + "observedAt": "2021-03-07T08:32:00.123Z" + } + } +]' +orionCurl --url /ngsi-ld/v1/entityOperations/create --payload "$payload" +echo +echo + + +echo "01b. See the entity E1 in mongo" +echo "===============================" +mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' +echo +echo + + +echo "02. PATCH E1, all 7 attributes - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED" +echo "=================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 21, 22 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 21, 23 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 21, 24 ] + } + }, + "weight": { + "type": "Property", + "value": 200, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:2", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH +echo +echo + + +echo "02b. See the entity E1 in mongo" +echo "===============================" +mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' +echo +echo + + +echo "03. GET E1 - make sure step 02 replaced the attributes" +echo "=======================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +echo "04. PATCH E1, all 7 attributes, and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "=====================================================================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 41, 42 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 41, 43 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 41, 44 ] + } + }, + "weight": { + "type": "Property", + "value": 400, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:4", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH -H 'Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' +echo +echo + + +echo "04b. See the entity E1 in mongo" +echo "===============================" +mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' +echo +echo + + +echo "05. GET E1 - make sure step 04 replaced 3 attributes and ignored the other four" +echo "================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +echo "06. PATCH E1, all 7 attributes, and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "======================================================================================================================================================================" +payload='{ + "@context": [ "https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld" ], + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 6.1, 6.2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 6.1, 6.3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 6.1, 6.4 ] + } + }, + "weight": { + "type": "Property", + "value": 600, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:6", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH --in application/ld+json +echo +echo + + +echo "06b. See the entity E1 in mongo" +echo "===============================" +mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' +echo +echo + + +echo "07. GET E1 - make sure step 06 replaced 3 attributes and ignored the other four" +echo "================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +--REGEXPECT-- +01. Create E1 with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +=========================================================================================================================== +HTTP/1.1 200 OK +Content-Length: 49 +Content-Type: application/json +Date: REGEX(.*) + +{ + "errors": [], + "success": [ + "urn:ngsi-ld:entity:E1" + ] +} + + +01b. See the entity E1 in mongo +=============================== +MongoDB shell version REGEX(.*) +connecting to: REGEX(.*) +MongoDB server version: REGEX(.*) +{ + "_id" : { + "id" : "urn:ngsi-ld:entity:E1", + "type" : "https://uri.etsi.org/ngsi-ld/default-context/Device", + "servicePath" : "/" + }, + "attrNames" : [ + "location", + "observationSpace", + "operationSpace", + "https://uri.etsi.org/ngsi-ld/default-context/weight", + "https://uri.etsi.org/ngsi-ld/default-context/owner" + ], + "attrs" : { + "location" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 11, + 12 + ] + }, + "mdNames" : [ ] + }, + "observationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 11, + 13 + ] + }, + "mdNames" : [ ] + }, + "operationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 11, + 14 + ] + }, + "mdNames" : [ ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/weight" : { + "type" : "Property", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : 100, + "md" : { + "unitCode" : { + "value" : "kg" + }, + "observedAt" : { + "value" : 1615105860.123 + } + }, + "mdNames" : [ + "unitCode", + "observedAt" + ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/owner" : { + "type" : "Relationship", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : "urn:ngsi-ld:owner:1", + "md" : { + "observedAt" : { + "value" : 1615105920.123 + } + }, + "mdNames" : [ + "observedAt" + ] + } + }, + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "lastCorrelator" : "" +} +bye + + +02. PATCH E1, all 7 attributes - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +================================================================================================================= +HTTP/1.1 207 Multi-Status +Content-Length: 453 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace", + "weight", + "owner" + ] +} + + +02b. See the entity E1 in mongo +=============================== +MongoDB shell version REGEX(.*) +connecting to: REGEX(.*) +MongoDB server version: REGEX(.*) +{ + "_id" : { + "id" : "urn:ngsi-ld:entity:E1", + "type" : "https://uri.etsi.org/ngsi-ld/default-context/Device", + "servicePath" : "/" + }, + "attrNames" : [ + "location", + "observationSpace", + "operationSpace", + "https://uri.etsi.org/ngsi-ld/default-context/weight", + "https://uri.etsi.org/ngsi-ld/default-context/owner" + ], + "attrs" : { + "location" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 21, + 22 + ] + }, + "mdNames" : [ ] + }, + "observationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 21, + 23 + ] + }, + "mdNames" : [ ] + }, + "operationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 21, + 24 + ] + }, + "mdNames" : [ ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/weight" : { + "type" : "Property", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : 200, + "md" : { + "unitCode" : { + "value" : "kg" + }, + "observedAt" : { + "value" : 1615372260.123 + } + }, + "mdNames" : [ + "unitCode", + "observedAt" + ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/owner" : { + "type" : "Relationship", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : "urn:ngsi-ld:owner:2", + "md" : { + "observedAt" : { + "value" : 1615372320.123 + } + }, + "mdNames" : [ + "observedAt" + ] + } + }, + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "lastCorrelator" : "" +} +bye + + +03. GET E1 - make sure step 02 replaced the attributes +======================================================= +HTTP/1.1 200 OK +Content-Length: 503 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 21, + 22 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 21, + 23 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 21, + 24 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:2", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 200 + } +} + + +04. PATCH E1, all 7 attributes, and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +===================================================================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +04b. See the entity E1 in mongo +=============================== +MongoDB shell version REGEX(.*) +connecting to: REGEX(.*) +MongoDB server version: REGEX(.*) +{ + "_id" : { + "id" : "urn:ngsi-ld:entity:E1", + "type" : "https://uri.etsi.org/ngsi-ld/default-context/Device", + "servicePath" : "/" + }, + "attrNames" : [ + "https://uri.etsi.org/ngsi-ld/default-context/weight", + "https://uri.etsi.org/ngsi-ld/default-context/owner", + "location", + "observationSpace", + "operationSpace" + ], + "attrs" : { + "https://uri=etsi=org/ngsi-ld/default-context/weight" : { + "type" : "Property", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : 200, + "md" : { + "unitCode" : { + "value" : "kg" + }, + "observedAt" : { + "value" : 1615372260.123 + } + }, + "mdNames" : [ + "unitCode", + "observedAt" + ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/owner" : { + "type" : "Relationship", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : "urn:ngsi-ld:owner:2", + "md" : { + "observedAt" : { + "value" : 1615372320.123 + } + }, + "mdNames" : [ + "observedAt" + ] + }, + "location" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 41, + 42 + ] + }, + "mdNames" : [ ] + }, + "observationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 41, + 43 + ] + }, + "mdNames" : [ ] + }, + "operationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 41, + 44 + ] + }, + "mdNames" : [ ] + } + }, + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "lastCorrelator" : "" +} +bye + + +05. GET E1 - make sure step 04 replaced 3 attributes and ignored the other four +================================================================================ +HTTP/1.1 200 OK +Content-Length: 503 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 41, + 42 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 41, + 43 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 41, + 44 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:2", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 200 + } +} + + +06. PATCH E1, all 7 attributes, and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +====================================================================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: REGEX(.*) +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +06b. See the entity E1 in mongo +=============================== +MongoDB shell version REGEX(.*) +connecting to: REGEX(.*) +MongoDB server version: REGEX(.*) +{ + "_id" : { + "id" : "urn:ngsi-ld:entity:E1", + "type" : "https://uri.etsi.org/ngsi-ld/default-context/Device", + "servicePath" : "/" + }, + "attrNames" : [ + "https://uri.etsi.org/ngsi-ld/default-context/weight", + "https://uri.etsi.org/ngsi-ld/default-context/owner", + "location", + "observationSpace", + "operationSpace" + ], + "attrs" : { + "https://uri=etsi=org/ngsi-ld/default-context/weight" : { + "type" : "Property", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : 200, + "md" : { + "unitCode" : { + "value" : "kg" + }, + "observedAt" : { + "value" : 1615372260.123 + } + }, + "mdNames" : [ + "unitCode", + "observedAt" + ] + }, + "https://uri=etsi=org/ngsi-ld/default-context/owner" : { + "type" : "Relationship", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : "urn:ngsi-ld:owner:2", + "md" : { + "observedAt" : { + "value" : 1615372320.123 + } + }, + "mdNames" : [ + "observedAt" + ] + }, + "location" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 6.1, + 6.2 + ] + }, + "mdNames" : [ ] + }, + "observationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 6.1, + 6.3 + ] + }, + "mdNames" : [ ] + }, + "operationSpace" : { + "type" : "GeoProperty", + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "value" : { + "type" : "Point", + "coordinates" : [ + 6.1, + 6.4 + ] + }, + "mdNames" : [ ] + } + }, + "creDate" : REGEX(.*), + "modDate" : REGEX(.*), + "lastCorrelator" : "" +} +bye + + +07. GET E1 - make sure step 06 replaced 3 attributes and ignored the other four +================================================================================ +HTTP/1.1 200 OK +Content-Length: 509 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 6.1, + 6.2 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 6.1, + 6.3 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 6.1, + 6.4 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:2", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 200 + } +} + + +--TEARDOWN-- +brokerStop CB +dbDrop CB diff --git a/test/functionalTest/cases/0000_troe/troe_exhaustive_patch_attributes.test b/test/functionalTest/cases/0000_troe/troe_exhaustive_patch_attributes.test new file mode 100644 index 0000000000..0cd3735425 --- /dev/null +++ b/test/functionalTest/cases/0000_troe/troe_exhaustive_patch_attributes.test @@ -0,0 +1,1233 @@ +# Copyright 2021 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-- +Exhaustive test of patching attributes for an entity + +--SHELL-INIT-- +export BROKER=orionld +dbInit CB +dbInit CB t1 +pgInit $CB_DB_NAME +pgInit ${CB_DB_NAME}_t1 +brokerStart CB 100 IPv4 -troe -multiservice + +--SHELL-- + +# +# 01. Create E1 on default tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +# 02. Create E2 on T1 tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +# 03. Patch E1, all 7 attributes, on default tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +# 04. GET E1 on default tenant - make sure step 03 replaced the attributes +# 05. Patch E2, all 7 attributes, on T1 tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +# 06. GET E2 on T1 tenant - make sure step 05 replaced the attributes +# 07. Patch E1, all 7 attributes, on default tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 08. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four +# 09. Patch E2, all 7 attributes, on T1 tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 10. GET E2 on T1 tenant - make sure step 09 replaced 3 attributes and ignored the other four +# 11. Patch E1, all 7 attributes, on default tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 12. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four +# 13. Patch E2, all 7 attributes, on T1 tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +# 14. GET E2 on T1 tenant - make sure step 13 replaced 3 attributes and ignored the other four +# 15. See all entities in TRoE DB, default tenant +# 16. See all attributes in TRoE DB, default tenant +# 17. See all sub-attributes in TRoE DB, default tenant - there aren't any +# 18. See all entities in TRoE DB, tenant T1 +# 19. See all attributes in TRoE DB, tenant T1 +# 20. See all sub-attributes in TRoE DB, tenant T1 - there aren't any +# + +echo "01. Create E1 on default tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored)" +echo "==============================================================================================================================================" +payload='[ + { + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 4 ] + } + }, + "weight": { + "type": "Property", + "value": 250, + "unitCode": "kg", + "observedAt": "2021-03-07T08:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:1", + "observedAt": "2021-03-07T08:32:00.123Z" + } + } +]' +orionCurl --url /ngsi-ld/v1/entityOperations/create --payload "$payload" +echo +echo + + +echo "02. Create E2 on T1 tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored)" +echo "=========================================================================================================================================" +payload='[ + { + "id": "urn:ngsi-ld:entity:E2", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 1, 4 ] + } + }, + "weight": { + "type": "Property", + "value": 250, + "unitCode": "kg", + "observedAt": "2021-03-07T08:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:1", + "observedAt": "2021-03-07T08:32:00.123Z" + } + } +]' +orionCurl --url /ngsi-ld/v1/entityOperations/create --payload "$payload" --tenant t1 +echo +echo + + +echo "03. Patch E1, all 7 attributes, on default tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED" +echo "===================================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 31, 32 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 31, 33 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 31, 34 ] + } + }, + "weight": { + "type": "Property", + "value": 350, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:3", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH +echo +echo + + +echo "04. GET E1 on default tenant - make sure step 03 replaced the attributes" +echo "========================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +echo "05. Patch E2, all 7 attributes, on T1 tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED" +echo "==============================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E2", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 51, 52 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 51, 53 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 51, 54 ] + } + }, + "weight": { + "type": "Property", + "value": 550, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:5", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2/attrs --payload "$payload" -X PATCH --tenant t1 +echo +echo + + +echo "06. GET E2 on T1 tenant - make sure step 05 replaced the attributes" +echo "===================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2 --tenant t1 +echo +echo + + +echo "07. Patch E1, all 7 attributes, on default tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "======================================================================================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 71, 72 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 71, 73 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 71, 74 ] + } + }, + "weight": { + "type": "Property", + "value": 750, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:7", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH -H 'Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' +echo +echo + + +echo "08. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four" +echo "=================================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +echo "09. Patch E2, all 7 attributes, on T1 tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "=================================================================================================================================================================================" +payload='{ + "id": "urn:ngsi-ld:entity:E2", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 9.1, 9.2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 9.1, 9.3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 9.1, 9.4 ] + } + }, + "weight": { + "type": "Property", + "value": 950, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:9", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2/attrs --payload "$payload" -X PATCH --tenant t1 -H 'Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' +echo +echo + + +echo "10. GET E2 on T1 tenant - make sure step 09 replaced 3 attributes and ignored the other four" +echo "============================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2 --tenant t1 +echo +echo + + +echo "11. Patch E1, all 7 attributes, on default tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "=======================================================================================================================================================================================" +payload='{ + "@context": [ "https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld" ], + "id": "urn:ngsi-ld:entity:E1", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11.1, 11.2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11.1, 11.3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 11.1, 11.4 ] + } + }, + "weight": { + "type": "Property", + "value": 1150, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:11", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1/attrs --payload "$payload" -X PATCH --in application/ld+json +echo +echo + + +echo "12. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four" +echo "=================================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E1 +echo +echo + + +echo "13. Patch E2, all 7 attributes, on T1 tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED" +echo "==================================================================================================================================================================================" +payload='{ + "@context": "https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld", + "id": "urn:ngsi-ld:entity:E2", + "type": "Device", + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 13.1, 13.2 ] + } + }, + "createdAt": "2021-03-07T08:30:00.123Z", + "modifiedAt": "2021-03-07T08:30:00.123Z", + "observationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 13.1, 13.3 ] + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ 13.1, 13.4 ] + } + }, + "weight": { + "type": "Property", + "value": 1350, + "unitCode": "kg", + "observedAt": "2021-03-10T10:31:00.123Z" + }, + "owner": { + "type": "Relationship", + "object": "urn:ngsi-ld:owner:13", + "observedAt": "2021-03-10T10:32:00.123Z" + }, + "noSuchAttr": { + "type": "Property", + "value": "Error in 207 response" + } +}' +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2/attrs --payload "$payload" -X PATCH --tenant t1 --in application/ld+json +echo +echo + + +echo "14. GET E2 on T1 tenant - make sure step 13 replaced 3 attributes and ignored the other four" +echo "============================================================================================" +orionCurl --url /ngsi-ld/v1/entities/urn:ngsi-ld:entity:E2 --tenant t1 +echo +echo + + +echo "15. See all entities in TRoE DB, default tenant" +echo "===============================================" +postgresCmd -sql "SELECT opMode,id,type,ts FROM entities" +echo +echo + + +echo "16. See all attributes in TRoE DB, default tenant" +echo "=================================================" +postgresCmd -sql "SELECT opMode,id,valueType,entityId,subProperties,unitcode,datasetid,text,number,boolean,observedAt,ts FROM attributes" +echo +echo + + +echo "17. See all sub-attributes in TRoE DB, default tenant - there aren't any" +echo "========================================================================" +postgresCmd -sql "SELECT id,valueType,entityId,attrInstanceId,unitcode,text,number,boolean FROM subAttributes" +echo +echo + + +echo "18. See all entities in TRoE DB, tenant T1" +echo "==========================================" +postgresCmd -sql "SELECT opMode,id,type,ts FROM entities" -t ftest_t1 +echo +echo + + +echo "19. See all attributes in TRoE DB, tenant T1" +echo "============================================" +postgresCmd -sql "SELECT opMode,id,valueType,entityId,subProperties,unitcode,datasetid,text,number,boolean,observedAt,ts FROM attributes" -t ftest_t1 +echo +echo + + +echo "20. See all sub-attributes in TRoE DB, tenant T1 - there aren't any" +echo "===================================================================" +postgresCmd -sql "SELECT id,valueType,entityId,attrInstanceId,unitcode,text,number,boolean FROM subAttributes" +echo +echo + + +--REGEXPECT-- +01. Create E1 on default tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +============================================================================================================================================== +HTTP/1.1 200 OK +Content-Length: 49 +Content-Type: application/json +Date: REGEX(.*) + +{ + "errors": [], + "success": [ + "urn:ngsi-ld:entity:E1" + ] +} + + +02. Create E2 on T1 tenant, with attrs location, observationSpace, operationSpace, weight, owner (and createdAt+modifiedAt to be ignored) +========================================================================================================================================= +HTTP/1.1 200 OK +Content-Length: 49 +Content-Type: application/json +Date: REGEX(.*) + +{ + "errors": [], + "success": [ + "urn:ngsi-ld:entity:E2" + ] +} + + +03. Patch E1, all 7 attributes, on default tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +=================================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 453 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace", + "weight", + "owner" + ] +} + + +04. GET E1 on default tenant - make sure step 03 replaced the attributes +======================================================================== +HTTP/1.1 200 OK +Content-Length: 503 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 31, + 32 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 31, + 33 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 31, + 34 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:3", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 350 + } +} + + +05. Patch E2, all 7 attributes, on T1 tenant - make sure createdAt+modifiedAt are ignored and that the other five are REPLACED +============================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 453 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace", + "weight", + "owner" + ] +} + + +06. GET E2 on T1 tenant - make sure step 05 replaced the attributes +=================================================================== +HTTP/1.1 200 OK +Content-Length: 503 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E2", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 51, + 52 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 51, + 53 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 51, + 54 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:5", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 550 + } +} + + +07. Patch E1, all 7 attributes, on default tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +====================================================================================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +08. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four +================================================================================================= +HTTP/1.1 200 OK +Content-Length: 503 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 71, + 72 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 71, + 73 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 71, + 74 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:3", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 350 + } +} + + +09. Patch E2, all 7 attributes, on T1 tenant and with user context in Link header - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +================================================================================================================================================================================= +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +10. GET E2 on T1 tenant - make sure step 09 replaced 3 attributes and ignored the other four +============================================================================================ +HTTP/1.1 200 OK +Content-Length: 509 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E2", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 9.1, + 9.2 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 9.1, + 9.3 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 9.1, + 9.4 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:5", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 550 + } +} + + +11. Patch E1, all 7 attributes, on default tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +======================================================================================================================================================================================= +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: REGEX(.*) +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +12. GET E1 on default tenant - make sure step 07 replaced 3 attributes and ignored the other four +================================================================================================= +HTTP/1.1 200 OK +Content-Length: 515 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E1", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 11.1, + 11.2 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 11.1, + 11.3 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 11.1, + 11.4 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:3", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 350 + } +} + + +13. Patch E2, all 7 attributes, on T1 tenant and with user context in payload body - make sure createdAt+modifiedAt+weight+owner are ignored and that the other three are REPLACED +================================================================================================================================================================================== +HTTP/1.1 207 Multi-Status +Content-Length: 559 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "notUpdated": [ + { + "attributeName": "id", + "reason": "the ID of an entity cannot be altered" + }, + { + "attributeName": "type", + "reason": "the TYPE of an entity cannot be altered" + }, + { + "attributeName": "createdAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "modifiedAt", + "reason": "built-in timestamps are ignored" + }, + { + "attributeName": "weight", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "owner", + "reason": "attribute doesn't exist" + }, + { + "attributeName": "noSuchAttr", + "reason": "attribute doesn't exist" + } + ], + "updated": [ + "location", + "observationSpace", + "operationSpace" + ] +} + + +14. GET E2 on T1 tenant - make sure step 13 replaced 3 attributes and ignored the other four +============================================================================================ +HTTP/1.1 200 OK +Content-Length: 515 +Content-Type: application/json +Link: ; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json" +Date: REGEX(.*) + +{ + "id": "urn:ngsi-ld:entity:E2", + "location": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 13.1, + 13.2 + ], + "type": "Point" + } + }, + "observationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 13.1, + 13.3 + ], + "type": "Point" + } + }, + "operationSpace": { + "type": "GeoProperty", + "value": { + "coordinates": [ + 13.1, + 13.4 + ], + "type": "Point" + } + }, + "owner": { + "object": "urn:ngsi-ld:owner:5", + "observedAt": "2021-03-10T10:32:00.123Z", + "type": "Relationship" + }, + "type": "Device", + "weight": { + "observedAt": "2021-03-10T10:31:00.123Z", + "type": "Property", + "unitCode": "kg", + "value": 550 + } +} + + +15. See all entities in TRoE DB, default tenant +=============================================== +opmode,id,type,ts +Create,urn:ngsi-ld:entity:E1,https://uri.etsi.org/ngsi-ld/default-context/Device,202REGEX(.*) + + +16. See all attributes in TRoE DB, default tenant +================================================= +opmode,id,valuetype,entityid,subproperties,unitcode,datasetid,text,number,boolean,observedat,ts +Create,location,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Create,observationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Create,operationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Create,https://uri.etsi.org/ngsi-ld/default-context/weight,Number,urn:ngsi-ld:entity:E1,f,kg,,,250,,2021-03-07 08:31:00.123,202REGEX(.*) +Create,https://uri.etsi.org/ngsi-ld/default-context/owner,Relationship,urn:ngsi-ld:entity:E1,f,,,urn:ngsi-ld:owner:1,,,2021-03-07 08:32:00.123,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,https://uri.etsi.org/ngsi-ld/default-context/weight,Number,urn:ngsi-ld:entity:E1,f,kg,,,350,,2021-03-10 10:31:00.123,202REGEX(.*) +Replace,https://uri.etsi.org/ngsi-ld/default-context/owner,Relationship,urn:ngsi-ld:entity:E1,f,,,urn:ngsi-ld:owner:3,,,2021-03-10 10:32:00.123,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E1,f,,,,,,,202REGEX(.*) + + +17. See all sub-attributes in TRoE DB, default tenant - there aren't any +======================================================================== +id,valuetype,entityid,attrinstanceid,unitcode,text,number,boolean + + +18. See all entities in TRoE DB, tenant T1 +========================================== +opmode,id,type,ts +Create,urn:ngsi-ld:entity:E2,https://uri.etsi.org/ngsi-ld/default-context/Device,202REGEX(.*) + + +19. See all attributes in TRoE DB, tenant T1 +============================================ +opmode,id,valuetype,entityid,subproperties,unitcode,datasetid,text,number,boolean,observedat,ts +Create,location,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Create,observationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Create,operationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Create,https://uri.etsi.org/ngsi-ld/default-context/weight,Number,urn:ngsi-ld:entity:E2,f,kg,,,250,,2021-03-07 08:31:00.123,202REGEX(.*) +Create,https://uri.etsi.org/ngsi-ld/default-context/owner,Relationship,urn:ngsi-ld:entity:E2,f,,,urn:ngsi-ld:owner:1,,,2021-03-07 08:32:00.123,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,https://uri.etsi.org/ngsi-ld/default-context/weight,Number,urn:ngsi-ld:entity:E2,f,kg,,,550,,2021-03-10 10:31:00.123,202REGEX(.*) +Replace,https://uri.etsi.org/ngsi-ld/default-context/owner,Relationship,urn:ngsi-ld:entity:E2,f,,,urn:ngsi-ld:owner:5,,,2021-03-10 10:32:00.123,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,location,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,observationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) +Replace,operationSpace,GeoPoint,urn:ngsi-ld:entity:E2,f,,,,,,,202REGEX(.*) + + +20. See all sub-attributes in TRoE DB, tenant T1 - there aren't any +=================================================================== +id,valuetype,entityid,attrinstanceid,unitcode,text,number,boolean + + +--TEARDOWN-- +brokerStop CB +#dbDrop CB +#dbDrop CB t1 +pgDrop $CB_DB_NAME +pgDrop ${CB_DB_NAME}_t1