Vidyashree Rama | 76faccc | 2016-10-17 22:06:52 +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.yab; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yangutils.datamodel.YangAugment; |
| 21 | import org.onosproject.yangutils.datamodel.YangNode; |
| 22 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 23 | import org.onosproject.yms.app.ydt.YdtAppContext; |
| 24 | import org.onosproject.yms.app.ydt.YdtAppNodeOperationType; |
| 25 | import org.onosproject.yms.app.ydt.YdtNode; |
| 26 | import org.onosproject.yms.ydt.YdtContext; |
| 27 | |
| 28 | import java.io.IOException; |
| 29 | import java.util.HashSet; |
| 30 | import java.util.List; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 34 | import static org.hamcrest.CoreMatchers.nullValue; |
| 35 | import static org.hamcrest.MatcherAssert.assertThat; |
| 36 | import static org.hamcrest.core.Is.is; |
| 37 | import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE; |
| 38 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 39 | import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST; |
| 40 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST; |
| 41 | import static org.onosproject.yms.ydt.YmsOperationType.RPC_REQUEST; |
| 42 | |
| 43 | /** |
| 44 | * Unit test case for YANG application broker. |
| 45 | */ |
| 46 | public class YangApplicationBrokerTest { |
| 47 | |
| 48 | MockYmsManager ymsManager = new MockYmsManager(); |
| 49 | |
| 50 | /** |
| 51 | * Returns YANG data tree to check edit operation of container. |
| 52 | * |
| 53 | * @return YANG data tree |
| 54 | */ |
| 55 | private YangRequestWorkBench buildYdtForEditOperationWithoutDelete() { |
| 56 | String rootName = "root"; |
| 57 | YangRequestWorkBench defaultYdtBuilder = |
| 58 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 59 | EDIT_CONFIG_REQUEST); |
| 60 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 61 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 62 | defaultYdtBuilder.addChild("cont2", null, MERGE); |
| 63 | defaultYdtBuilder.addChild("cont3", null, MERGE); |
| 64 | defaultYdtBuilder.addLeaf("leaf1", null, "1"); |
| 65 | defaultYdtBuilder.traverseToParent(); |
| 66 | defaultYdtBuilder.traverseToParent(); |
| 67 | defaultYdtBuilder.traverseToParent(); |
| 68 | defaultYdtBuilder.addLeaf("leaf4", null, "4"); |
| 69 | defaultYdtBuilder.traverseToParent(); |
| 70 | defaultYdtBuilder.traverseToParent(); |
| 71 | defaultYdtBuilder.addChild("cont4", null, MERGE); |
| 72 | defaultYdtBuilder.addChild("cont5", null, MERGE); |
| 73 | defaultYdtBuilder.addLeaf("leaf9", null, "9"); |
| 74 | defaultYdtBuilder.traverseToParent(); |
| 75 | defaultYdtBuilder.traverseToParent(); |
| 76 | defaultYdtBuilder.traverseToParent(); |
| 77 | defaultYdtBuilder.addLeaf("leaf10", null, "10"); |
| 78 | return defaultYdtBuilder; |
| 79 | } |
| 80 | |
| 81 | private YangRequestWorkBench buildYdtForKeyLeavesInDeleteTree() { |
| 82 | String rootName = "root"; |
| 83 | YangRequestWorkBench defaultYdtBuilder = |
| 84 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 85 | EDIT_CONFIG_REQUEST); |
| 86 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 87 | defaultYdtBuilder.addChild("list2", null, MERGE); |
| 88 | defaultYdtBuilder.addLeaf("leaf5", null, "5"); |
| 89 | defaultYdtBuilder.traverseToParent(); |
| 90 | defaultYdtBuilder.addLeaf("leaf6", null, "6"); |
| 91 | defaultYdtBuilder.traverseToParent(); |
| 92 | defaultYdtBuilder.addLeaf("leaf7", null, "7"); |
| 93 | defaultYdtBuilder.traverseToParent(); |
| 94 | defaultYdtBuilder.addChild("cont7", null, DELETE); |
| 95 | defaultYdtBuilder.traverseToParent(); |
| 96 | defaultYdtBuilder.traverseToParent(); |
| 97 | return defaultYdtBuilder; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns YANG data tree to check delete operation of container. |
| 102 | * |
| 103 | * @return YANG data tree |
| 104 | */ |
| 105 | private YangRequestWorkBench buildYdtForEditOperationWithDelete() { |
| 106 | String rootName = "rootNode"; |
| 107 | YangRequestWorkBench defaultYdtBuilder = |
| 108 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 109 | EDIT_CONFIG_REQUEST); |
| 110 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 111 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 112 | defaultYdtBuilder.addChild("cont2", null, DELETE); |
| 113 | defaultYdtBuilder.addChild("cont3", null, DELETE); |
| 114 | defaultYdtBuilder.addLeaf("leaf1", null, "1"); |
| 115 | defaultYdtBuilder.traverseToParent(); |
| 116 | defaultYdtBuilder.traverseToParent(); |
| 117 | defaultYdtBuilder.traverseToParent(); |
| 118 | defaultYdtBuilder.addLeaf("leaf4", null, "4"); |
| 119 | defaultYdtBuilder.traverseToParent(); |
| 120 | defaultYdtBuilder.traverseToParent(); |
| 121 | defaultYdtBuilder.addChild("cont4", null, DELETE); |
| 122 | defaultYdtBuilder.addChild("cont5", null, DELETE); |
| 123 | defaultYdtBuilder.addLeaf("leaf9", null, "9"); |
| 124 | defaultYdtBuilder.traverseToParent(); |
| 125 | defaultYdtBuilder.traverseToParent(); |
| 126 | defaultYdtBuilder.traverseToParent(); |
| 127 | defaultYdtBuilder.addLeaf("leaf10", null, "10"); |
| 128 | return defaultYdtBuilder; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns YANG data tree to check edit operation of list. |
| 133 | * |
| 134 | * @return YANG data tree |
| 135 | */ |
| 136 | private YangRequestWorkBench buildYdtForListEditOperationWithoutDelete() { |
| 137 | String rootName = "listWithoutDelete"; |
| 138 | Set<String> valueSet = new HashSet<>(); |
| 139 | valueSet.add("10"); |
| 140 | YangRequestWorkBench defaultYdtBuilder = |
| 141 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 142 | EDIT_CONFIG_REQUEST); |
| 143 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 144 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 145 | defaultYdtBuilder.addChild("list1", null, MERGE); |
| 146 | defaultYdtBuilder.addLeaf("leaf2", null, "2"); |
| 147 | defaultYdtBuilder.traverseToParent(); |
| 148 | defaultYdtBuilder.addLeaf("leaf3", null, "3"); |
| 149 | defaultYdtBuilder.traverseToParent(); |
| 150 | defaultYdtBuilder.traverseToParent(); |
| 151 | defaultYdtBuilder.addLeaf("leaf4", null, "4"); |
| 152 | defaultYdtBuilder.traverseToParent(); |
| 153 | defaultYdtBuilder.traverseToParent(); |
| 154 | defaultYdtBuilder.addChild("list2", null, MERGE); |
| 155 | defaultYdtBuilder.addLeaf("leaf5", null, "5"); |
| 156 | defaultYdtBuilder.traverseToParent(); |
| 157 | defaultYdtBuilder.addLeaf("leaf6", null, "6"); |
| 158 | defaultYdtBuilder.traverseToParent(); |
| 159 | defaultYdtBuilder.addLeaf("leaf7", null, "7"); |
| 160 | defaultYdtBuilder.traverseToParent(); |
| 161 | defaultYdtBuilder.addLeaf("leaflist8", null, valueSet); |
| 162 | defaultYdtBuilder.traverseToParent(); |
| 163 | defaultYdtBuilder.traverseToParent(); |
| 164 | defaultYdtBuilder.addLeaf("leaf10", null, "10"); |
| 165 | return defaultYdtBuilder; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Returns YANG data tree to check delete operation of list. |
| 170 | * |
| 171 | * @return YANG data tree |
| 172 | */ |
| 173 | private YangRequestWorkBench buildYdtForListEditOperationWithDelete() { |
| 174 | String rootName = "listWithDelete"; |
| 175 | YangRequestWorkBench defaultYdtBuilder = |
| 176 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 177 | EDIT_CONFIG_REQUEST); |
| 178 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 179 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 180 | defaultYdtBuilder.addChild("list1", null, DELETE); |
| 181 | defaultYdtBuilder.addLeaf("leaf2", null, "2"); |
| 182 | defaultYdtBuilder.traverseToParent(); |
| 183 | defaultYdtBuilder.addLeaf("leaf3", null, "3"); |
| 184 | defaultYdtBuilder.traverseToParent(); |
| 185 | defaultYdtBuilder.traverseToParent(); |
| 186 | defaultYdtBuilder.addLeaf("leaf4", null, "4"); |
| 187 | defaultYdtBuilder.traverseToParent(); |
| 188 | defaultYdtBuilder.traverseToParent(); |
| 189 | defaultYdtBuilder.addChild("list2", null, DELETE); |
| 190 | defaultYdtBuilder.addLeaf("leaf5", null, "5"); |
| 191 | defaultYdtBuilder.traverseToParent(); |
| 192 | defaultYdtBuilder.addLeaf("leaf6", null, "6"); |
| 193 | defaultYdtBuilder.traverseToParent(); |
| 194 | defaultYdtBuilder.traverseToParent(); |
| 195 | defaultYdtBuilder.addLeaf("leaf10", null, "10"); |
| 196 | return defaultYdtBuilder; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Returns YANG data tree to check query operation of container. |
| 201 | * |
| 202 | * @return YANG data tree |
| 203 | */ |
| 204 | private YangRequestWorkBench buildYdtForQueryOperation() { |
| 205 | String rootName = "root"; |
| 206 | YangRequestWorkBench defaultYdtBuilder = |
| 207 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 208 | QUERY_CONFIG_REQUEST); |
| 209 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 210 | defaultYdtBuilder.addChild("cont1", null); |
| 211 | defaultYdtBuilder.addChild("cont2", null); |
| 212 | defaultYdtBuilder.addChild("cont3", null); |
| 213 | defaultYdtBuilder.traverseToParent(); |
| 214 | defaultYdtBuilder.traverseToParent(); |
| 215 | defaultYdtBuilder.traverseToParent(); |
| 216 | defaultYdtBuilder.addChild("cont4", null); |
| 217 | defaultYdtBuilder.addChild("cont5", null); |
| 218 | return defaultYdtBuilder; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Returns YANG data tree to check query operation of list. |
| 223 | * |
| 224 | * @return YANG data tree |
| 225 | */ |
| 226 | private YangRequestWorkBench buildYdtForListQueryOperation() { |
| 227 | String rootName = "listQuery"; |
| 228 | YangRequestWorkBench defaultYdtBuilder = |
| 229 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 230 | QUERY_CONFIG_REQUEST); |
| 231 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 232 | defaultYdtBuilder.addChild("cont1", null); |
| 233 | defaultYdtBuilder.addChild("list1", null); |
| 234 | defaultYdtBuilder.addLeaf("leaf2", null, "2"); |
| 235 | defaultYdtBuilder.traverseToParent(); |
| 236 | defaultYdtBuilder.traverseToParent(); |
| 237 | defaultYdtBuilder.traverseToParent(); |
| 238 | defaultYdtBuilder.addChild("list2", null); |
| 239 | defaultYdtBuilder.addLeaf("leaf5", null, "5"); |
| 240 | defaultYdtBuilder.traverseToParent(); |
| 241 | defaultYdtBuilder.addLeaf("leaf6", null, "6"); |
| 242 | return defaultYdtBuilder; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Returns YANG data tree to check delete operation of a node. |
| 247 | * |
| 248 | * @return YANG data tree |
| 249 | */ |
| 250 | private YangRequestWorkBench buildYdtWithOneDeleteNode() { |
| 251 | String rootName = "root"; |
| 252 | YangRequestWorkBench defaultYdtBuilder = |
| 253 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 254 | EDIT_CONFIG_REQUEST); |
| 255 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 256 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 257 | defaultYdtBuilder.traverseToParent(); |
| 258 | defaultYdtBuilder.addChild("cont4", null, DELETE); |
| 259 | defaultYdtBuilder.traverseToParent(); |
| 260 | defaultYdtBuilder.addLeaf("leaf10", null, "10"); |
| 261 | return defaultYdtBuilder; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Returns YANG data tree to check delete operation of last node. |
| 266 | * |
| 267 | * @return YANG data tree |
| 268 | */ |
| 269 | private YangRequestWorkBench buildYdtWithDeleteNodeAsLastChild() { |
| 270 | String rootName = "root"; |
| 271 | YangRequestWorkBench defaultYdtBuilder = |
| 272 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 273 | EDIT_CONFIG_REQUEST); |
| 274 | defaultYdtBuilder.addChild("test", "ydt.test", MERGE); |
| 275 | defaultYdtBuilder.addChild("cont1", null, MERGE); |
| 276 | defaultYdtBuilder.traverseToParent(); |
| 277 | defaultYdtBuilder.addChild("list2", null, MERGE); |
| 278 | defaultYdtBuilder.addLeaf("leaf5", null, "10"); |
| 279 | defaultYdtBuilder.traverseToParent(); |
| 280 | defaultYdtBuilder.addLeaf("leaf6", null, "10"); |
| 281 | defaultYdtBuilder.traverseToParent(); |
| 282 | defaultYdtBuilder.traverseToParent(); |
| 283 | defaultYdtBuilder.addChild("cont4", null, DELETE); |
| 284 | return defaultYdtBuilder; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Returns YANG data tree to with delete operation of all the nodes. |
| 289 | * |
| 290 | * @return YANG data tree |
| 291 | */ |
| 292 | private YangRequestWorkBench buildYdtWithAllDeleteNode() { |
| 293 | String rootName = "root"; |
| 294 | YangRequestWorkBench defaultYdtBuilder = |
| 295 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 296 | EDIT_CONFIG_REQUEST); |
| 297 | defaultYdtBuilder.addChild("test", "ydt.test", DELETE); |
| 298 | defaultYdtBuilder.addChild("cont1", null, DELETE); |
| 299 | defaultYdtBuilder.traverseToParent(); |
| 300 | defaultYdtBuilder.addChild("list2", null, DELETE); |
| 301 | defaultYdtBuilder.addLeaf("leaf5", null, "10"); |
| 302 | defaultYdtBuilder.traverseToParent(); |
| 303 | defaultYdtBuilder.addLeaf("leaf6", null, "10"); |
| 304 | defaultYdtBuilder.traverseToParent(); |
| 305 | defaultYdtBuilder.traverseToParent(); |
| 306 | defaultYdtBuilder.addChild("cont4", null, DELETE); |
| 307 | return defaultYdtBuilder; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Returns YANG data tree to check rpc operation with only input. |
| 312 | * |
| 313 | * @return YANG data tree |
| 314 | */ |
| 315 | private YangRequestWorkBench buildYdtForRpcWithOnlyInput() { |
| 316 | String rootName = "root"; |
| 317 | YangRequestWorkBench defaultYdtBuilder = |
| 318 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 319 | RPC_REQUEST); |
| 320 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 321 | defaultYdtBuilder.addChild("rock-the-house1", null); |
| 322 | defaultYdtBuilder.addChild("input", null); |
| 323 | defaultYdtBuilder.addLeaf("leaf13", null, "5"); |
| 324 | defaultYdtBuilder.traverseToParent(); |
| 325 | defaultYdtBuilder.traverseToParent(); |
| 326 | defaultYdtBuilder.traverseToParent(); |
| 327 | defaultYdtBuilder.traverseToParent(); |
| 328 | return defaultYdtBuilder; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Returns YANG data tree to check rpc operation with only output. |
| 333 | * |
| 334 | * @return YANG data tree |
| 335 | */ |
| 336 | private YangRequestWorkBench buildYdtForRpcWithOnlyOutput() { |
| 337 | String rootName = "root"; |
| 338 | YangRequestWorkBench defaultYdtBuilder = |
| 339 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 340 | RPC_REQUEST); |
| 341 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 342 | defaultYdtBuilder.addChild("rock-the-house2", null); |
| 343 | defaultYdtBuilder.addChild("output", null); |
| 344 | defaultYdtBuilder.addLeaf("leaf14", null, "14"); |
| 345 | defaultYdtBuilder.traverseToParent(); |
| 346 | defaultYdtBuilder.traverseToParent(); |
| 347 | defaultYdtBuilder.traverseToParent(); |
| 348 | defaultYdtBuilder.traverseToParent(); |
| 349 | return defaultYdtBuilder; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Returns YANG data tree to check rpc operation with both input and output. |
| 354 | * |
| 355 | * @return YANG data tree |
| 356 | */ |
| 357 | private YangRequestWorkBench buildYdtForRpcWithBothInputOutput() { |
| 358 | String rootName = "root"; |
| 359 | YangRequestWorkBench defaultYdtBuilder = |
| 360 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 361 | RPC_REQUEST); |
| 362 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 363 | defaultYdtBuilder.addChild("rock-the-house", null); |
| 364 | defaultYdtBuilder.addChild("input", null); |
| 365 | defaultYdtBuilder.addLeaf("zip-code", null, "5"); |
| 366 | defaultYdtBuilder.traverseToParent(); |
| 367 | defaultYdtBuilder.traverseToParent(); |
| 368 | defaultYdtBuilder.addChild("output", null); |
| 369 | defaultYdtBuilder.addLeaf("hello", null, "5"); |
| 370 | defaultYdtBuilder.traverseToParent(); |
| 371 | defaultYdtBuilder.traverseToParent(); |
| 372 | defaultYdtBuilder.traverseToParent(); |
| 373 | defaultYdtBuilder.traverseToParent(); |
| 374 | return defaultYdtBuilder; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Returns YANG data tree to check rpc operation. |
| 379 | * |
| 380 | * @return YANG data tree |
| 381 | */ |
| 382 | private YangRequestWorkBench buildYdtForRpc() { |
| 383 | String rootName = "root"; |
| 384 | YangRequestWorkBench defaultYdtBuilder = |
| 385 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 386 | RPC_REQUEST); |
| 387 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 388 | defaultYdtBuilder.addChild("rock-the-house3", null); |
| 389 | defaultYdtBuilder.traverseToParent(); |
| 390 | defaultYdtBuilder.traverseToParent(); |
| 391 | return defaultYdtBuilder; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Returns YANG data tree to check query operation with multiple level of |
| 396 | * augment. |
| 397 | * |
| 398 | * @return YANG data tree |
| 399 | */ |
| 400 | private YangRequestWorkBench buildYdtForQueryWithMultipleAugment() { |
| 401 | String rootName = "root"; |
| 402 | YangRequestWorkBench defaultYdtBuilder = |
| 403 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 404 | QUERY_CONFIG_REQUEST); |
| 405 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 406 | defaultYdtBuilder.traverseToParent(); |
| 407 | return defaultYdtBuilder; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Returns YANG data tree to check delete operation with multiple level of |
| 412 | * augment. |
| 413 | * |
| 414 | * @return YANG data tree |
| 415 | */ |
| 416 | private YangRequestWorkBench buildYdtForDeleteWithMultipleAugment() { |
| 417 | String rootName = "root"; |
| 418 | YangRequestWorkBench defaultYdtBuilder = |
| 419 | (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null, |
| 420 | EDIT_CONFIG_REQUEST); |
| 421 | defaultYdtBuilder.addChild("test", "ydt.test"); |
| 422 | defaultYdtBuilder.addChild("cont4", null, DELETE); |
| 423 | defaultYdtBuilder.traverseToParent(); |
| 424 | defaultYdtBuilder.traverseToParent(); |
| 425 | return defaultYdtBuilder; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Checks whether YANG data tree and delete tree is correct. |
| 430 | */ |
| 431 | @Test |
| 432 | public void validateDeleteTreeOnlyOneNodeInDeleteList() |
| 433 | throws IOException, CloneNotSupportedException { |
| 434 | YangRequestWorkBench defaultYdtBuilder = |
| 435 | buildYdtForEditOperationWithDelete(); |
| 436 | YdtAppContext appContext = |
| 437 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 438 | YdtContext ydtContext = appContext.getModuleContext(); |
| 439 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 440 | |
| 441 | YdtContext cont1YdtContext; |
| 442 | YdtContext cont2YdtContext; |
| 443 | YdtContext cont3YdtContext; |
| 444 | YdtContext cont4YdtContext; |
| 445 | YdtContext deleteTree; |
| 446 | |
| 447 | // verify whether ydt tree is correct |
| 448 | assertThat(ydtContext.getName(), is("test")); |
| 449 | |
| 450 | cont1YdtContext = ydtContext.getFirstChild(); |
| 451 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 452 | |
| 453 | cont2YdtContext = cont1YdtContext.getFirstChild(); |
| 454 | assertThat(cont2YdtContext.getName(), is("cont2")); |
| 455 | |
| 456 | cont3YdtContext = cont2YdtContext.getFirstChild(); |
| 457 | assertThat(cont3YdtContext.getName(), is("cont3")); |
| 458 | |
| 459 | ydtContext = cont3YdtContext.getFirstChild(); |
| 460 | assertThat(ydtContext.getName(), is("leaf1")); |
| 461 | assertThat(ydtContext.getValue(), is("1")); |
| 462 | |
| 463 | ydtContext = cont2YdtContext.getNextSibling(); |
| 464 | assertThat(ydtContext.getName(), is("leaf4")); |
| 465 | assertThat(ydtContext.getValue(), is("4")); |
| 466 | |
| 467 | cont4YdtContext = cont1YdtContext.getNextSibling(); |
| 468 | assertThat(cont4YdtContext.getName(), is("cont4")); |
| 469 | |
| 470 | ydtContext = cont4YdtContext.getFirstChild(); |
| 471 | assertThat(ydtContext.getName(), is("cont5")); |
| 472 | |
| 473 | ydtContext = ydtContext.getFirstChild(); |
| 474 | assertThat(ydtContext.getName(), is("leaf9")); |
| 475 | assertThat(ydtContext.getValue(), is("9")); |
| 476 | |
| 477 | ydtContext = cont4YdtContext.getNextSibling(); |
| 478 | assertThat(ydtContext.getName(), is("leaf10")); |
| 479 | assertThat(ydtContext.getValue(), is("10")); |
| 480 | |
| 481 | // build delete tree |
| 482 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 483 | deleteTree = yab.buildDeleteTree(deleteNodes); |
| 484 | |
| 485 | // verify whether delete ydt tree is correct |
| 486 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 487 | |
| 488 | cont1YdtContext = deleteTree.getFirstChild().getFirstChild(); |
| 489 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 490 | |
| 491 | cont2YdtContext = cont1YdtContext.getFirstChild(); |
| 492 | assertThat(cont2YdtContext.getName(), is("cont2")); |
| 493 | |
| 494 | cont3YdtContext = cont2YdtContext.getFirstChild(); |
| 495 | assertThat(cont3YdtContext.getName(), is("cont3")); |
| 496 | |
| 497 | ydtContext = cont3YdtContext.getFirstChild(); |
| 498 | assertThat(ydtContext.getName(), is("leaf1")); |
| 499 | assertThat(ydtContext.getValue(), is("1")); |
| 500 | |
| 501 | assertThat(cont2YdtContext.getNextSibling(), nullValue()); |
| 502 | |
| 503 | cont4YdtContext = cont1YdtContext.getNextSibling(); |
| 504 | assertThat(cont4YdtContext.getName(), is("cont4")); |
| 505 | |
| 506 | ydtContext = cont4YdtContext.getFirstChild(); |
| 507 | assertThat(ydtContext.getName(), is("cont5")); |
| 508 | |
| 509 | ydtContext = ydtContext.getFirstChild(); |
| 510 | assertThat(ydtContext.getName(), is("leaf9")); |
| 511 | assertThat(ydtContext.getValue(), is("9")); |
| 512 | |
| 513 | assertThat(cont4YdtContext.getNextSibling(), nullValue()); |
| 514 | |
| 515 | // ydtTree after removing delete nodes |
| 516 | ydtContext = appContext.getModuleContext(); |
| 517 | assertThat(ydtContext.getName(), is("test")); |
| 518 | |
| 519 | cont1YdtContext = ydtContext.getFirstChild(); |
| 520 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 521 | |
| 522 | ydtContext = cont1YdtContext.getFirstChild(); |
| 523 | assertThat(ydtContext.getName(), is("leaf4")); |
| 524 | assertThat(ydtContext.getValue(), is("4")); |
| 525 | |
| 526 | ydtContext = cont1YdtContext.getNextSibling(); |
| 527 | assertThat(ydtContext.getName(), is("leaf10")); |
| 528 | assertThat(ydtContext.getValue(), is("10")); |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * Checks whether YANG data tree and delete tree is correct. |
| 533 | */ |
| 534 | @Test |
| 535 | public void validateListDeleteTree() |
| 536 | throws IOException, CloneNotSupportedException { |
| 537 | YangRequestWorkBench defaultYdtBuilder = |
| 538 | buildYdtForListEditOperationWithDelete(); |
| 539 | YdtAppContext appContext = |
| 540 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 541 | YdtContext ydtContext = appContext.getModuleContext(); |
| 542 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 543 | |
| 544 | YdtContext cont1YdtContext; |
| 545 | YdtContext list1YdtContext; |
| 546 | YdtContext list2YdtContext; |
| 547 | YdtContext deleteTree; |
| 548 | |
| 549 | // verify whether ydt tree is correct |
| 550 | assertThat(ydtContext.getName(), is("test")); |
| 551 | |
| 552 | cont1YdtContext = ydtContext.getFirstChild(); |
| 553 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 554 | |
| 555 | list1YdtContext = cont1YdtContext.getFirstChild(); |
| 556 | assertThat(list1YdtContext.getName(), is("list1")); |
| 557 | |
| 558 | ydtContext = list1YdtContext.getFirstChild(); |
| 559 | assertThat(ydtContext.getName(), is("leaf2")); |
| 560 | assertThat(ydtContext.getValue(), is("2")); |
| 561 | |
| 562 | ydtContext = ydtContext.getNextSibling(); |
| 563 | assertThat(ydtContext.getName(), is("leaf3")); |
| 564 | assertThat(ydtContext.getValue(), is("3")); |
| 565 | |
| 566 | ydtContext = list1YdtContext.getNextSibling(); |
| 567 | assertThat(ydtContext.getName(), is("leaf4")); |
| 568 | assertThat(ydtContext.getValue(), is("4")); |
| 569 | |
| 570 | list2YdtContext = cont1YdtContext.getNextSibling(); |
| 571 | assertThat(list2YdtContext.getName(), is("list2")); |
| 572 | |
| 573 | ydtContext = list2YdtContext.getFirstChild(); |
| 574 | assertThat(ydtContext.getName(), is("leaf5")); |
| 575 | assertThat(ydtContext.getValue(), is("5")); |
| 576 | |
| 577 | ydtContext = ydtContext.getNextSibling(); |
| 578 | assertThat(ydtContext.getName(), is("leaf6")); |
| 579 | assertThat(ydtContext.getValue(), is("6")); |
| 580 | |
| 581 | ydtContext = list2YdtContext.getNextSibling(); |
| 582 | assertThat(ydtContext.getName(), is("leaf10")); |
| 583 | assertThat(ydtContext.getValue(), is("10")); |
| 584 | |
| 585 | // build delete tree |
| 586 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 587 | deleteTree = yab.buildDeleteTree(deleteNodes); |
| 588 | |
| 589 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 590 | |
| 591 | cont1YdtContext = deleteTree.getFirstChild().getFirstChild(); |
| 592 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 593 | |
| 594 | list1YdtContext = cont1YdtContext.getFirstChild(); |
| 595 | assertThat(list1YdtContext.getName(), is("list1")); |
| 596 | |
| 597 | ydtContext = list1YdtContext.getFirstChild(); |
| 598 | assertThat(ydtContext.getName(), is("leaf2")); |
| 599 | assertThat(ydtContext.getValue(), is("2")); |
| 600 | |
| 601 | ydtContext = ydtContext.getNextSibling(); |
| 602 | assertThat(ydtContext.getName(), is("leaf3")); |
| 603 | assertThat(ydtContext.getValue(), is("3")); |
| 604 | |
| 605 | assertThat(list1YdtContext.getNextSibling(), nullValue()); |
| 606 | |
| 607 | list2YdtContext = cont1YdtContext.getNextSibling(); |
| 608 | assertThat(list2YdtContext.getName(), is("list2")); |
| 609 | |
| 610 | ydtContext = list2YdtContext.getFirstChild(); |
| 611 | assertThat(ydtContext.getName(), is("leaf5")); |
| 612 | assertThat(ydtContext.getValue(), is("5")); |
| 613 | |
| 614 | ydtContext = ydtContext.getNextSibling(); |
| 615 | assertThat(ydtContext.getName(), is("leaf6")); |
| 616 | assertThat(ydtContext.getValue(), is("6")); |
| 617 | |
| 618 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 619 | |
| 620 | // verify whether ydt tree is correct |
| 621 | ydtContext = appContext.getModuleContext(); |
| 622 | assertThat(ydtContext.getName(), is("test")); |
| 623 | |
| 624 | cont1YdtContext = ydtContext.getFirstChild(); |
| 625 | assertThat(cont1YdtContext.getName(), is("cont1")); |
| 626 | |
| 627 | ydtContext = cont1YdtContext.getFirstChild(); |
| 628 | assertThat(ydtContext.getName(), is("leaf4")); |
| 629 | assertThat(ydtContext.getValue(), is("4")); |
| 630 | |
| 631 | ydtContext = cont1YdtContext.getNextSibling(); |
| 632 | assertThat(ydtContext.getName(), is("leaf10")); |
| 633 | assertThat(ydtContext.getValue(), is("10")); |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Checks whether there is no exception when there is valid edit |
| 638 | * request. |
| 639 | */ |
| 640 | @Test |
| 641 | public void testExecuteEditOperationWithoutDelete() |
| 642 | throws IOException, CloneNotSupportedException { |
| 643 | YangRequestWorkBench defaultYdtBuilder = |
| 644 | buildYdtForEditOperationWithoutDelete(); |
| 645 | ymsManager.executeOperation(defaultYdtBuilder); |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Checks whether there is no exception when there is valid delete |
| 650 | * request. |
| 651 | */ |
| 652 | @Test |
| 653 | public void testExecuteEditOperationWithDelete() |
| 654 | throws IOException, CloneNotSupportedException { |
| 655 | YangRequestWorkBench defaultYdtBuilder = |
| 656 | buildYdtForEditOperationWithDelete(); |
| 657 | ymsManager.executeOperation(defaultYdtBuilder); |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Checks whether there is no exception when there is valid edit |
| 662 | * request for list. |
| 663 | */ |
| 664 | @Test |
| 665 | public void testExecuteListEditOperationWithoutDelete() |
| 666 | throws IOException, CloneNotSupportedException { |
| 667 | YangRequestWorkBench defaultYdtBuilder = |
| 668 | buildYdtForListEditOperationWithoutDelete(); |
| 669 | ymsManager.executeOperation(defaultYdtBuilder); |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * Checks whether there is no exception when there is valid delete |
| 674 | * request for list. |
| 675 | */ |
| 676 | @Test |
| 677 | public void testExecuteListEditOperationWithDelete() |
| 678 | throws IOException, CloneNotSupportedException { |
| 679 | YangRequestWorkBench defaultYdtBuilder = |
| 680 | buildYdtForListEditOperationWithDelete(); |
| 681 | ymsManager.executeOperation(defaultYdtBuilder); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Checks whether there is no exception when there is valid query |
| 686 | * request. |
| 687 | */ |
| 688 | @Test |
| 689 | public void testExecuteQueryOperation() |
| 690 | throws IOException, CloneNotSupportedException { |
| 691 | YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryOperation(); |
| 692 | ymsManager.executeOperation(defaultYdtBuilder); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Checks whether there is no exception when there is valid query |
| 697 | * request for list. |
| 698 | */ |
| 699 | @Test |
| 700 | public void testExecuteListQueryOperation() |
| 701 | throws IOException, CloneNotSupportedException { |
| 702 | YangRequestWorkBench defaultYdtBuilder = |
| 703 | buildYdtForListQueryOperation(); |
| 704 | ymsManager.executeOperation(defaultYdtBuilder); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Checks whether delete tree is updated correctly. |
| 709 | */ |
| 710 | @Test |
| 711 | public void testSiblingsInDeleteTree() |
| 712 | throws IOException, CloneNotSupportedException { |
| 713 | YangRequestWorkBench defaultYdtBuilder = buildYdtWithOneDeleteNode(); |
| 714 | YdtAppContext appContext = |
| 715 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 716 | YdtContext ydtContext = appContext.getModuleContext(); |
| 717 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 718 | |
| 719 | // verify whether ydt tree is correct |
| 720 | assertThat(ydtContext.getName(), is("test")); |
| 721 | |
| 722 | ydtContext = ydtContext.getFirstChild(); |
| 723 | assertThat(ydtContext.getName(), is("cont1")); |
| 724 | |
| 725 | ydtContext = ydtContext.getNextSibling(); |
| 726 | assertThat(ydtContext.getName(), is("cont4")); |
| 727 | |
| 728 | ydtContext = ydtContext.getNextSibling(); |
| 729 | assertThat(ydtContext.getName(), is("leaf10")); |
| 730 | assertThat(ydtContext.getValue(), is("10")); |
| 731 | |
| 732 | // build delete tree |
| 733 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 734 | YdtContext deleteTree = yab.buildDeleteTree(deleteNodes); |
| 735 | |
| 736 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 737 | |
| 738 | ydtContext = deleteTree.getFirstChild().getFirstChild(); |
| 739 | assertThat(ydtContext.getName(), is("cont4")); |
| 740 | |
| 741 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 742 | assertThat(ydtContext.getPreviousSibling(), nullValue()); |
| 743 | |
| 744 | ydtContext = appContext.getModuleContext(); |
| 745 | |
| 746 | // verify whether ydt tree is correct |
| 747 | assertThat(ydtContext.getName(), is("test")); |
| 748 | |
| 749 | ydtContext = ydtContext.getFirstChild(); |
| 750 | assertThat(ydtContext.getName(), is("cont1")); |
| 751 | |
| 752 | ydtContext = ydtContext.getNextSibling(); |
| 753 | assertThat(ydtContext.getName(), is("leaf10")); |
| 754 | assertThat(ydtContext.getValue(), is("10")); |
| 755 | |
| 756 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * Checks last child is updated correctly after delete tree is built. |
| 761 | */ |
| 762 | @Test |
| 763 | public void testLastChildInYdtTree() |
| 764 | throws IOException, CloneNotSupportedException { |
| 765 | YangRequestWorkBench defaultYdtBuilder = |
| 766 | buildYdtWithDeleteNodeAsLastChild(); |
| 767 | YdtAppContext appContext = |
| 768 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 769 | YdtContext ydtContext = appContext.getModuleContext(); |
| 770 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 771 | assertThat(YdtAppNodeOperationType.BOTH, |
| 772 | is(appContext.getOperationType())); |
| 773 | |
| 774 | // verify whether ydt tree is correct |
| 775 | assertThat(ydtContext.getName(), is("test")); |
| 776 | |
| 777 | ydtContext = ydtContext.getFirstChild(); |
| 778 | assertThat(ydtContext.getName(), is("cont1")); |
| 779 | |
| 780 | ydtContext = ydtContext.getNextSibling(); |
| 781 | assertThat(ydtContext.getName(), is("list2")); |
| 782 | |
| 783 | ydtContext = ydtContext.getNextSibling(); |
| 784 | assertThat(ydtContext.getName(), is("cont4")); |
| 785 | |
| 786 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 787 | |
| 788 | // build delete tree |
| 789 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 790 | YdtContext deleteTree = yab.buildDeleteTree(deleteNodes); |
| 791 | |
| 792 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 793 | |
| 794 | ydtContext = deleteTree.getFirstChild().getFirstChild(); |
| 795 | assertThat(ydtContext.getName(), is("cont4")); |
| 796 | |
| 797 | ydtContext = deleteTree.getFirstChild().getLastChild(); |
| 798 | assertThat(ydtContext.getName(), is("cont4")); |
| 799 | |
| 800 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 801 | assertThat(ydtContext.getPreviousSibling(), nullValue()); |
| 802 | |
| 803 | ydtContext = appContext.getModuleContext(); |
| 804 | |
| 805 | assertThat(ydtContext.getLastChild().getName(), is("list2")); |
| 806 | |
| 807 | // verify whether ydt tree is correct |
| 808 | assertThat(ydtContext.getName(), is("test")); |
| 809 | |
| 810 | ydtContext = ydtContext.getFirstChild(); |
| 811 | assertThat(ydtContext.getName(), is("cont1")); |
| 812 | |
| 813 | ydtContext = ydtContext.getNextSibling(); |
| 814 | assertThat(ydtContext.getName(), is("list2")); |
| 815 | |
| 816 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 817 | } |
| 818 | |
| 819 | /** |
| 820 | * Checks YDT tree with all delete nodes. |
| 821 | */ |
| 822 | @Test |
| 823 | public void testYdtTreeWithAllDeleteNodes() |
| 824 | throws IOException, CloneNotSupportedException { |
| 825 | YangRequestWorkBench defaultYdtBuilder = buildYdtWithAllDeleteNode(); |
| 826 | YdtAppContext appContext = |
| 827 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 828 | YdtContext ydtContext = appContext.getModuleContext(); |
| 829 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 830 | |
| 831 | assertThat(YdtAppNodeOperationType.DELETE_ONLY, |
| 832 | is(appContext.getOperationType())); |
| 833 | |
| 834 | // verify whether ydt tree is correct |
| 835 | assertThat(ydtContext.getName(), is("test")); |
| 836 | |
| 837 | ydtContext = ydtContext.getFirstChild(); |
| 838 | assertThat(ydtContext.getName(), is("cont1")); |
| 839 | |
| 840 | ydtContext = ydtContext.getNextSibling(); |
| 841 | assertThat(ydtContext.getName(), is("list2")); |
| 842 | |
| 843 | ydtContext = ydtContext.getNextSibling(); |
| 844 | assertThat(ydtContext.getName(), is("cont4")); |
| 845 | |
| 846 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 847 | |
| 848 | // build delete tree |
| 849 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 850 | YdtContext deleteTree = yab.buildDeleteTree(deleteNodes); |
| 851 | |
| 852 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 853 | |
| 854 | ydtContext = deleteTree.getFirstChild().getFirstChild(); |
| 855 | assertThat(ydtContext.getName(), is("cont1")); |
| 856 | |
| 857 | ydtContext = ydtContext.getNextSibling(); |
| 858 | assertThat(ydtContext.getName(), is("list2")); |
| 859 | |
| 860 | ydtContext = ydtContext.getNextSibling(); |
| 861 | assertThat(ydtContext.getName(), is("cont4")); |
| 862 | |
| 863 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Checks whether key leaves are also available when there is delete |
| 868 | * request for list. |
| 869 | */ |
| 870 | @Test |
| 871 | public void testKeyLeavesInDeleteTree() throws IOException, CloneNotSupportedException { |
| 872 | YangRequestWorkBench defaultYdtBuilder = buildYdtForKeyLeavesInDeleteTree(); |
| 873 | |
| 874 | YdtAppContext appContext = |
| 875 | defaultYdtBuilder.getAppRootNode().getFirstChild(); |
| 876 | YdtContext ydtContext = appContext.getModuleContext(); |
| 877 | List<YdtContext> deleteNodes = appContext.getDeleteNodes(); |
| 878 | |
| 879 | assertThat(YdtAppNodeOperationType.BOTH, is(appContext.getOperationType())); |
| 880 | |
| 881 | // verify whether ydt tree is correct |
| 882 | assertThat(ydtContext.getName(), is("test")); |
| 883 | |
| 884 | ydtContext = ydtContext.getFirstChild(); |
| 885 | assertThat(ydtContext.getName(), is("list2")); |
| 886 | |
| 887 | ydtContext = ydtContext.getFirstChild(); |
| 888 | assertThat(ydtContext.getName(), is("leaf5")); |
| 889 | assertThat(ydtContext.getValue(), is("5")); |
| 890 | |
| 891 | ydtContext = ydtContext.getNextSibling(); |
| 892 | assertThat(ydtContext.getName(), is("leaf6")); |
| 893 | assertThat(ydtContext.getValue(), is("6")); |
| 894 | |
| 895 | ydtContext = ydtContext.getNextSibling(); |
| 896 | assertThat(ydtContext.getName(), is("leaf7")); |
| 897 | assertThat(ydtContext.getValue(), is("7")); |
| 898 | |
| 899 | ydtContext = ydtContext.getNextSibling(); |
| 900 | assertThat(ydtContext.getName(), is("cont7")); |
| 901 | |
| 902 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 903 | |
| 904 | // build delete tree |
| 905 | YangApplicationBroker yab = new YangApplicationBroker(null); |
| 906 | YdtContext deleteTree = yab.buildDeleteTree(deleteNodes); |
| 907 | |
| 908 | assertThat(deleteTree.getFirstChild().getName(), is("test")); |
| 909 | |
| 910 | ydtContext = deleteTree.getFirstChild().getFirstChild(); |
| 911 | assertThat(ydtContext.getName(), is("list2")); |
| 912 | |
| 913 | ydtContext = ydtContext.getFirstChild(); |
| 914 | assertThat(ydtContext, notNullValue()); |
| 915 | |
| 916 | ydtContext = ydtContext.getNextSibling(); |
| 917 | assertThat(ydtContext, notNullValue()); |
| 918 | |
| 919 | ydtContext = ydtContext.getNextSibling(); |
| 920 | assertThat(ydtContext.getName(), is("cont7")); |
| 921 | |
| 922 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 923 | |
| 924 | ydtContext = appContext.getModuleContext(); |
| 925 | |
| 926 | // verify whether ydt tree is correct |
| 927 | assertThat(ydtContext.getName(), is("test")); |
| 928 | |
| 929 | ydtContext = ydtContext.getFirstChild(); |
| 930 | assertThat(ydtContext.getName(), is("list2")); |
| 931 | |
| 932 | ydtContext = ydtContext.getFirstChild(); |
| 933 | assertThat(ydtContext.getName(), is("leaf5")); |
| 934 | assertThat(ydtContext.getValue(), is("5")); |
| 935 | |
| 936 | ydtContext = ydtContext.getNextSibling(); |
| 937 | assertThat(ydtContext.getName(), is("leaf6")); |
| 938 | assertThat(ydtContext.getValue(), is("6")); |
| 939 | |
| 940 | ydtContext = ydtContext.getNextSibling(); |
| 941 | assertThat(ydtContext.getName(), is("leaf7")); |
| 942 | assertThat(ydtContext.getValue(), is("7")); |
| 943 | |
| 944 | assertThat(ydtContext.getNextSibling(), nullValue()); |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Checks YDT tree and application tree for query request with mutiple |
| 949 | * augments. |
| 950 | */ |
| 951 | @Test |
| 952 | public void testApptreeForQueryWithMultipleAugment() |
| 953 | throws IOException, CloneNotSupportedException { |
| 954 | YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment(); |
| 955 | YdtAppContext appContext = defaultYdtBuilder.getAppRootNode() |
| 956 | .getFirstChild(); |
| 957 | YdtContext ydtNode = appContext.getModuleContext(); |
| 958 | YangNode yangNode = (YangNode) ((YdtNode) ydtNode).getYangSchemaNode(); |
| 959 | |
| 960 | YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder. |
| 961 | getYangSchemaRegistry()); |
| 962 | yab.processAugmentForChildNode(appContext, yangNode); |
| 963 | |
| 964 | assertThat(appContext.getModuleContext().getName(), is("test")); |
| 965 | |
| 966 | appContext = appContext.getFirstChild(); |
| 967 | |
| 968 | String augmentName = ((YangAugment) appContext |
| 969 | .getAugmentingSchemaNode()).getTargetNode().get(0) |
| 970 | .getResolvedNode().getJavaClassNameOrBuiltInType(); |
| 971 | assertThat(augmentName, is("cont4")); |
| 972 | |
| 973 | appContext = appContext.getFirstChild(); |
| 974 | augmentName = ((YangAugment) appContext |
| 975 | .getAugmentingSchemaNode()).getTargetNode().get(0) |
| 976 | .getResolvedNode().getJavaClassNameOrBuiltInType(); |
| 977 | assertThat(augmentName, is("cont4")); |
| 978 | assertThat(appContext.getFirstChild(), nullValue()); |
| 979 | assertThat(appContext.getLastChild(), nullValue()); |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * Checks whether there is no exception when there is valid query request |
| 984 | * for data resource with multiple augments. |
| 985 | */ |
| 986 | @Test |
| 987 | public void testQueryWithMultipleAugment() |
| 988 | throws IOException, CloneNotSupportedException { |
| 989 | YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment(); |
| 990 | ymsManager.executeOperation(defaultYdtBuilder); |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * Checks whether YDT is updated correctly for delete with multiple augment. |
| 995 | */ |
| 996 | @Test |
| 997 | public void testYdtForDeleteWithMultipleAugment() |
| 998 | throws IOException, CloneNotSupportedException { |
| 999 | YangRequestWorkBench defaultYdtBuilder = |
| 1000 | buildYdtForDeleteWithMultipleAugment(); |
| 1001 | YdtAppContext appContext = defaultYdtBuilder.getAppRootNode() |
| 1002 | .getFirstChild(); |
| 1003 | |
| 1004 | YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder. |
| 1005 | getYangSchemaRegistry()); |
| 1006 | YdtContext deleteTree = yab.buildDeleteTree(appContext.getDeleteNodes()); |
| 1007 | yab.processAugmentedNodesForDelete(deleteTree.getFirstChild(), |
| 1008 | appContext); |
| 1009 | |
| 1010 | assertThat(appContext.getModuleContext().getName(), is("test")); |
| 1011 | |
| 1012 | appContext = appContext.getFirstChild(); |
| 1013 | String augmentName = ((YangAugment) appContext |
| 1014 | .getAugmentingSchemaNode()).getTargetNode().get(0) |
| 1015 | .getResolvedNode().getJavaClassNameOrBuiltInType(); |
| 1016 | assertThat(augmentName, is("cont4")); |
| 1017 | |
| 1018 | appContext = appContext.getFirstChild(); |
| 1019 | augmentName = ((YangAugment) appContext |
| 1020 | .getAugmentingSchemaNode()).getTargetNode().get(0) |
| 1021 | .getResolvedNode().getJavaClassNameOrBuiltInType(); |
| 1022 | assertThat(augmentName, is("cont4")); |
| 1023 | assertThat(appContext.getFirstChild(), nullValue()); |
| 1024 | assertThat(appContext.getLastChild(), nullValue()); |
| 1025 | |
| 1026 | YdtContext ydtContext = deleteTree.getFirstChild(); |
| 1027 | assertThat(ydtContext.getName(), is("test")); |
| 1028 | |
| 1029 | ydtContext = ydtContext.getFirstChild(); |
| 1030 | assertThat(ydtContext.getName(), is("cont4")); |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * Checks whether there is no exception when there is valid delete request |
| 1035 | * for data resource with multiple augments. |
| 1036 | */ |
| 1037 | @Test |
| 1038 | public void testDeleteWithMultipleAugment() { |
| 1039 | YangRequestWorkBench defaultYdtBuilder = |
| 1040 | buildYdtForDeleteWithMultipleAugment(); |
| 1041 | ymsManager.executeOperation(defaultYdtBuilder); |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * Checks execute operation for rpc request with only output. |
| 1046 | */ |
| 1047 | @Test |
| 1048 | public void testRpcWithOutput() |
| 1049 | throws IOException, CloneNotSupportedException { |
| 1050 | YangRequestWorkBench defaultYdtBuilder = |
| 1051 | buildYdtForRpcWithOnlyOutput(); |
| 1052 | ymsManager.executeOperation(defaultYdtBuilder); |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * Checks execute operation for rpc request with only input. |
| 1057 | */ |
| 1058 | @Test |
| 1059 | public void testRpcWithInput() |
| 1060 | throws IOException, CloneNotSupportedException { |
| 1061 | YangRequestWorkBench defaultYdtBuilder = |
| 1062 | buildYdtForRpcWithOnlyInput(); |
| 1063 | ymsManager.executeOperation(defaultYdtBuilder); |
| 1064 | } |
| 1065 | |
| 1066 | /** |
| 1067 | * Checks execute operation for rpc request with input and output. |
| 1068 | */ |
| 1069 | @Test |
| 1070 | public void testRpcWithInputOutput() |
| 1071 | throws IOException, CloneNotSupportedException { |
| 1072 | YangRequestWorkBench defaultYdtBuilder = |
| 1073 | buildYdtForRpcWithBothInputOutput(); |
| 1074 | ymsManager.executeOperation(defaultYdtBuilder); |
| 1075 | } |
| 1076 | |
| 1077 | /** |
| 1078 | * Checks execute operation for rpc request without input and |
| 1079 | * output. |
| 1080 | */ |
| 1081 | @Test |
| 1082 | public void testRpcWithoutInputOutput() |
| 1083 | throws IOException, CloneNotSupportedException { |
| 1084 | YangRequestWorkBench defaultYdtBuilder = |
| 1085 | buildYdtForRpc(); |
| 1086 | ymsManager.executeOperation(defaultYdtBuilder); |
| 1087 | } |
| 1088 | } |