sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yms.app.ydt; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yms.app.ydt.exceptions.YdtException; |
| 21 | |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 22 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MAXIWR; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 23 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MAXUIWR; |
| 24 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MIDIWR; |
| 25 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MIDUIWR; |
| 26 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MINIWR; |
| 27 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MINUIWR; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 28 | import static org.onosproject.yms.app.ydt.YdtTestConstants.MRV; |
| 29 | import static org.onosproject.yms.app.ydt.YdtTestConstants.RUI; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 30 | import static org.onosproject.yms.app.ydt.YdtTestConstants.TYPE; |
| 31 | import static org.onosproject.yms.app.ydt.YdtTestUtils.integer16Ydt; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 32 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 33 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 34 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 35 | |
| 36 | public class YdtInteger16Test { |
| 37 | |
| 38 | /* |
| 39 | Positive scenario |
| 40 | |
| 41 | input at boundry for integer |
| 42 | i. min value |
| 43 | ii. max value |
| 44 | |
| 45 | input at boundry for uinteger |
| 46 | i. min value |
| 47 | ii. max value |
| 48 | |
| 49 | input with in range |
| 50 | if range is 10 to 100 for integer |
| 51 | i.1. input 11 |
| 52 | i.2. min value 10 |
| 53 | i.3. max value 100 |
| 54 | |
| 55 | if range is 10 to 100 for uinteger |
| 56 | i.1. input 11 |
| 57 | i.2. min value 10 |
| 58 | i.3. max value 100 |
| 59 | |
| 60 | input with multi interval range |
| 61 | if range is 10..40 | 50..100 for integer |
| 62 | i.1. input 11 |
| 63 | i.2. input 10 |
| 64 | i.3. input 40 |
| 65 | i.4. input 50 |
| 66 | i.5. input 55 |
| 67 | i.6. input 100 |
| 68 | |
| 69 | if range is 10..40 | 50..100 for uinteger |
| 70 | i.1. input 11 |
| 71 | i.2. input 10 |
| 72 | i.3. input 40 |
| 73 | i.4. input 50 |
| 74 | i.5. input 55 |
| 75 | i.6. input 100 |
| 76 | |
| 77 | if range is "min .. 2 | 10 | 20..max" for integer |
| 78 | i.1. input -32768 |
| 79 | i.2. input 1 |
| 80 | i.3. input 2 |
| 81 | i.4. input 10 |
| 82 | i.5. input 20 |
| 83 | i.6. input 100 |
| 84 | i.7. input 32767 |
| 85 | |
| 86 | if range is "min .. 2 | 10 | 20..max" for uInteger |
| 87 | i.1. input 0 |
| 88 | i.2. input 1 |
| 89 | i.3. input 2 |
| 90 | i.4. input 10 |
| 91 | i.5. input 20 |
| 92 | i.6. input 100 |
| 93 | i.7. input 65535 |
| 94 | */ |
| 95 | |
| 96 | /** |
| 97 | * Creates and validates integer16 ydt covering different positive scenario. |
| 98 | */ |
| 99 | @Test |
| 100 | public void positiveTest() throws YdtException { |
| 101 | YangRequestWorkBench ydtBuilder = integer16Ydt(); |
| 102 | validateTree(ydtBuilder); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Validates the given built ydt. |
| 107 | */ |
| 108 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 109 | |
| 110 | // assign root node to ydtNode for validating purpose. |
| 111 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 112 | // Logical root node does not have operation type |
| 113 | validateNodeContents(ydtNode, TYPE, null); |
| 114 | |
| 115 | ydtNode = ydtNode.getFirstChild(); |
| 116 | validateNodeContents(ydtNode, "integer16", MERGE); |
| 117 | ydtNode = ydtNode.getFirstChild(); |
| 118 | validateLeafContents(ydtNode, "negInt", "-32768"); |
| 119 | ydtNode = ydtNode.getNextSibling(); |
| 120 | validateLeafContents(ydtNode, "posInt", "32767"); |
| 121 | ydtNode = ydtNode.getNextSibling(); |
| 122 | validateLeafContents(ydtNode, "minUInt", "0"); |
| 123 | ydtNode = ydtNode.getNextSibling(); |
| 124 | validateLeafContents(ydtNode, "maxUInt", "65535"); |
| 125 | ydtNode = ydtNode.getNextSibling(); |
| 126 | validateLeafContents(ydtNode, MIDIWR, "11"); |
| 127 | ydtNode = ydtNode.getNextSibling(); |
| 128 | validateLeafContents(ydtNode, MINIWR, "10"); |
| 129 | ydtNode = ydtNode.getNextSibling(); |
| 130 | validateLeafContents(ydtNode, MAXIWR, "100"); |
| 131 | ydtNode = ydtNode.getNextSibling(); |
| 132 | validateLeafContents(ydtNode, MIDUIWR, "11"); |
| 133 | ydtNode = ydtNode.getNextSibling(); |
| 134 | validateLeafContents(ydtNode, MINUIWR, "10"); |
| 135 | ydtNode = ydtNode.getNextSibling(); |
| 136 | validateLeafContents(ydtNode, MAXUIWR, "100"); |
| 137 | ydtNode = ydtNode.getNextSibling(); |
| 138 | validateNodeContents(ydtNode, MRV, MERGE); |
| 139 | ydtNode = ydtNode.getFirstChild(); |
| 140 | validateLeafContents(ydtNode, "integer", "11"); |
| 141 | ydtNode = ydtNode.getParent(); |
| 142 | ydtNode = ydtNode.getNextSibling(); |
| 143 | validateNodeContents(ydtNode, MRV, MERGE); |
| 144 | ydtNode = ydtNode.getFirstChild(); |
| 145 | validateLeafContents(ydtNode, "integer", "10"); |
| 146 | ydtNode = ydtNode.getParent(); |
| 147 | ydtNode = ydtNode.getNextSibling(); |
| 148 | validateNodeContents(ydtNode, MRV, MERGE); |
| 149 | ydtNode = ydtNode.getFirstChild(); |
| 150 | validateLeafContents(ydtNode, "integer", "40"); |
| 151 | ydtNode = ydtNode.getParent(); |
| 152 | ydtNode = ydtNode.getNextSibling(); |
| 153 | validateNodeContents(ydtNode, MRV, MERGE); |
| 154 | ydtNode = ydtNode.getFirstChild(); |
| 155 | validateLeafContents(ydtNode, "integer", "50"); |
| 156 | ydtNode = ydtNode.getParent(); |
| 157 | ydtNode = ydtNode.getNextSibling(); |
| 158 | validateNodeContents(ydtNode, MRV, MERGE); |
| 159 | ydtNode = ydtNode.getFirstChild(); |
| 160 | validateLeafContents(ydtNode, "integer", "55"); |
| 161 | ydtNode = ydtNode.getParent(); |
| 162 | ydtNode = ydtNode.getNextSibling(); |
| 163 | validateNodeContents(ydtNode, MRV, MERGE); |
| 164 | ydtNode = ydtNode.getFirstChild(); |
| 165 | validateLeafContents(ydtNode, "integer", "100"); |
| 166 | ydtNode = ydtNode.getParent(); |
| 167 | ydtNode = ydtNode.getNextSibling(); |
| 168 | validateNodeContents(ydtNode, MRV, MERGE); |
| 169 | ydtNode = ydtNode.getFirstChild(); |
| 170 | validateLeafContents(ydtNode, "UnInteger", "11"); |
| 171 | ydtNode = ydtNode.getParent(); |
| 172 | ydtNode = ydtNode.getNextSibling(); |
| 173 | validateNodeContents(ydtNode, MRV, MERGE); |
| 174 | ydtNode = ydtNode.getFirstChild(); |
| 175 | validateLeafContents(ydtNode, "UnInteger", "10"); |
| 176 | ydtNode = ydtNode.getParent(); |
| 177 | ydtNode = ydtNode.getNextSibling(); |
| 178 | validateNodeContents(ydtNode, MRV, MERGE); |
| 179 | ydtNode = ydtNode.getFirstChild(); |
| 180 | validateLeafContents(ydtNode, "UnInteger", "40"); |
| 181 | ydtNode = ydtNode.getParent(); |
| 182 | ydtNode = ydtNode.getNextSibling(); |
| 183 | validateNodeContents(ydtNode, MRV, MERGE); |
| 184 | ydtNode = ydtNode.getFirstChild(); |
| 185 | validateLeafContents(ydtNode, "UnInteger", "50"); |
| 186 | ydtNode = ydtNode.getParent(); |
| 187 | ydtNode = ydtNode.getNextSibling(); |
| 188 | validateNodeContents(ydtNode, MRV, MERGE); |
| 189 | ydtNode = ydtNode.getFirstChild(); |
| 190 | validateLeafContents(ydtNode, "UnInteger", "55"); |
| 191 | ydtNode = ydtNode.getParent(); |
| 192 | ydtNode = ydtNode.getNextSibling(); |
| 193 | validateNodeContents(ydtNode, MRV, MERGE); |
| 194 | ydtNode = ydtNode.getFirstChild(); |
| 195 | validateLeafContents(ydtNode, "UnInteger", "100"); |
| 196 | |
| 197 | ydtNode = ydtNode.getParent(); |
| 198 | ydtNode = ydtNode.getNextSibling(); |
| 199 | validateNodeContents(ydtNode, MRV, MERGE); |
| 200 | ydtNode = ydtNode.getFirstChild(); |
| 201 | validateLeafContents(ydtNode, "revInteger", "-32768"); |
| 202 | ydtNode = ydtNode.getParent(); |
| 203 | ydtNode = ydtNode.getNextSibling(); |
| 204 | validateNodeContents(ydtNode, MRV, MERGE); |
| 205 | ydtNode = ydtNode.getFirstChild(); |
| 206 | validateLeafContents(ydtNode, "revInteger", "1"); |
| 207 | ydtNode = ydtNode.getParent(); |
| 208 | ydtNode = ydtNode.getNextSibling(); |
| 209 | validateNodeContents(ydtNode, MRV, MERGE); |
| 210 | |
| 211 | validate1Tree(ydtNode); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Validates the given built ydt. |
| 216 | */ |
| 217 | private void validate1Tree(YdtNode ydtNode) { |
| 218 | |
| 219 | ydtNode = ydtNode.getFirstChild(); |
| 220 | validateLeafContents(ydtNode, "revInteger", "2"); |
| 221 | ydtNode = ydtNode.getParent(); |
| 222 | ydtNode = ydtNode.getNextSibling(); |
| 223 | validateNodeContents(ydtNode, MRV, MERGE); |
| 224 | ydtNode = ydtNode.getFirstChild(); |
| 225 | validateLeafContents(ydtNode, "revInteger", "10"); |
| 226 | ydtNode = ydtNode.getParent(); |
| 227 | ydtNode = ydtNode.getNextSibling(); |
| 228 | validateNodeContents(ydtNode, MRV, MERGE); |
| 229 | ydtNode = ydtNode.getFirstChild(); |
| 230 | validateLeafContents(ydtNode, "revInteger", "20"); |
| 231 | ydtNode = ydtNode.getParent(); |
| 232 | ydtNode = ydtNode.getNextSibling(); |
| 233 | validateNodeContents(ydtNode, MRV, MERGE); |
| 234 | ydtNode = ydtNode.getFirstChild(); |
| 235 | validateLeafContents(ydtNode, "revInteger", "100"); |
| 236 | ydtNode = ydtNode.getParent(); |
| 237 | ydtNode = ydtNode.getNextSibling(); |
| 238 | validateNodeContents(ydtNode, MRV, MERGE); |
| 239 | ydtNode = ydtNode.getFirstChild(); |
| 240 | validateLeafContents(ydtNode, "revInteger", "32767"); |
| 241 | |
| 242 | ydtNode = ydtNode.getParent(); |
| 243 | ydtNode = ydtNode.getNextSibling(); |
| 244 | validateNodeContents(ydtNode, MRV, MERGE); |
| 245 | ydtNode = ydtNode.getFirstChild(); |
| 246 | validateLeafContents(ydtNode, RUI, "0"); |
| 247 | ydtNode = ydtNode.getParent(); |
| 248 | ydtNode = ydtNode.getNextSibling(); |
| 249 | validateNodeContents(ydtNode, MRV, MERGE); |
| 250 | ydtNode = ydtNode.getFirstChild(); |
| 251 | validateLeafContents(ydtNode, RUI, "1"); |
| 252 | ydtNode = ydtNode.getParent(); |
| 253 | ydtNode = ydtNode.getNextSibling(); |
| 254 | validateNodeContents(ydtNode, MRV, MERGE); |
| 255 | ydtNode = ydtNode.getFirstChild(); |
| 256 | validateLeafContents(ydtNode, RUI, "2"); |
| 257 | ydtNode = ydtNode.getParent(); |
| 258 | ydtNode = ydtNode.getNextSibling(); |
| 259 | validateNodeContents(ydtNode, MRV, MERGE); |
| 260 | ydtNode = ydtNode.getFirstChild(); |
| 261 | validateLeafContents(ydtNode, RUI, "10"); |
| 262 | ydtNode = ydtNode.getParent(); |
| 263 | ydtNode = ydtNode.getNextSibling(); |
| 264 | validateNodeContents(ydtNode, MRV, MERGE); |
| 265 | ydtNode = ydtNode.getFirstChild(); |
| 266 | validateLeafContents(ydtNode, RUI, "20"); |
| 267 | ydtNode = ydtNode.getParent(); |
| 268 | ydtNode = ydtNode.getNextSibling(); |
| 269 | validateNodeContents(ydtNode, MRV, MERGE); |
| 270 | ydtNode = ydtNode.getFirstChild(); |
| 271 | validateLeafContents(ydtNode, RUI, "100"); |
| 272 | ydtNode = ydtNode.getParent(); |
| 273 | ydtNode = ydtNode.getNextSibling(); |
| 274 | validateNodeContents(ydtNode, MRV, MERGE); |
| 275 | ydtNode = ydtNode.getFirstChild(); |
| 276 | validateLeafContents(ydtNode, RUI, "65535"); |
| 277 | } |
| 278 | |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 279 | //TODO negative scenario will be handled later |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 280 | /* |
| 281 | Negative scenario |
| 282 | |
| 283 | wrong type input |
| 284 | i. input string instead of integer |
| 285 | ii. input string instead of uinteger |
| 286 | |
| 287 | input out of range |
| 288 | i. input for int 8 range -32768 to 32767 |
| 289 | i.1. input -32769 |
| 290 | i.2. input 32768 |
| 291 | |
| 292 | ii. input for uint 8 range 0 to 65535 |
| 293 | ii.1. input -32769 |
| 294 | ii.2. input 65536 |
| 295 | |
| 296 | input out of range parameter |
| 297 | if range is 10 to 100 for int |
| 298 | i.1. input 9 |
| 299 | i.2. input 101 |
| 300 | |
| 301 | if range is 10 to 100 for uInt |
| 302 | i.1. input 9 |
| 303 | i.2. input 101 |
| 304 | |
| 305 | input with multi interval range |
| 306 | if range is 10..40 | 50..100 for integer |
| 307 | i.1. input 9 |
| 308 | i.2. input 41 |
| 309 | i.3. input 49 |
| 310 | i.4. input 101 |
| 311 | |
| 312 | if range is 10..40 | 50..100 for uinteger |
| 313 | i.1. input 9 |
| 314 | i.2. input 41 |
| 315 | i.3. input 49 |
| 316 | i.4. input 101 |
| 317 | |
| 318 | input with multi interval range |
| 319 | if range is min .. | 10 | 20..max for integer |
| 320 | i.1. input -32769 |
| 321 | i.2. input 4 |
| 322 | i.3. input 9 |
| 323 | i.4. input 11 |
| 324 | i.5. input 19 |
| 325 | i.6. input 32768 |
| 326 | |
| 327 | if range is min .. 3 | 10 | 20..max for uinteger |
| 328 | i.1. input -32769 |
| 329 | i.2. input 4 |
| 330 | i.3. input 9 |
| 331 | i.4. input 11 |
| 332 | i.5. input 19 |
| 333 | i.6. input 65536 |
| 334 | |
| 335 | */ |
| 336 | |
| 337 | /** |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 338 | * Tests all the minimum and maximum value's negative scenario's for |
| 339 | * signed integer16 data type. |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 340 | */ |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 341 | // @Test |
| 342 | // public void negative1Test() throws YdtException { |
| 343 | // validateErrMsg("posInt", INT16NS, "integer", SINT16, null); |
| 344 | // validateErrMsg("posInt", INT16NS, "127.0", SINT16, null); |
| 345 | // validateErrMsg("negInt", INT16NS, "-32769", SINT16, null); |
| 346 | // validateErrMsg("posInt", INT16NS, "32768", SINT16, null); |
| 347 | // validateErrMsg(MINIWR, INT16NS, "9", CAPSINT16, null); |
| 348 | // validateErrMsg(MAXIWR, INT16NS, "101", CAPSINT16, null); |
| 349 | // } |
| 350 | // |
| 351 | // /** |
| 352 | // * Tests all the minimum and maximum value's negative scenario's for |
| 353 | // * unsigned integer16 data type. |
| 354 | // */ |
| 355 | // @Test |
| 356 | // public void negative2Test() throws YdtException { |
| 357 | // validateErrMsg("maxUInt", INT16NS, "integer", SUINT16, null); |
| 358 | // validateErrMsg("maxUInt", INT16NS, "127.0", SUINT16, null); |
| 359 | // validateErrMsg("minUInt", INT16NS, "-32769", MINVALUE, null); |
| 360 | // validateErrMsg("maxUInt", INT16NS, "65536", MAXUINT16, null); |
| 361 | // validateErrMsg(MINUIWR, INT16NS, "9", CAPSUINT16, null); |
| 362 | // validateErrMsg(MAXUIWR, INT16NS, "101", CAPSUINT16, null); |
| 363 | // } |
| 364 | // |
| 365 | // /** |
| 366 | // * Tests all possible negative scenario's for signed integer16 data type |
| 367 | // * with range "10..40 | 50..100". |
| 368 | // */ |
| 369 | // @Test |
| 370 | // public void negative3Test() throws YdtException { |
| 371 | // validateErrMsg("integer", INT16NS, "9", CAPSINT16, MRV); |
| 372 | // validateErrMsg("integer", INT16NS, "41", CAPSINT16, MRV); |
| 373 | // validateErrMsg("integer", INT16NS, "49", CAPSINT16, MRV); |
| 374 | // validateErrMsg("integer", INT16NS, "101", CAPSINT16, MRV); |
| 375 | // } |
| 376 | // |
| 377 | // /** |
| 378 | // * Tests all possible negative scenario's for unsigned integer16 data type |
| 379 | // * with range "10..40 | 50..100". |
| 380 | // */ |
| 381 | // @Test |
| 382 | // public void negative4Test() throws YdtException { |
| 383 | // validateErrMsg("UnInteger", INT16NS, "9", CAPSUINT16, MRV); |
| 384 | // validateErrMsg("UnInteger", INT16NS, "41", CAPSUINT16, MRV); |
| 385 | // validateErrMsg("UnInteger", INT16NS, "49", CAPSUINT16, MRV); |
| 386 | // validateErrMsg("UnInteger", INT16NS, "101", CAPSUINT16, MRV); |
| 387 | // } |
| 388 | // |
| 389 | // /** |
| 390 | // * Tests all possible negative scenario's for signed integer16 data type |
| 391 | // * with range "min .. 2 | 10 | 20..max". |
| 392 | // */ |
| 393 | // @Test |
| 394 | // public void negative5Test() throws YdtException { |
| 395 | // // multi range validation |
| 396 | // validateErrMsg("revInteger", INT16NS, "-32769", SINT16, MRV); |
| 397 | // validateErrMsg("revInteger", INT16NS, "19", CAPSINT16, MRV); |
| 398 | // validateErrMsg("revInteger", INT16NS, "4", CAPSINT16, MRV); |
| 399 | // validateErrMsg("revInteger", INT16NS, "32768", SINT16, MRV); |
| 400 | // validateErrMsg("revInteger", INT16NS, "9", CAPSINT16, MRV); |
| 401 | // validateErrMsg("revInteger", INT16NS, "11", CAPSINT16, MRV); |
| 402 | // } |
| 403 | // |
| 404 | // /** |
| 405 | // * Tests all possible negative scenario's for unsigned integer16 data type |
| 406 | // * with range "min .. 2 | 10 | 20..max". |
| 407 | // */ |
| 408 | // @Test |
| 409 | // public void negative6Test() throws YdtException { |
| 410 | // // multi range validation |
| 411 | // validateErrMsg(RUI, INT16NS, "-32769", MINVALUE, MRV); |
| 412 | // validateErrMsg(RUI, INT16NS, "4", CAPSUINT16, MRV); |
| 413 | // validateErrMsg(RUI, INT16NS, "9", CAPSUINT16, MRV); |
| 414 | // validateErrMsg(RUI, INT16NS, "11", CAPSUINT16, MRV); |
| 415 | // validateErrMsg(RUI, INT16NS, "19", CAPSUINT16, MRV); |
| 416 | // validateErrMsg(RUI, INT16NS, "65536", MAXUINT16, MRV); |
| 417 | // } |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 418 | } |