6d6569711bf64c9208c96017d38619801fc6cda9
[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.testVerbStatusSuccess(testPrefix.."insert","persistence","insert", {key="TEST", value="myvalue"}, nil,
25   function()
26     _AFT.callVerb("persistence", "delete", {key="TEST"})
27   end)
28
29 -- This tests the 'delete' verb of the persistence API
30 _AFT.testVerbStatusSuccess(testPrefix.."delete","persistence","delete", {key="TEST"},
31   function()
32     _AFT.callVerb("persistence", "insert", {key="TEST", value="myvalue"})
33   end, nil)
34
35 -- This tests the 'update' verb of the persistence API
36 _AFT.testVerbStatusSuccess(testPrefix.."update","persistence","update", {key="TEST", value="test"},
37   function()
38     _AFT.callVerb("persistence", "insert", {key="TEST", value="myvalue"})
39   end,
40   function()
41     _AFT.callVerb("persistence", "delete", {key="TEST"})
42   end)
43
44 -- This tests the 'read' verb of the persistence API
45 _AFT.testVerbStatusSuccess(testPrefix.."read","persistence","read", {key="TEST"},
46   function()
47     _AFT.callVerb("persistence", "insert", {key="TEST", value="myvalue"})
48   end,
49   function()
50     _AFT.callVerb("persistence", "delete", {key="TEST"})
51   end)
52
53 -- This tests the 'read' verb of the persistence API
54 _AFT.testVerbStatusError(testPrefix.."read-unknow-value","persistence","read", {key="TEST"}, nil, nil)
55
56 -- This tests the 'insert' verb of the persistence API
57 _AFT.testVerbStatusError(testPrefix.."insert-without-value","persistence","insert", {key="TEST"}, nil,
58   function()
59     _AFT.callVerb("persistence", "delete", {key="TEST"})
60   end)
61
62 -- This tests the 'delete' verb of the persistence API
63 _AFT.testVerbStatusError(testPrefix.."delete-unknow-key","persistence","delete", {key="TEST"}, nil, nil)
64
65 -- This tests the 'insert' verb of the persistence API
66 _AFT.testVerbStatusError(testPrefix.."insert-with-anything","persistence","insert", {value="talenka"}, nil, nil)
67
68 -- This tests the 'update' verb of the persistence API
69 _AFT.testVerbStatusError(testPrefix.."update-unkwon-null-value","persistence","update", {key=null}, nil, nil)
70
71 _AFT.exitAtEnd()