Skip to content

Commit

Permalink
Merge pull request #513 from FIWARE/bug/issue507
Browse files Browse the repository at this point in the history
Fixed issue #507
  • Loading branch information
kzangeli authored Sep 2, 2020
2 parents ba1574d + 8ce573e commit 5247f6e
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* Issue #280 createdAt and modifiedAt for registrations were returned as integers - now as ISO8601 strings (with milliseconds)
* Issue #280 Returning 501 Not Implemented if timeInterval is used for subscriptions
* Issue #430 Accepting "?options=count" as well as "?count=true" in NGSI-LD queries, for backwards compatibility
* Issue #507 Core context instead of the one in the Link header used in Batch Update
6 changes: 3 additions & 3 deletions src/lib/orionld/serviceRoutines/orionldPostBatchCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C"
#include "orionld/rest/orionldServiceInit.h" // orionldHostName, orionldHostNameLen
#include "orionld/common/orionldErrorResponse.h" // orionldErrorResponseCreate
#include "orionld/common/SCOMPARE.h" // SCOMPAREx
#include "orionld/common/CHECK.h" // ARRAY_CHECK
#include "orionld/common/urlCheck.h" // urlCheck
#include "orionld/common/urnCheck.h" // urnCheck
#include "orionld/common/orionldState.h" // orionldState
Expand All @@ -59,7 +60,6 @@ extern "C"
#include "orionld/common/entityLookupById.h" // entityLookupById
#include "orionld/common/removeArrayEntityLookup.h" // removeArrayEntityLookup
#include "orionld/common/typeCheckForNonExistingEntities.h" // typeCheckForNonExistingEntities
#include "orionld/payloadCheck/pcheckEntityInfoArray.h" // pcheckEntityInfoArray
#include "orionld/context/orionldCoreContext.h" // orionldDefaultUrl, orionldCoreContext
#include "orionld/context/orionldContextPresent.h" // orionldContextPresent
#include "orionld/context/orionldContextItemAliasLookup.h" // orionldContextItemAliasLookup
Expand Down Expand Up @@ -129,7 +129,8 @@ bool orionldPostBatchCreate(ConnectionInfo* ciP)
// * all entities must contain an entity::id (one level down)
// * no entity can contain an entity::type (one level down)
//
pcheckEntityInfoArray(orionldState.requestTree, true); // FIXME: This is not the correct check!
ARRAY_CHECK(orionldState.requestTree, "incoming payload body");
EMPTY_ARRAY_CHECK(orionldState.requestTree, "incoming payload body");

KjNode* incomingTree = orionldState.requestTree;
KjNode* idArray = kjArray(orionldState.kjsonP, NULL);
Expand Down Expand Up @@ -157,7 +158,6 @@ bool orionldPostBatchCreate(ConnectionInfo* ciP)

entityP = next;
}

//
// 02. Query database extracting three fields: { id, type and creDate } for each of the entities
// whose Entity::Id is part of the array "idArray".
Expand Down
2 changes: 2 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldPostBatchUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ bool orionldPostBatchUpdate(ConnectionInfo* ciP)

if (contextNodeP != NULL)
contextP = orionldContextFromTree(NULL, false, contextNodeP, &pd);
else if (orionldState.contextP != NULL)
contextP = orionldState.contextP;
else
contextP = orionldCoreContextP;

Expand Down
213 changes: 213 additions & 0 deletions test/functionalTest/cases/0000_ngsild/ngsild_issue_0507.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# Copyright 2019 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--
Issue 507

--SHELL-INIT--
export BROKER=orionld
dbInit CB
brokerStart CB 0-255

--SHELL--

#
# 01. Create three entities
# 02. Update two of them using batch update
# 03. Get the entities
# 04. Update two of them using batch upsert
# 05. Get the entities

echo "01. Create three entities"
echo "========================="
payload='[
{
"id": "urn:ngsi-ld:TemperatureSensor:002",
"type": "TemperatureSensor",
"category": {
"type": "Property",
"value": "sensor"
},
"temperature": {
"type": "Property",
"value": 20,
"unitCode": "CEL"
}
},
{
"id": "urn:ngsi-ld:TemperatureSensor:003",
"type": "TemperatureSensor",
"category": {
"type": "Property",
"value": "sensor"
},
"temperature": {
"type": "Property",
"value": 2,
"unitCode": "CEL"
}
},
{
"id": "urn:ngsi-ld:TemperatureSensor:004",
"type": "TemperatureSensor",
"category": {
"type": "Property",
"value": "sensor"
},
"temperature": {
"type": "Property",
"value": 100,
"unitCode": "CEL"
}
}
]'
orionCurl --url /ngsi-ld/v1/entityOperations/create --payload "$payload" -H 'Link: <https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' -H 'Cookie: _csrf=MAPTGFPcoPnewsGCWklHi4Mq'
echo
echo


echo "02. Update two of them using batch update"
echo "========================================="
payload='[
{
"id": "urn:ngsi-ld:TemperatureSensor:003",
"type": "https://uri.fiware.org/ns/data-models#TemperatureSensor",
"category": {
"type": "Property",
"value": [
"actuator",
"sensor"
]
}
},
{
"id": "urn:ngsi-ld:TemperatureSensor:004",
"type": "TemperatureSensor",
"temperature": {
"type": "Property",
"value": [
"actuator",
"sensor"
]
}
}
]'
orionCurl --url /ngsi-ld/v1/entityOperations/update?options=replace --payload "$payload" -H 'Link: <https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' -H 'Cookie: _csrf=MAPTGFPcoPnewsGCWklHi4Mq'
echo
echo



echo "03. Get the entities"
echo "===================="
orionCurl --url '/ngsi-ld/v1/entities?type=TemperatureSensor' -H 'Link: <https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' -H 'Cookie: _csrf=MAPTGFPcoPnewsGCWklHi4Mq'
echo
echo


--REGEXPECT--
01. Create three entities
=========================
HTTP/1.1 200 OK
Content-Length: 133
Content-Type: application/json
Link: <https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)

{
"errors": [],
"success": [
"urn:ngsi-ld:TemperatureSensor:002",
"urn:ngsi-ld:TemperatureSensor:003",
"urn:ngsi-ld:TemperatureSensor:004"
]
}


02. Update two of them using batch update
=========================================
HTTP/1.1 204 No Content
Content-Length: 0
Date: REGEX(.*)



03. Get the entities
====================
HTTP/1.1 200 OK
Content-Length: 572
Content-Type: application/json
Link: <https://raw.githubusercontent.com/FIWARE/tutorials.NGSI-LD/master/app/public/data-models/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)

[
{
"category": {
"type": "Property",
"value": "sensor"
},
"id": "urn:ngsi-ld:TemperatureSensor:002",
"temperature": {
"type": "Property",
"unitCode": "CEL",
"value": 20
},
"type": "TemperatureSensor"
},
{
"category": {
"type": "Property",
"value": [
"actuator",
"sensor"
]
},
"id": "urn:ngsi-ld:TemperatureSensor:003",
"temperature": {
"type": "Property",
"unitCode": "CEL",
"value": 2
},
"type": "TemperatureSensor"
},
{
"category": {
"type": "Property",
"value": "sensor"
},
"id": "urn:ngsi-ld:TemperatureSensor:004",
"temperature": {
"type": "Property",
"unitCode": "CEL",
"value": [
"actuator",
"sensor"
]
},
"type": "TemperatureSensor"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit 5247f6e

Please sign in to comment.