Skip to content

Commit

Permalink
Merge pull request #250 from kuzzleio/2-dev
Browse files Browse the repository at this point in the history
## 2.0.0-rc38

 - [breaking] Change the measures property in API and data model to be more intuitive #246 
 - Add asset historization #247 
 - [breaking] Remove Measures controller pushAsset action #248
  • Loading branch information
Aschen committed Jan 3, 2023
2 parents 6e446ad + 968288d commit fed1032
Show file tree
Hide file tree
Showing 56 changed files with 1,232 additions and 695 deletions.
75 changes: 16 additions & 59 deletions features/Asset/Controller.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ Feature: Asset Controller
| body.reference | "A1" |
| body.metadata.height | 5 |
Then The document "engine-kuzzle":"assets":"Container-A1" content match:
| metadata.height | 5 |
| metadata.weight | null |
| measures.temperatureExt.type | "temperature" |
| measures.temperatureInt.type | "temperature" |
| measures.position.type | "position" |
| linkedDevices | [] |
| metadata.height | 5 |
| metadata.weight | null |
| measures.temperatureExt | null |
| measures.temperatureInt | null |
| measures.position | null |
| linkedDevices | [] |
| _kuzzle_info.author | "-1" |
# Update metadata
When I successfully execute the action "device-manager/assets":"update" with args:
| engineId | "engine-kuzzle" |
| _id | "Container-A1" |
| body.metadata.weight | 1250 |
Then The document "engine-kuzzle":"assets":"Container-A1" content match:
| metadata.height | 5 |
| metadata.weight | 1250 |
| metadata.height | 5 |
| metadata.weight | 1250 |
| _kuzzle_info.updater | "-1" |
# Get
When I successfully execute the action "device-manager/assets":"get" with args:
| engineId | "engine-kuzzle" |
Expand All @@ -42,11 +45,11 @@ Feature: Asset Controller
Then I should receive a "hits" array of objects matching:
| _id |
| "Container-A1" |
# Delete
When I successfully execute the action "device-manager/assets":"delete" with args:
| engineId | "engine-kuzzle" |
| _id | "Container-A1" |
Then The document "engine-kuzzle":"assets":"Container-A1" does not exists
# Delete
When I successfully execute the action "device-manager/assets":"delete" with args:
| engineId | "engine-kuzzle" |
| _id | "Container-A1" |
Then The document "engine-kuzzle":"assets":"Container-A1" does not exists

Scenario: Error when creating Asset from unknown model
When I execute the action "device-manager/assets":"create" with args:
Expand Down Expand Up @@ -81,49 +84,3 @@ Feature: Asset Controller
| _source.values.temperature | _source.asset._id | _source.origin._id | _source.asset.model |
| 40 | "Container-linked1" | "DummyTemp-linked1" | "Container" |
| 41 | "Container-linked1" | "DummyTemp-linked1" | "Container" |

Scenario: Push a measures in the asset, an other with different name and an older one
When I successfully execute the action "device-manager/measures":"push" with args:
| engineId | "engine-ayse" |
| body.assetId | "Container-unlinked1" |
| body.measure.type | "temperature" |
| body.measure.values.temperature | 26 |
| body.measure.type | "temperature" |
| body.measure.name | "temperatureExt" |
Then The document "engine-ayse":"assets":"Container-unlinked1" content match:
| measures.temperatureExt.type | "temperature" |
| measures.temperatureExt.values.temperature | 26 |
When I successfully execute the action "device-manager/measures":"push" with args:
| engineId | "engine-ayse" |
| body.assetId | "Container-unlinked1" |
| body.measure.type | "temperature" |
| body.measure.values.temperature | -5 |
| body.measure.type | "temperature" |
| body.measure.name | "temperatureInt" |
Then The document "engine-ayse":"assets":"Container-unlinked1" content match:
| measures.temperatureInt.type | "temperature" |
| measures.temperatureInt.values.temperature | -5 |
| measures.temperatureExt.type | "temperature" |
| measures.temperatureExt.values.temperature | 26 |
When I successfully execute the action "device-manager/measures":"push" with args:
| engineId | "engine-ayse" |
| body.assetId | "Container-unlinked1" |
| body.measure.type | "temperature" |
| body.measure.values.temperature | 31 |
| body.measure.type | "temperature" |
| body.measure.name | "temperatureExt" |
Then The document "engine-ayse":"assets":"Container-unlinked1" content match:
| measures.temperatureExt.values.temperature | 31 |
Then I count 3 documents in "engine-ayse":"measures"

Scenario: Push a measure without name use measure type as name
When I successfully execute the action "device-manager/measures":"push" with args:
| engineId | "engine-ayse" |
| body.assetId | "Container-unlinked1" |
| body.measure.type | "temperature" |
| body.measure.values.temperature | 70 |
| body.measure.name | "temperatureExt" |
Then The document "engine-ayse":"assets":"Container-unlinked1" content match:
| measures.temperatureExt.type | "temperature" |
| measures.temperatureExt.name | "temperatureExt" |
| measures.temperatureExt.values.temperature | 70 |
91 changes: 91 additions & 0 deletions features/Asset/History.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Feature: Asset Historization

Scenario: Historize asset after creation and metadata update
When I successfully execute the action "device-manager/assets":"create" with args:
| engineId | "engine-kuzzle" |
| body.model | "Container" |
| body.reference | "A1" |
| body.metadata.height | 5 |
And I successfully execute the action "device-manager/assets":"update" with args:
| engineId | "engine-kuzzle" |
| _id | "Container-A1" |
| body.metadata.weight | 1250 |
And I refresh the collection "engine-kuzzle":"assets-history"
Then I successfully execute the action "document":"search" with args:
| index | "engine-kuzzle" |
| collection | "assets-history" |
| body.sort | {"_kuzzle_info.createdAt": "desc"} |
And I should receive a result matching:
| hits.length | 2 |
| hits[0]._source.id | "Container-A1" |
| hits[0]._source.event.name | "metadata" |
| hits[0]._source.event.metadata.names | ["weight"] |
| hits[0]._source.asset.metadata.height | 5 |
| hits[0]._source.asset.metadata.weight | 1250 |
| hits[1]._source.id | "Container-A1" |
| hits[1]._source.event.name | "metadata" |
| hits[1]._source.event.metadata.names | ["weight", "height"] |
| hits[1]._source.asset.metadata.height | 5 |
| hits[1]._source.asset.metadata.weight | null |

Scenario: Historize asset after being linked and unlinked
When I successfully execute the action "device-manager/devices":"linkAsset" with args:
| _id | "DummyTemp-unlinked1" |
| assetId | "Container-unlinked1" |
| engineId | "engine-ayse" |
| body.measureNames[0].device | "temperature" |
| body.measureNames[0].asset | "temperatureExt" |
And I execute the action "device-manager/devices":"unlinkAsset" with args:
| engineId | "engine-ayse" |
| _id | "DummyTemp-unlinked1" |
And I refresh the collection "engine-ayse":"assets-history"
Then I successfully execute the action "document":"search" with args:
| index | "engine-ayse" |
| collection | "assets-history" |
| body.sort | {"_kuzzle_info.createdAt": "desc"} |
And I should receive a result matching:
| hits.length | 2 |
| hits[0]._source.id | "Container-unlinked1" |
| hits[0]._source.event.name | "unlink" |
| hits[0]._source.event.unlink.deviceId | "DummyTemp-unlinked1" |
| hits[0]._source.asset.linkedDevices | [] |
| hits[1]._source.id | "Container-unlinked1" |
| hits[1]._source.event.name | "link" |
| hits[1]._source.event.link.deviceId | "DummyTemp-unlinked1" |
| hits[1]._source.asset.linkedDevices[0]._id | "DummyTemp-unlinked1" |

Scenario: Historize asset after receiving a new measure
When I send the following "dummy-temp" payloads:
| deviceEUI | temperature |
| "linked1" | 42.2 |
And I refresh the collection "engine-ayse":"assets-history"
Then I successfully execute the action "document":"search" with args:
| index | "engine-ayse" |
| collection | "assets-history" |
| body.sort | {"_kuzzle_info.createdAt": "desc"} |
And I should receive a result matching:
| hits.length | 1 |
| hits[0]._source.id | "Container-linked1" |
| hits[0]._source.event.name | "measure" |
| hits[0]._source.event.measure.names | ["temperatureExt"] |
| hits[0]._source.event.metadata | "_UNDEFINED_" |
| hits[0]._source.asset.measures.temperatureExt.values.temperature | 42.2 |

Scenario: Historize asset when metadata have been updated when receiving a measure
# A pipe will set the asset "weight" metadata to 42042
When I send the following "dummy-temp" payloads:
| deviceEUI | temperature | metadata.color |
| "linked1" | 42.2 | "test-metadata-history-with-measure" |
And I refresh the collection "engine-ayse":"assets-history"
Then I successfully execute the action "document":"search" with args:
| index | "engine-ayse" |
| collection | "assets-history" |
| body.sort | {"_kuzzle_info.createdAt": "desc"} |
And I should receive a result matching:
| hits.length | 1 |
| hits[0]._source.id | "Container-linked1" |
| hits[0]._source.event.name | "measure" |
| hits[0]._source.event.measure.names | ["temperatureExt"] |
| hits[0]._source.event.metadata.names | ["weight"] |
| hits[0]._source.asset.measures.temperatureExt.values.temperature | 42.2 |
| hits[0]._source.asset.metadata.weight | 42042 |
34 changes: 25 additions & 9 deletions features/Decoder/PayloadController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Feature: Payloads Controller
| valid | false |
And The document "device-manager":"devices":"DummyTemp-12345" does not exists

Scenario: Receive a payload with 3 measures
Scenario: Receive a payload with 3 measures but only 2 are propagated to the asset
Given I send the following "dummy-temp-position" payloads:
| deviceEUI | temperature | location.lat | location.lon | location.accuracy | battery |
| "12345" | 21 | 42.2 | 2.42 | 2100 | 0.8 |
Then The document "device-manager":"devices":"DummyTempPosition-12345" content match:
| reference | "12345" |
| "linked2" | 21 | 42.2 | 2.42 | 2100 | 0.8 |
Then The document "device-manager":"devices":"DummyTempPosition-linked2" content match:
| reference | "linked2" |
| model | "DummyTempPosition" |
| measures.temperature.type | "temperature" |
| measures.temperature.measuredAt | "_DATE_NOW_" |
Expand All @@ -54,22 +54,38 @@ Feature: Payloads Controller
| measures.battery.type | "battery" |
| measures.battery.measuredAt | "_DATE_NOW_" |
| measures.battery.values.battery | 80 |
| engineId | null |
| assetId | null |
| engineId | "engine-ayse" |
| assetId | "Container-linked2" |
Then The document "engine-ayse":"assets":"Container-linked2" content match:
| measures.temperatureExt.values.temperature | 21 |
| measures.position.values.position.lat | 42.2 |
| measures.position.values.position.lon | 2.42 |
| measures.battery | "_UNDEFINED_" |
And I refresh the collection "engine-ayse":"assets-history"
Then I successfully execute the action "document":"search" with args:
| index | "engine-ayse" |
| collection | "assets-history" |
| body.sort | {"_kuzzle_info.createdAt": "desc"} |
And I should receive a result matching:
| hits.length | 1 |
| hits[0]._source.id | "Container-linked2" |
| hits[0]._source.event.name | "measure" |
| hits[0]._source.event.measure.names | ["temperatureExt", "position"] |


Scenario: Historize the measures with device and asset context
Given I send the following "dummy-temp" payloads:
| deviceEUI | "12345" |
| "linked1" | 42.2 |
| deviceEUI | temperature |
| "linked1" | 42.2 |
And I refresh the collection "engine-ayse":"measures"
Then When I successfully execute the action "document":"search" with args:
| index | "engine-ayse" |
| collection | "measures" |
And I should receive a result matching:
| hits[0]._source.type | "temperature" |
| hits[0]._source.values.temperature | 42.2 |
| hits[0]._source.measuredAt | "_DATE_NOW_" |
| hits[0]._source.origin._id | "DummyTemp-linked1" |
| hits[0]._source.origin.type | "device" |
| hits[0]._source.origin.measureName | "temperature" |
| hits[0]._source.origin.deviceModel | "DummyTemp" |
| hits[0]._source.origin.reference | "linked1" |
Expand Down
6 changes: 4 additions & 2 deletions features/Device/Controller/AttachEngine.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ Feature: Attach device to engine
| _id | "DummyTemp-detached1" |
| engineId | "engine-kuzzle" |
Then The document "device-manager":"devices":"DummyTemp-detached1" content match:
| engineId | "engine-kuzzle" |
| engineId | "engine-kuzzle" |
| _kuzzle_info.updater | "-1" |
Then The document "engine-kuzzle":"devices":"DummyTemp-detached1" content match:
| engineId | "engine-kuzzle" |
| engineId | "engine-kuzzle" |
| _kuzzle_info.author | "-1" |
When I send the following "dummy-temp" payloads:
| deviceEUI | temperature |
| "detached1" | 21 |
Expand Down
3 changes: 2 additions & 1 deletion features/Device/Controller/DetachEngine.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Feature: Detach device from engine
| engineId | "engine-kuzzle" |
| _id | "DummyTemp-detached1" |
Then The document "device-manager":"devices":"DummyTemp-detached1" content match:
| engineId | null |
| engineId | null |
| _kuzzle_info.updater | "-1" |
And The document "engine-kuzzle":"devices":"DummyTemp-detached1" does not exists

Scenario: Error if device is not attached
Expand Down
Loading

0 comments on commit fed1032

Please sign in to comment.