forked from telefonicaid/fiware-orion
-
Notifications
You must be signed in to change notification settings - Fork 43
/
ngsild_batch_upsert-options=replace.test
391 lines (347 loc) · 10.9 KB
/
ngsild_batch_upsert-options=replace.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# 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--
Entity Creation and Retrieval
--SHELL-INIT--
export BROKER=orionld
dbInit CB
brokerStart CB 0-255
--SHELL--
#
# 01. Create entities E1 and E2 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace
# 02. See the two entities in mongo
# 03. T3: Extract creDate and modDate of E1 and E2 from mongo (E1_T3_creDate, E1_T3_modDate, E2_T3_creDate, E2_T3_modDate)
# 04. Sleep 3 secs - to force E2::creDate to be 3 secs older than E2::modDate after step 05
# 05. Modify E2 and add E3 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace
# 06. T6: Extract creDate and modDate of E1, E2 and E3 from mongo
# 07. Make sure all creDate/modDates are correct
# 08. See E1-E3 in mongo. E1::P2: STEP 01, E2/E3::P2: STEP 05
#
echo "01. Create entities E1 and E2 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace"
echo "============================================================================================"
payload='[
{
"id": "urn:ngsi-ld:entity:E1",
"type": "Vehicle",
"P1": {
"type": "Property",
"value": "STEP 01"
}
},
{
"id": "urn:ngsi-ld:entity:E2",
"type": "Vehicle",
"P1": {
"type": "Property",
"value": "STEP 01"
}
}
]'
orionCurl --url "/ngsi-ld/v1/entityOperations/upsert?options=replace" -X POST --payload "$payload"
echo
echo
echo "02. See the two entities in mongo"
echo "================================="
mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})'
mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})'
echo
echo
echo "03. T3: Extract creDate and modDate of E1 and E2 from mongo (E1_T3_creDate, E1_T3_modDate, E2_T3_creDate, E2_T3_modDate)"
echo "========================================================================================================================"
E1_T3_creDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' | grep '^ "creDate"')
E1_T3_modDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' | grep '^ "modDate"')
E2_T3_creDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})' | grep '^ "creDate"')
E2_T3_modDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})' | grep '^ "modDate"')
echo $E1_T3_creDate
echo $E1_T3_modDate
echo $E2_T3_creDate
echo $E2_T3_modDate
echo
echo
#
# Sleep 3 secs to provoke a modDate different from creDate - creDate should stay intact in step 05
#
echo "04. Sleep 3 secs - to force E2::creDate to be 3 secs older than E2::modDate after step 05"
echo "========================================================================================="
sleep 3
echo Slept 3 seconds
echo
echo
echo "05. Modify E2 and add E3 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace"
echo "======================================================================================="
payload='[
{
"id": "urn:ngsi-ld:entity:E2",
"type": "Vehicle",
"P2": {
"type": "Property",
"value": "STEP 05"
}
},
{
"id": "urn:ngsi-ld:entity:E3",
"type": "Vehicle",
"P2": {
"type": "Property",
"value": "STEP 05"
}
}
]'
orionCurl --url "/ngsi-ld/v1/entityOperations/upsert?options=replace" -X POST --payload "$payload"
echo
echo
echo "06. T6: Extract creDate and modDate of E1, E2 and E3 from mongo"
echo "==============================================================="
E1_T6_creDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' | grep '^ "creDate"')
E1_T6_modDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})' | grep '^ "modDate"')
E2_T6_creDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})' | grep '^ "creDate"')
E2_T6_modDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})' | grep '^ "modDate"')
E3_T6_creDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E3"})' | grep '^ "creDate"')
E3_T6_modDate=$(mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E3"})' | grep '^ "modDate"')
echo E1: $E1_T6_creDate
echo E1: $E1_T6_modDate
echo E2: $E2_T6_creDate
echo E2: $E2_T6_modDate
echo E3: $E3_T6_creDate
echo E3: $E3_T6_modDate
echo
echo
echo "07. Make sure all creDate/modDates are correct"
echo "=============================================="
if [ "$E1_T6_creDate" != "$E1_T3_creDate" ]
then
echo "E1::creDate has changed!!"
else
echo "E1::creDate is OK"
fi
if [ "$E1_T6_modDate" != "$E1_T3_modDate" ]
then
echo "E1::modDate has changed without the entity being updated!!"
else
echo "E1::modDate is OK"
fi
if [ "$E2_T6_creDate" != "$E2_T3_creDate" ]
then
echo "E2::creDate has changed!!!"
echo $E2_T3_creDate
echo $E2_T6_creDate
else
echo "E2::creDate is OK"
fi
if [ "$E2_T6_modDate" == "$E2_T3_modDate" ]
then
echo "E2::modDate has NOT changed!!!"
else
echo "E2::modDate is OK"
fi
echo
echo
echo "08. See E1-E3 in mongo. E1::P2: STEP 01, E2/E3::P2: STEP 05"
echo "==========================================================="
mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E1"})'
mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E2"})'
mongoCmd2 ftest 'db.entities.findOne({"_id.id": "urn:ngsi-ld:entity:E3"})'
echo
echo
--REGEXPECT--
01. Create entities E1 and E2 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace
============================================================================================
HTTP/1.1 201 Created
Content-Length: 49
Content-Type: application/json
Date: REGEX(.*)
[
"urn:ngsi-ld:entity:E1",
"urn:ngsi-ld:entity:E2"
]
02. See the two entities 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/Vehicle",
"servicePath" : "/"
},
"attrNames" : [
"https://uri.etsi.org/ngsi-ld/default-context/P1"
],
"attrs" : {
"https://uri=etsi=org/ngsi-ld/default-context/P1" : {
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "STEP 01",
"mdNames" : [ ]
}
},
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"lastCorrelator" : ""
}
bye
MongoDB shell version REGEX(.*)
connecting to: REGEX(.*)
MongoDB server version: REGEX(.*)
{
"_id" : {
"id" : "urn:ngsi-ld:entity:E2",
"type" : "https://uri.etsi.org/ngsi-ld/default-context/Vehicle",
"servicePath" : "/"
},
"attrNames" : [
"https://uri.etsi.org/ngsi-ld/default-context/P1"
],
"attrs" : {
"https://uri=etsi=org/ngsi-ld/default-context/P1" : {
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "STEP 01",
"mdNames" : [ ]
}
},
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"lastCorrelator" : ""
}
bye
03. T3: Extract creDate and modDate of E1 and E2 from mongo (E1_T3_creDate, E1_T3_modDate, E2_T3_creDate, E2_T3_modDate)
========================================================================================================================
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
04. Sleep 3 secs - to force E2::creDate to be 3 secs older than E2::modDate after step 05
=========================================================================================
Slept 3 seconds
05. Modify E2 and add E3 using POST /ngsi-ld/v1/entityOperations/upsert?options=replace
=======================================================================================
HTTP/1.1 207 Multi-Status
Content-Length: 73
Content-Type: application/json
Date: REGEX(.*)
{
"errors": [],
"success": [
"urn:ngsi-ld:entity:E2",
"urn:ngsi-ld:entity:E3"
]
}
06. T6: Extract creDate and modDate of E1, E2 and E3 from mongo
===============================================================
E1: "creDate" : REGEX(.*),
E1: "modDate" : REGEX(.*),
E2: "creDate" : REGEX(.*),
E2: "modDate" : REGEX(.*),
E3: "creDate" : REGEX(.*),
E3: "modDate" : REGEX(.*),
07. Make sure all creDate/modDates are correct
==============================================
E1::creDate is OK
E1::modDate is OK
E2::creDate is OK
E2::modDate is OK
08. See E1-E3 in mongo. E1::P2: STEP 01, E2/E3::P2: STEP 05
===========================================================
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/Vehicle",
"servicePath" : "/"
},
"attrNames" : [
"https://uri.etsi.org/ngsi-ld/default-context/P1"
],
"attrs" : {
"https://uri=etsi=org/ngsi-ld/default-context/P1" : {
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "STEP 01",
"mdNames" : [ ]
}
},
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"lastCorrelator" : ""
}
bye
MongoDB shell version REGEX(.*)
connecting to: REGEX(.*)
MongoDB server version: REGEX(.*)
{
"_id" : {
"id" : "urn:ngsi-ld:entity:E2",
"type" : "https://uri.etsi.org/ngsi-ld/default-context/Vehicle",
"servicePath" : "/"
},
"attrNames" : [
"https://uri.etsi.org/ngsi-ld/default-context/P2"
],
"attrs" : {
"https://uri=etsi=org/ngsi-ld/default-context/P2" : {
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "STEP 05",
"mdNames" : [ ]
}
},
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"lastCorrelator" : ""
}
bye
MongoDB shell version REGEX(.*)
connecting to: REGEX(.*)
MongoDB server version: REGEX(.*)
{
"_id" : {
"id" : "urn:ngsi-ld:entity:E3",
"type" : "https://uri.etsi.org/ngsi-ld/default-context/Vehicle",
"servicePath" : "/"
},
"attrNames" : [
"https://uri.etsi.org/ngsi-ld/default-context/P2"
],
"attrs" : {
"https://uri=etsi=org/ngsi-ld/default-context/P2" : {
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "STEP 05",
"mdNames" : [ ]
}
},
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"lastCorrelator" : ""
}
bye
--TEARDOWN--
brokerStop CB
dbDrop CB