Update iotdm library and tests.
[integration/test.git] / csit / suites / iotdm / basic / 030_LayerTest.robot
1 *** Settings ***
2 Documentation     Test for layers AE/CONTAINER/CONTENTINSTANCE
3 Suite Teardown    Kill The Tree    ${ODL_SYSTEM_IP}    InCSE1    admin    admin
4 Library           ../../../libraries/criotdm.py
5 Library           Collections
6
7 *** Variables ***
8 ${httphost}       ${ODL_SYSTEM_IP}
9 ${httpuser}       admin
10 ${httppass}       admin
11 ${rt_ae}          2
12 ${rt_container}    3
13 ${rt_contentInstance}    4
14
15 *** Test Cases ***
16 Set Suite Variable
17     [Documentation]    set a suite variable ${iserver}
18     #==================================================
19     #    AE Test
20     #==================================================
21     ${iserver} =    Connect To Iotdm    ${httphost}    ${httpuser}    ${httppass}    http
22     Set Suite Variable    ${iserver}
23
24 1.11 Valid Input for AE without name
25     [Documentation]    Valid Input for AE without name
26     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true
27     ${r} =    Create Resource    ${iserver}    InCSE1    ${rt_ae}    ${attr}
28     Response Is Correct    ${r}
29
30 1.12 Valid Input for AE with name
31     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true,"rn":"ODL3"
32     ${r} =    Create Resource    ${iserver}    InCSE1    ${rt_ae}    ${attr}
33     Response Is Correct    ${r}
34
35 1.13 Invalid Input for AE with name Already Exist, should return error
36     [Documentation]    Invalid Input for AE with name Already Exist, should return error
37     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true,"rn":"ODL3"
38     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1    ${rt_ae}
39     ...    ${attr}
40     Should Start with    ${error}    Cannot create this resource [409]
41
42 1.14 Invalid Input for AE (AE cannot be created under AE)
43     [Documentation]    Invalid Input for AE (AE cannot be created under AE), expect error
44     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true,"rn":"ODL4"
45     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/ODL3    ${rt_ae}
46     ...    ${attr}
47     Should Start with    ${error}    Cannot create this resource [405]
48     # -----------------    Update and Retrieve -------------
49
50 1.15 Valid Update AE's label
51     [Documentation]    Valid Update AE's label
52     ${attr} =    Set Variable    "lbl":["aaa","bbb","ccc"]
53     ${r} =    Update Resource    ${iserver}    InCSE1/ODL3    ${rt_ae}    ${attr}
54     Response Is Correct    ${r}
55     # Retrieve and test the lbl
56     ${r} =    Retrieve Resource    ${iserver}    InCSE1/ODL3
57     ${Json} =    Text    ${r}
58     Should Contain    ${Json}    "aaa"    "bbb"    "ccc"
59     Should Contain    ${r.json()['m2m:ae']['lbl']}    aaa    bbb    ccc
60     #==================================================
61     #    Container Test
62     #==================================================
63
64 2.11 Create Container under AE without name
65     [Documentation]    Create Container under AE without name
66     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you"
67     Connect And Create Resource    InCSE1/ODL3    ${rt_container}    ${attr}
68
69 2.12 Create Container under AE with name
70     [Documentation]    Invalid Input for Container Under AE with name (Already exist)
71     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderAE"
72     ${r} =    Create Resource    ${iserver}    InCSE1/ODL3    ${rt_container}    ${attr}
73     ${container} =    Location    ${r}
74     Response Is Correct    ${r}
75     # retrieve it
76     ${result} =    Retrieve Resource    ${iserver}    ${container}
77     ${text} =    Text    ${result}
78     Should Contain    ${text}    containerUnderAE
79
80 2.13 Invalid Input for Container Under AE with name (Already exist)
81     [Documentation]    Invalid Input for Container Under AE with name (Already exist)
82     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderAE"
83     ${error} =    Run Keyword And Expect Error    *    Connect And Create Resource    InCSE1/ODL3    ${rt_container}    ${attr}
84     Should Start with    ${error}    Cannot create this resource [409]
85
86 2.14 Update Container Label
87     [Documentation]    Update Label to ["aaa","bbb","ccc"]
88     ${attr} =    Set Variable    "lbl":["aaa","bbb","ccc"]
89     ${r} =    Update Resource    ${iserver}    InCSE1/ODL3/containerUnderAE    ${rt_container}    ${attr}
90     Response Is Correct    ${r}
91     # Retrieve and test the lbl
92     ${r} =    Retrieve Resource    ${iserver}    InCSE1/ODL3/containerUnderAE
93     ${Json} =    Text    ${r}
94     Should Contain    ${Json}    "aaa"    "bbb"    "ccc"
95     Should Contain    ${r.json()['m2m:cnt']['lbl']}    aaa    bbb    ccc
96     #----------------------------------------------------------------------
97
98 2.21 Create Container under InCSE1 without name
99     [Documentation]    Create Container under InCSE1 without name
100     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you"
101     ${r} =    Create Resource    ${iserver}    InCSE1    ${rt_container}    ${attr}
102     Response Is Correct    ${r}
103
104 2.22 Create Container under CSE with name
105     [Documentation]    Create Container under CSE with name
106     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderCSE"
107     ${r} =    Create Resource    ${iserver}    InCSE1    ${rt_container}    ${attr}
108     Response Is Correct    ${r}
109     # retrieve it
110     ${result} =    Retrieve Resource    ${iserver}    InCSE1/containerUnderCSE
111     ${text} =    Text    ${result}
112     Should Contain    ${text}    containerUnderCSE
113
114 2.23 Invalid Input for Container Under CSE with name (Already exist)
115     [Documentation]    Invalid Input for Container Under CSE with name (Already exist)
116     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderCSE"
117     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1    ${rt_container}
118     ...    ${attr}
119     Should Start with    ${error}    Cannot create this resource [409]
120
121 2.24 Update Container Label
122     [Documentation]    Update Container Label
123     ${attr} =    Set Variable    "lbl":["aaa","bbb","ccc"]
124     ${r} =    Update Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_container}    ${attr}
125     Response Is Correct    ${r}
126     # Retrieve and test the lbl
127     ${r} =    Retrieve Resource    ${iserver}    InCSE1/containerUnderCSE
128     ${Json} =    Text    ${r}
129     Should Contain    ${Json}    "aaa"    "bbb"    "ccc"
130     Should Contain    ${r.json()['m2m:cnt']['lbl']}    aaa    bbb    ccc
131     #----------------------------------------------------------------------
132
133 2.31 Create Container under Container without name
134     [Documentation]    Create Container under Container without name
135     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you"
136     ${r} =    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_container}    ${attr}
137     Response Is Correct    ${r}
138
139 2.32 Create Container under Container with name
140     [Documentation]    Create Container under Container with name
141     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderContainer"
142     ${r} =    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_container}    ${attr}
143     ${container} =    Location    ${r}
144     Response Is Correct    ${r}
145     # retrieve it
146     ${result} =    Retrieve Resource    ${iserver}    ${container}
147     ${text} =    Text    ${result}
148     Should Contain    ${text}    containerUnderContainer
149
150 2.33 Invalid Input for Container Under Container with name (Already exist)
151     [Documentation]    Invalid Input for Container Under Container with name (Already exist)
152     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you","rn":"containerUnderContainer"
153     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_container}
154     ...    ${attr}
155     Should Start with    ${error}    Cannot create this resource [409]
156
157 2.34 Update Container Label
158     [Documentation]    Update Container Label to ["aaa","bbb","ccc"]
159     ${attr} =    Set Variable    "lbl":["aaa","bbb","ccc"]
160     ${r} =    Update Resource    ${iserver}    InCSE1/containerUnderCSE/containerUnderContainer    ${rt_container}    ${attr}
161     Response Is Correct    ${r}
162     # Retrieve and test the lbl
163     ${r} =    Retrieve Resource    ${iserver}    InCSE1/containerUnderCSE/containerUnderContainer
164     ${Json} =    Text    ${r}
165     Should Contain    ${Json}    "aaa"    "bbb"    "ccc"
166     Should Contain    ${r.json()['m2m:cnt']['lbl']}    aaa    bbb    ccc
167
168 2.41 Invalid Input for AE under container with name(mess up layer)
169     [Documentation]    Invalid Input for AE under container withoutname(mess up layer)
170     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true,"rn":"ODL4"
171     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_ae}
172     ...    ${attr}
173     Should Start with    ${error}    Cannot create this resource [405]
174     Should Contain    ${error}    Cannot create AE under this resource type: 3
175     #==================================================
176     #    ContentInstance Test
177     #==================================================
178
179 3.11 Valid contentInstance under CSEBase/container without name
180     [Documentation]    Valid contentInstance under CSEBase/container without name
181     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"101"
182     ${r} =    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_contentInstance}    ${attr}
183     Response Is Correct    ${r}
184
185 3.12 Valid contentInstance under CSEBase/container with name
186     [Documentation]    Valid contentInstance under CSEBase/container with name
187     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"102","rn":"conIn1"
188     ${r} =    Create Resource    ${iserver}    InCSE1/containerUnderCSE    ${rt_contentInstance}    ${attr}
189     Response Is Correct    ${r}
190
191 3.13 Invalid contentInstance under CSEBase
192     [Documentation]    Invalid contentInstance under CSEBase
193     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"101"
194     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1    ${rt_contentInstance}
195     ...    ${attr}
196     Should Start with    ${error}    Cannot create this resource [405]
197     Should Contain    ${error}    Cannot create ContentInstance under this resource type: 5
198
199 3.14 Invalid contentInstance under AE
200     [Documentation]    Invalid contentInstance under AE
201     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"101"
202     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/ODL3    ${rt_contentInstance}
203     ...    ${attr}
204     Should Start with    ${error}    Cannot create this resource [405]
205     Should Contain    ${error}    Cannot create ContentInstance under this resource type: 2
206
207 3.15 Invalid contentInstance under contentInstance
208     [Documentation]    Invalid contentInstance under contentInstance
209     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"101"
210     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/containerUnderCSE/conIn1    ${rt_contentInstance}
211     ...    ${attr}
212     Should Start with    ${error}    Cannot create this resource [405]
213     Should Contain    ${error}    Cannot create ContentInstance under this resource type: 4
214
215 3.16 Invalid AE under contentInstance
216     [Documentation]    Invalid AE under contentInstance
217     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true
218     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/containerUnderCSE/conIn1    ${rt_ae}
219     ...    ${attr}
220     Should Start with    ${error}    Cannot create this resource [405]
221     Should Contain    ${error}    Cannot create AE under this resource type: 4
222
223 3.17 Invalid container under contentInstance
224     [Documentation]    Invalid container under contentInstance
225     ${attr} =    Set Variable    "cr":null,"lbl":["aaa","bbb","ccc"]
226     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/containerUnderCSE/conIn1    ${rt_container}
227     ...    ${attr}
228     Should Start with    ${error}    Cannot create this resource [405]
229     Should Contain    ${error}    Cannot create Container under this resource type: 4
230     #==================================================
231     #    Delete Test
232     #==================================================
233
234 4.11 Delete AE without child resource
235     [Documentation]    Delete AE without child resource
236     ${attr} =    Set Variable    "api":"jb","apn":"jb2","or":"http://hey/you","rr":true
237     ${r} =    Create Resource    ${iserver}    InCSE1    ${rt_ae}    ${attr}
238     ${ae} =    Location    ${r}
239     Response Is Correct    ${r}
240     ${deleteRes} =    Delete Resource    ${iserver}    ${ae}
241     ${status_code} =    Status Code    ${deleteRes}
242     Should Be Equal As Integers    ${status_code}    200
243     # Delete AE that does not exist/has been deleted should return error
244     ${error} =    Run Keyword And Expect Error    *    Delete Resource    ${iserver}    ${ae}
245     Should Start with    ${error}    Cannot delete this resource [404]
246
247 4.12 Delete Container without child resource
248     [Documentation]    Delete Container without child resource
249     ${attr} =    Set Variable    "cr":null,"mni":1,"mbs":15,"or":"http://hey/you"
250     ${r} =    Create Resource    ${iserver}    InCSE1/ODL3    ${rt_container}    ${attr}
251     ${container} =    Location    ${r}
252     Response Is Correct    ${r}
253     ${deleteRes} =    Delete Resource    ${iserver}    ${container}
254     ${status_code} =    Status Code    ${deleteRes}
255     Should Be Equal As Integers    ${status_code}    200
256     # Delete container that does not exist/has been deleted should return error
257     ${error} =    Run Keyword And Expect Error    *    Delete Resource    ${iserver}    ${container}
258     Should Start with    ${error}    Cannot delete this resource [404]
259
260 Delete the Container Under CSEBase
261     [Documentation]    Delete the Container and AE Under CSEBase
262     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/containerUnderCSE
263     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/ODL3
264
265 *** Keywords ***
266 Connect And Create Resource
267     [Arguments]    ${targetURI}    ${resoutceType}    ${attr}
268     ${iserver} =    Connect To Iotdm    ${httphost}    ${httpuser}    ${httppass}    http
269     ${r} =    Create Resource    ${iserver}    ${targetURI}    ${resoutceType}    ${attr}
270     ${container} =    Resid    ${r}
271     ${status_code} =    Status Code    ${r}
272     Should Be Equal As Integers    ${status_code}    201
273
274 Response Is Correct
275     [Arguments]    ${r}
276     ${status_code} =    Status Code    ${r}
277     Should Be True    199 < ${status_code} < 299
278     ${text} =    Text    ${r}
279     LOG    ${text}
280     ${json} =    Json    ${r}
281     LOG    ${json}