Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / iotdm / basic / 022_ResourceAttributesContentInstance.robot
1 *** Settings ***
2 Documentation     Tests for Content Instance resource attributes
3 Suite Setup       IOTDM Basic Suite Setup    ${ODL_SYSTEM_1_IP}    ${ODL_RESTCONF_USER}    ${ODL_RESTCONF_PASSWORD}
4 Suite Teardown    Kill The Tree    ${ODL_SYSTEM_1_IP}    InCSE1    admin    admin
5 Resource          ../../../libraries/SubStrings.robot
6 Library           ../../../libraries/IoTDM/criotdm.py
7 Library           Collections
8 Resource          ../../../variables/Variables.robot
9 Resource          ../../../libraries/IoTDM/IoTDMKeywords.robot
10
11 *** Variables ***
12 ${rt_ae}          2
13 ${rt_container}    3
14 ${rt_contentInstance}    4
15
16 *** Test Cases ***
17 TODO Refactor test suite and implement TCs
18     [Documentation]    Refactor this test suite and implement next TCs according to 000_ResourceAttributesNotes.txt03.
19     ...    Example of changes is in 024_ResourceAttributesAE.robot
20     [Tags]    not-implemented    exclude
21     TODO
22
23 1.1 After Created, test whether all the mandatory attribtues are exist.
24     [Documentation]    create 1 conIn test whether all the mandatory attribtues are exist
25     ${attr} =    Set Variable    "rn":"Container1", "mni": 5
26     ${r}=    Create Resource With Command    ${iserver}    InCSE1    ${rt_container}    rcn=3    ${attr}
27     ${container} =    Location    ${r}
28     ${status_code} =    Status Code    ${r}
29     Should Be Equal As Integers    ${status_code}    201
30     ${attr} =    Set Variable    "con":"102CSS","rn":"conIn1"
31     ${r} =    Create Resource With Command    ${iserver}    InCSE1/Container1    ${rt_contentInstance}    rcn=3    ${attr}
32     ${text} =    Text    ${r}
33     Should Contain All Sub Strings    ${text}    "ri":    "rn":    "cs":    "lt":    "pi":
34     ...    "con":    "ct":    "ty":4
35     Should Not Contain    S{text}    "lbl"    "creator"    "or"
36
37 1.21 Missing content should return error
38     [Documentation]    Missing content should return error
39     ${attr} =    Set Variable
40     ${error} =    Run Keyword And Expect Error    *    Create Resource    ${iserver}    InCSE1/Container1    ${rt_contentInstance}
41     ...    ${attr}
42     Should Start with    ${error}    Cannot create this resource [400]
43     Should Contain    ${error}    CONTENT    missing
44     #===========================================================
45     #    ContentInstance Optional Attribute Test (Allowed)
46     #===========================================================
47     #    create--> delete
48     #    Cannot be updated
49     # Optional attribute: [aa,at],contentInfo, ontologyRef, label, creator
50
51 2.11 ContentInfo (cnf) can be added when create
52     [Documentation]    ContentInfo (cnf) can be added when create
53     ${attr} =    Set Variable    "cnf": "1","con":"102CSS","rn":"conIn2"
54     # create conIn under Container1
55     ${r}=    Create Resource    ${iserver}    InCSE1/Container1    ${rt_contentInstance}    ${attr}
56     ${text} =    Check Create and Retrieve ContentInstance    ${r}
57     Should Contain    ${text}    cnf
58
59 Delete the ContenInstance 2.1
60     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/Container1/conIn2
61
62 2.12 ContentInfo (cnf) cannot be updated
63     [Documentation]    ContentInfo (cnf) cannot be updated
64     ${attr} =    Set Variable    "cnf": "1"
65     ${error} =    Cannot Update ContentInstance Error    ${attr}
66     Should Contain    ${error}    Not permitted to update content
67
68 2.21 OntologyRef (or) can be added when create
69     [Documentation]    OntologyRef (or) can be added when create
70     ${attr} =    Set Variable    "or": "http://cisco.com","con":"102CSS","rn":"conIn2"
71     # create conIn under Container1
72     ${r}=    Create Resource    ${iserver}    InCSE1/Container1    ${rt_contentInstance}    ${attr}
73     ${text} =    Check Create and Retrieve ContentInstance    ${r}
74     Should Contain    ${text}    or
75
76 Delete the ContenInstance 2.2
77     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/Container1/conIn2
78
79 2.22 OntologyRef (or) cannot be updated
80     [Documentation]    OntologyRef (or) cannot be updated
81     ${attr} =    Set Variable    "or": "1"
82     ${error} =    Cannot Update ContentInstance Error    ${attr}
83     Should Contain    ${error}    Not permitted to update content
84
85 2.31 labels[single] can be added when create
86     [Documentation]    create conIn under Container1, labels[single] can be added when create
87     ${attr} =    Set Variable    "lbl":["ds"],"con":"102CSS","rn":"conIn2"
88     ${r}=    Create Resource    ${iserver}    InCSE1/Container1    ${rt_contentInstance}    ${attr}
89     ${text} =    Check Create and Retrieve ContentInstance    ${r}
90     Should Contain    ${text}    lbl
91
92 Delete the ContenInstance 2.31
93     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/Container1/conIn2
94
95 2.32 labels (single) cannot be updated
96     [Documentation]    update labels then expect error
97     ${attr} =    Set Variable    "lbl":["1"]
98     ${error} =    Cannot Update ContentInstance Error    ${attr}
99     Should Contain    ${error}    Not permitted to update content
100
101 2.33 labels (multiple) can be added when create
102     [Documentation]    labels (multiple) can be added when create
103     ${attr} =    Set Variable    "lbl":["http://cisco.com","dsds"],"con":"102CSS","rn":"conIn2"
104     # create conIn under Container1
105     ${r}=    Create Resource    ${iserver}    InCSE1/Container1    ${rt_contentInstance}    ${attr}
106     ${text} =    Check Create and Retrieve ContentInstance    ${r}
107     Should Contain    ${text}    lbl
108
109 Delete the ContenInstance 2.33
110     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/Container1/conIn2
111
112 2.34 labels (multiple) cannot be updated
113     [Documentation]    labels (multiple) cannot be updated
114     ${attr} =    Set Variable    "lbl":["1"]
115     ${error} =    Cannot Update ContentInstance Error    ${attr}
116     Should Contain    ${error}    Not permitted to update content
117     #=================================================================
118     #    contentInstance Disturbing Attribute Test, Not Allowed Update
119     #=================================================================
120     # using non-valid attribtue to create then expext error
121
122 3.11 Mulitiple labels should return error
123     [Documentation]    Mulitiple labels should return error
124     ${attr} =    Set Variable    "con": "1", "lbl":["label1"],"lbl":["label2"]
125     ${error} =    Cannot Craete ContentInstance Error    ${attr}
126     Should Contain All Sub Strings    ${error}    Duplicate    lbl
127
128 3.12 Multiple creator should return error
129     [Documentation]    Multiple creator should return error
130     ${attr} =    Set Variable    "con": "1", "cr":null, "cr":null
131     ${error} =    Cannot Craete ContentInstance Error    ${attr}
132     Should Contain All Sub Strings    ${error}    Duplicate    cr
133
134 3.13 Multiple contentInfo should return error
135     [Documentation]    Multiple contentInfo should return error
136     ${attr} =    Set Variable    "con": "1", "cnf":"1","cnf":"2"
137     ${error} =    Cannot Craete ContentInstance Error    ${attr}
138     Should Contain All Sub Strings    ${error}    Duplicate    cnf
139
140 3.14 Multiple ontologyRef should return error
141     [Documentation]    Multiple ontologyRef should return error
142     ${attr} =    Set Variable    "con": "1", "or":"http://cisco.com","or":"http://google.com"
143     ${error} =    Cannot Craete ContentInstance Error    ${attr}
144     Should Contain All Sub Strings    ${error}    Duplicate    or
145
146 3.15 Mulptiple content should return error
147     [Documentation]    Mulptiple content should return error
148     ${attr} =    Set Variable    "con": "1", "con":"2313"
149     ${error} =    Cannot Craete ContentInstance Error    ${attr}
150     Should Contain All Sub Strings    ${error}    Duplicate    con
151     #----------------All attributes cannot be updated----------
152
153 3.21 resourceType cannot be updated.
154     [Documentation]    update resourceType and expect error
155     ${attr} =    Set Variable    "rt": 3
156     ${error} =    Cannot Update ContentInstance Error    ${attr}
157     Should Contain    ${error}    Not permitted to update content
158
159 3.22 resourceId cannot be updated.
160     [Documentation]    update resourceId and expect error
161     ${attr} =    Set Variable    "ri": "e4e43"
162     ${error} =    Cannot Update ContentInstance Error    ${attr}
163     Should Contain    ${error}    Not permitted to update content
164
165 3.23 resourceName cannot be updated.
166     [Documentation]    update resourceName and expect error
167     ${attr} =    Set Variable    "rn": "4343"
168     ${error} =    Cannot Update ContentInstance Error    ${attr}
169     Should Contain    ${error}    Not permitted to update content
170
171 3.24 parentId cannot be updated.
172     [Documentation]    update parentID and expect error
173     ${attr} =    Set Variable    "pi": "InCSE2/ERE"
174     ${error} =    Cannot Update ContentInstance Error    ${attr}
175     Should Contain    ${error}    Not permitted to update content
176
177 3.25 cretionTime cannot be updated.
178     [Documentation]    update createTime and expect error
179     ${attr} =    Set Variable    "ct": "20201210T123434"
180     ${error} =    Cannot Update ContentInstance Error    ${attr}
181     Should Contain    ${error}    Not permitted to update content
182
183 3.26 last modified time cannot be updated.
184     [Documentation]    update lt then expect error
185     ${attr} =    Set Variable    "lt": "20201210T123434"
186     ${error} =    Cannot Update ContentInstance Error    ${attr}
187     Should Contain    ${error}    Not permitted to update content
188
189 3.27 contentSize cannot be updated.
190     [Documentation]    update contentSize then expect error
191     ${attr} =    Set Variable    "cs": 232
192     ${error} =    Cannot Update ContentInstance Error    ${attr}
193     Should Contain    ${error}    Not permitted to update content
194
195 3.28 content cannot be updated
196     [Documentation]    update content then expect error
197     ${attr} =    Set Variable    "con": "1"
198     ${error} =    Cannot Update ContentInstance Error    ${attr}
199     Should Contain    ${error}    Not permitted to update content
200
201 4.11 GetLatest Test
202     [Documentation]    Set mni to 1 when creating a container, then continue creating <cin> "get latest" should always return the last created <cin>'s "con" value.
203     ${attr} =    Set Variable    "mni":1,"rn":"Container2"
204     ${r}=    Create Resource    ${iserver}    InCSE1    ${rt_container}    ${attr}
205     ${container} =    Location    ${r}
206     ${random} =    Evaluate    random.randint(0,50)    modules=random
207     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"${random}"
208     Create Resource    ${iserver}    ${container}    ${rt_contentInstance}    ${attr}
209     ${latestCon} =    Get Latest    ${container}
210     Should Be Equal As Strings    ${random}    ${latestCon}
211
212 4.12 GetLatest Loop 50 times Test
213     [Documentation]    Just like 4.11, but do 50 times.
214     ${attr} =    Set Variable    "mni":1,"rn":"Container3"
215     ${r}=    Create Resource    ${iserver}    InCSE1    ${rt_container}    ${attr}
216     ${container} =    Location    ${r}
217     FOR    ${INDEX}    IN RANGE    1    100
218         Latest Con Test    ${container}
219     END
220
221 Delete the test Container1
222     [Documentation]    Delete the test Container1
223     ${deleteRes} =    Delete Resource    ${iserver}    InCSE1/Container1
224
225 *** Keywords ***
226 Cannot Update ContentInstance Error
227     [Arguments]    ${attr}
228     ${error} =    Run Keyword And Expect Error    *    update Resource    ${iserver}    InCSE1/Container1/conIn1    ${rt_contentInstance}
229     ...    ${attr}
230     Should Start with    ${error}    Cannot update this resource [405]
231     [Return]    ${error}
232
233 Cannot Craete ContentInstance Error
234     [Arguments]    ${attr}
235     ${error} =    Run Keyword And Expect Error    *    create Resource    ${iserver}    InCSE1/Container1/conIn1    ${rt_contentInstance}
236     ...    ${attr}
237     Should Start with    ${error}    Cannot create this resource [400]
238     [Return]    ${error}
239
240 Check Create and Retrieve ContentInstance
241     [Arguments]    ${r}
242     ${con} =    Location    ${r}
243     ${status_code} =    Status Code    ${r}
244     Should Be Equal As Integers    ${status_code}    201
245     ${rr} =    Retrieve Resource    ${iserver}    ${con}
246     ${text} =    Text    ${rr}
247     [Return]    ${text}
248
249 Get Latest
250     [Arguments]    ${resourceURI}
251     ${latest} =    Retrieve Resource    ${iserver}    ${resourceURI}/latest
252     ${con} =    Content    ${latest}
253     [Return]    ${con}
254
255 Latest Con Test
256     [Arguments]    ${resourceURI}
257     ${random} =    Evaluate    random.randint(0,50)    modules=random
258     ${attr} =    Set Variable    "cnf": "1","or": "http://hey/you","con":"${random}"
259     Create Resource    ${iserver}    ${resourceURI}    ${rt_contentInstance}    ${attr}
260     ${latestCon} =    Get Latest    ${resourceURI}
261     Should Be Equal As Strings    ${random}    ${latestCon}
262
263 TODO
264     Fail    "Not implemented"