c4c6e500cc36af212c80a4082fd8cd31220eacc8
[apps/agl-service-data-persistence.git] / test / tests / persistence_BasicAPITest.lua
1 --[[
2    Copyright (C) 2018 "IoT.bzh"
3    Author Frédéric Marec <frederic.marec@iot.bzh>
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9      http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17
18    NOTE: strict mode: every global variables should be prefixed by '_'
19 --]]
20
21 local testPrefix ="persistence_BasicAPITest_"
22
23 -- This tests the 'insert' verb of the persistence API
24 _AFT.describe(testPrefix.."insert_with_verification",function()
25   _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTinsert", value="insert"})
26   _AFT.assertVerbResponseEquals("persistence","read", {key="TESTinsert"},{value="insert"})
27   _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTinsert"})
28   _AFT.assertVerbResponseEqualsError("persistence","read", {key="TESTinsert"},{value="insert"})
29 end)
30
31 -- This tests the 'update' verb of the persistence API
32 _AFT.describe(testPrefix.."update_with_verification",function()
33   _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTupdate", value="myvalue"})
34   _AFT.assertVerbResponseEquals("persistence","read", {key="TESTupdate"},{value="myvalue"})
35   _AFT.assertVerbStatusSuccess("persistence", "update", {key="TESTupdate", value="newvalue"})
36   _AFT.assertVerbResponseEquals("persistence","read", {key="TESTupdate"},{value="newvalue"})
37   _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTupdate"})
38   _AFT.assertVerbResponseEqualsError("persistence","read", {key="TESTupdate"},{value="myvalue"})
39   _AFT.assertVerbResponseEqualsError("persistence","read", {key="TESTupdate"},{value="newvalue"})
40 end)
41
42 -- This tests the 'delete' verb of the persistence API
43 _AFT.describe(testPrefix.."delete_with_verification",function()
44   _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTdelete", value="delete"})
45   _AFT.assertVerbResponseEquals("persistence","read", {key="TESTdelete"},{value="delete"})
46   _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTdelete"})
47   _AFT.assertVerbResponseEqualsError("persistence","read", {key="TESTdelete"},{value="delete"})
48 end)
49
50 -- This tests the 'insert' verb of the persistence API
51 _AFT.testVerbStatusSuccess(testPrefix.."insert","persistence","insert", {key="TESTinsert", value="insert"}, nil,
52   function()
53     _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTinsert"})
54   end)
55
56 -- This tests the 'delete' verb of the persistence API
57 _AFT.testVerbStatusSuccess(testPrefix.."delete","persistence","delete", {key="TESTdelete"},
58   function()
59     _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTdelete", value="delete"})
60   end, nil)
61
62 -- This tests the 'update' verb of the persistence API
63 _AFT.testVerbStatusSuccess(testPrefix.."update","persistence","update", {key="TESTupdate", value="testupdate"},
64   function()
65     _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTupdate", value="newupdate"})
66   end,
67   function()
68     _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTupdate"})
69   end)
70
71 -- This tests the 'read' verb of the persistence API
72 _AFT.testVerbStatusSuccess(testPrefix.."read","persistence","read", {key="TESTread"},
73   function()
74     _AFT.assertVerbStatusSuccess("persistence", "insert", {key="TESTread", value="myvalue"})
75   end,
76   function()
77     _AFT.assertVerbStatusSuccess("persistence", "delete", {key="TESTread"})
78   end)
79
80 -- This tests the 'read' verb of the persistence API
81 _AFT.testVerbStatusError(testPrefix.."read-unknow-value","persistence","read", {key="TESTread-unknow-value"}, nil, nil)
82
83 -- This tests the 'insert' verb of the persistence API
84 _AFT.testVerbStatusError(testPrefix.."insert-without-value","persistence","insert", {key="TESTread-unknow-value"}, nil,
85   function()
86     _AFT.assertVerbStatusError("persistence", "delete", {key="TEST"})
87   end)
88
89 -- This tests the 'insert' verb of the persistence API
90 _AFT.testVerbStatusError(testPrefix.."insert-with-wrong_key","persistence","insert", {wrong_key="TESTinsert-wrong-key", value="TESTinsert-wrong-key"}, nil,
91   function()
92     _AFT.assertVerbStatusError("persistence", "delete", {key="TESTinsert-wrong-key"})
93   end)
94
95 -- This tests the 'insert' verb of the persistence API
96 _AFT.testVerbStatusError(testPrefix.."insert-with-wrong_value","persistence","insert", {key="TESTinsert-wrong-value", wrong_value="TESTinsert-wrong-value"}, nil,
97   function()
98     _AFT.assertVerbStatusError("persistence", "delete", {key="TESTinsert-wrong-value"})
99   end)
100
101 -- This tests the 'delete' verb of the persistence API
102 _AFT.testVerbStatusError(testPrefix.."delete-unknow-key","persistence","delete", {key="TESTdelete-unknow-key"}, nil, nil)
103
104 -- This tests the 'insert' verb of the persistence API
105 _AFT.testVerbStatusError(testPrefix.."insert-with-anything","persistence","insert", {value="TESTinsert-with-anything"}, nil, nil)
106
107 -- This tests the 'update' verb of the persistence API
108 _AFT.testVerbStatusError(testPrefix.."update-unkwon-null-value","persistence","update", {key=null}, nil, nil)