Skip to content

Commit

Permalink
Merge pull request #4627 from telefonicaid/hardening/improve-push-exa…
Browse files Browse the repository at this point in the history
…mples

FIX add new push cases in doc and test
  • Loading branch information
mrutid authored Oct 23, 2024
2 parents b839b9f + 8096eef commit b24ecae
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
25 changes: 25 additions & 0 deletions doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,31 @@ PUT /v2/entities/E/attrs/A

would change the value of attribute A to `[1, 2, 3, 3]`

If after the previous result the following request is done:

```
PUT /v2/entities/E/attrs/A
{
"value": { "$push": { "$each": [4, 5]} },
"type": "Array"
}
```

would change the value of attribute A to `[1, 2, 3, 3, 4, 5]`.

If after the previous result the following request is done:

```
PUT /v2/entities/E/attrs/A
{
"value": { "$push": { "$each": [ -1, 0 ], "$position": 0} },
"type": "Array"
}
```

would change the value of attribute A to `[-1, 0, 1, 2, 3, 3, 4, 5]`


#### `$addToSet`

Similar to push but avoids duplications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ accumulatorStart --pretty-print
# 02. Create sub for entity E
# 03. Update A with $push: $each: [2, 3, 4]
# 04. Get entity, see E-A=[1,2,3,4]
# 05. Dump accumulator, see E-A=[1,2,3,4]
# 05. Update A with $push: $each: [-1, 0], $position: 0
# 06. Get entity, see E-A=[-1,0,1,2,3,4]
# 07. Dump accumulator, see E-A=[1,2,3,4] and E-A=[-1,0,1,2,3,4]
#


Expand Down Expand Up @@ -96,8 +98,28 @@ echo
echo


echo '05. Dump accumulator, see E-A=[1,2,3,4]'
echo '======================================='
echo '05. Update A with $push: $each: [-1, 0], $position: 0'
echo '====================================================='
payload='{
"A": {
"value": { "$push": { "$each": [-1, 0], "$position": 0} },
"type": "StructuredValue"
}
}'
orionCurl --url /v2/entities/E/attrs --payload "$payload"
echo
echo


echo '06. Get entity, see E-A=[-1,0,1,2,3,4]'
echo '======================================'
orionCurl --url /v2/entities/E
echo
echo


echo '07. Dump accumulator, see E-A=[1,2,3,4] and E-A=[-1,0,1,2,3,4]'
echo '=============================================================='
accumulatorDump
echo
echo
Expand Down Expand Up @@ -156,8 +178,42 @@ Content-Length: 84
}


05. Dump accumulator, see E-A=[1,2,3,4]
=======================================
05. Update A with $push: $each: [-1, 0], $position: 0
=====================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})



06. Get entity, see E-A=[-1,0,1,2,3,4]
======================================
HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 89

{
"A": {
"metadata": {},
"type": "StructuredValue",
"value": [
-1,
0,
1,
2,
3,
4
]
},
"id": "E",
"type": "T"
}


07. Dump accumulator, see E-A=[1,2,3,4] and E-A=[-1,0,1,2,3,4]
==============================================================
POST http://localhost:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 139
Expand Down Expand Up @@ -188,6 +244,38 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1
"subscriptionId": "REGEX([0-9a-f\-]{24})"
}
=======================================
POST http://localhost:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 144
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
Ngsiv2-Attrsformat: normalized
Host: localhost:REGEX(\d+)
Accept: application/json
Content-Type: application/json; charset=utf-8
Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1

{
"data": [
{
"A": {
"metadata": {},
"type": "StructuredValue",
"value": [
-1,
0,
1,
2,
3,
4
]
},
"id": "E",
"type": "T"
}
],
"subscriptionId": "REGEX([0-9a-f\-]{24})"
}
=======================================


--TEARDOWN--
Expand Down

0 comments on commit b24ecae

Please sign in to comment.