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