1 import org.cesnet.*; 2 import org.cesnet.Module; 3 import static org.cesnet.LYD_ANYDATA_VALUETYPE.LYD_ANYDATA_CONSTSTRING; 4 import static org.cesnet.LYD_FORMAT.LYD_JSON; 5 import static org.cesnet.LYD_FORMAT.LYD_XML; 6 import static org.cesnet.LYS_INFORMAT.LYS_IN_YIN; 7 import static org.cesnet.yangConstants.*; 8 9 import java.io.FileDescriptor; 10 import java.io.RandomAccessFile; 11 import java.lang.reflect.Field; 12 import org.junit.Test; 13 import static org.junit.Assert.*; 14 15 public class TreeDataTest { 16 17 static { 18 System.loadLibrary("yangJava"); 19 } 20 21 String lys_module_a = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 22 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" xmlns:a=\"urn:a\" name=\"a\"> \n" + 23 " <namespace uri=\"urn:a\"/> \n" + 24 " <prefix value=\"a_mod\"/> \n" + 25 " <include module=\"asub\"/> \n" + 26 " <include module=\"atop\"/> \n" + 27 " <import module=\"ietf-yang-metadata\"> \n" + 28 " <prefix value=\"md\"/> \n" + 29 " </import> \n" + 30 " <feature name=\"foo\"/> \n" + 31 " <grouping name=\"gg\"> \n" + 32 " <leaf name=\"bar-gggg\"> \n" + 33 " <type name=\"string\"/> \n" + 34 " </leaf> \n" + 35 " </grouping> \n" + 36 " <md:annotation name=\"test\"> \n" + 37 " <type name=\"string\"/> \n" + 38 " </md:annotation> \n" + 39 " <container name=\"x\"> \n" + 40 " <leaf name=\"bar-leaf\"> \n" + 41 " <type name=\"string\"/> \n" + 42 " </leaf> \n" + 43 " <uses name=\"gg\"></uses> \n" + 44 " <leaf name=\"baz\"> \n" + 45 " <type name=\"string\"/> \n" + 46 " </leaf> \n" + 47 " <leaf name=\"bubba\"> \n" + 48 " <type name=\"string\"/> \n" + 49 " </leaf> \n" + 50 " <leaf name=\"number32\"> \n" + 51 " <type name=\"int32\"/> \n" + 52 " </leaf> \n" + 53 " <leaf name=\"number64\"> \n" + 54 " <type name=\"int64\"/> \n" + 55 " </leaf> \n" + 56 " <leaf name=\"def-leaf\"> \n" + 57 " <type name=\"string\"/> \n" + 58 " <default value=\"def\"/> \n" + 59 " </leaf> \n" + 60 " </container> \n" + 61 " <leaf name=\"y\">\n" + 62 " <type name=\"string\"/>\n" + 63 " </leaf> \n" + 64 " <anyxml name=\"any\"/> \n" + 65 " <augment target-node=\"/x\"> \n" + 66 " <container name=\"bar-y\"/> \n" + 67 " </augment> \n" + 68 " <rpc name=\"bar-rpc\"></rpc> \n" + 69 " <rpc name=\"foo-rpc\"></rpc> \n" + 70 " <rpc name=\"rpc1\"> \n" + 71 " <input> \n" + 72 " <leaf name=\"input-leaf1\"> \n" + 73 " <type name=\"string\"/> \n" + 74 " </leaf> \n" + 75 " <container name=\"x\"> \n" + 76 " <leaf name=\"input-leaf2\"> \n" + 77 " <type name=\"string\"/> \n" + 78 " </leaf> \n" + 79 " </container> \n" + 80 " </input> \n" + 81 " <output> \n" + 82 " <leaf name=\"output-leaf1\"> \n" + 83 " <type name=\"string\"/> \n" + 84 " </leaf> \n" + 85 " <leaf name=\"output-leaf2\"> \n" + 86 " <type name=\"string\"/> \n" + 87 " </leaf> \n" + 88 " <container name=\"rpc-container\"> \n" + 89 " <leaf name=\"output-leaf3\"> \n" + 90 " <type name=\"string\"/> \n" + 91 " </leaf> \n" + 92 " </container> \n" + 93 " </output> \n" + 94 " </rpc> \n" + 95 " <list name=\"l\"> \n" + 96 " <key value=\"key1 key2\"/> \n" + 97 " <leaf name=\"key1\"> \n" + 98 " <type name=\"uint8\"/> \n" + 99 " </leaf> \n" + 100 " <leaf name=\"key2\"> \n" + 101 " <type name=\"uint8\"/> \n" + 102 " </leaf> \n" + 103 " <leaf name=\"value\"> \n" + 104 " <type name=\"string\"/> \n" + 105 " </leaf> \n" + 106 " </list> \n" + 107 "</module>"; 108 109 String result_xml = "<x xmlns=\"urn:a\"><bubba>test</bubba></x>"; 110 String result_xml_format = 111 "<x xmlns=\"urn:a\">\n" + 112 " <bubba>test</bubba>\n" + 113 "</x>\n"; 114 String result_json = "{\n" + 115 " \"a:x\": {\n" + 116 " \"bubba\": \"test\"\n" + 117 " }\n" + 118 "}\n"; 119 120 @Test test_ly_ctx_parse_data_mem()121 public void test_ly_ctx_parse_data_mem() { 122 String a_data_xml = "<x xmlns=\"urn:a\">\n" + 123 "<bubba>test</bubba>\n" + 124 "</x>"; 125 126 String yang_folder = Constants.TESTS_DIR + "/api/files"; 127 String yin_file = Constants.TESTS_DIR + "/api/files/a.yin"; 128 129 try { 130 Context ctx = new Context(yang_folder); 131 assertNotNull(ctx); 132 ctx.parse_module_path(yin_file, LYS_IN_YIN); 133 134 Data_Node root = ctx.parse_data_mem(a_data_xml, LYD_XML, LYD_OPT_NOSIBLINGS | LYD_OPT_STRICT); 135 assertNotNull(root); 136 assertEquals("x", root.schema().name()); 137 } catch (Exception e) { 138 fail(e.getMessage()); 139 } 140 } 141 142 @Test test_ly_ctx_parse_data_fd()143 public void test_ly_ctx_parse_data_fd() { 144 String yang_folder = Constants.TESTS_DIR + "/api/files"; 145 String yin_file = Constants.TESTS_DIR + "/api/files/a.yin"; 146 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 147 148 try { 149 Context ctx = new Context(yang_folder); 150 assertNotNull(ctx); 151 ctx.parse_module_path(yin_file, LYS_IN_YIN); 152 RandomAccessFile f = new RandomAccessFile(config_file, "r"); 153 FileDescriptor fileno = f.getFD(); 154 Field _fileno = FileDescriptor.class.getDeclaredField("fd"); 155 _fileno.setAccessible(true); 156 Integer fd = (Integer) _fileno.get(fileno); 157 158 Data_Node root = ctx.parse_data_fd(fd, LYD_XML, LYD_OPT_NOSIBLINGS | LYD_OPT_STRICT); 159 assertNotNull(root); 160 assertEquals("x", root.schema().name()); 161 f.close(); 162 } catch (Exception e) { 163 fail(e.getMessage()); 164 } 165 } 166 167 @Test test_ly_ctx_parse_data_path()168 public void test_ly_ctx_parse_data_path() { 169 String yang_folder = Constants.TESTS_DIR + "/api/files"; 170 String yin_file = Constants.TESTS_DIR + "/api/files/a.yin"; 171 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 172 String module_name = "a"; 173 String schema_name = "x"; 174 175 try { 176 Context ctx = new Context(yang_folder); 177 assertNotNull(ctx); 178 Module module = ctx.parse_module_path(yin_file, LYS_IN_YIN); 179 assertNotNull(module); 180 assertEquals(module_name, module.name()); 181 182 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 183 assertNotNull(root); 184 assertEquals(schema_name, root.schema().name()); 185 } catch (Exception e) { 186 fail(e.getMessage()); 187 } 188 } 189 190 @Test test_ly_ctx_parse_data_path_invalid()191 public void test_ly_ctx_parse_data_path_invalid() { 192 String yang_folder = Constants.TESTS_DIR + "/api/files"; 193 194 try { 195 Context ctx = new Context(yang_folder); 196 assertNotNull(ctx); 197 198 Data_Node root = ctx.parse_data_path("INVALID_PATH", LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 199 throw new Exception("exception not thrown"); 200 } catch (Exception e) { 201 assertTrue(e.getMessage().contains("INVALID_PATH")); 202 } 203 } 204 205 @Test test_ly_data_node()206 public void test_ly_data_node() { 207 String yang_folder = Constants.TESTS_DIR + "/api/files"; 208 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 209 210 try { 211 Context ctx = new Context(yang_folder); 212 assertNotNull(ctx); 213 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 214 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 215 assertNotNull(root); 216 217 Data_Node new_node = new Data_Node(root, root.child().schema().module(), "bar-y"); 218 assertNotNull(new_node); 219 new_node = new Data_Node(root, root.schema().module(), "number32", "100"); 220 assertNotNull(new_node); 221 Data_Node dup_node = new_node.dup(0); 222 assertNotNull(dup_node); 223 } catch (Exception e) { 224 fail(e.getMessage()); 225 } 226 } 227 228 @Test test_ly_data_node_new_path()229 public void test_ly_data_node_new_path() { 230 String yang_folder = Constants.TESTS_DIR + "/api/files"; 231 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 232 233 try { 234 Context ctx = new Context(yang_folder); 235 assertNotNull(ctx); 236 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 237 ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 238 Module mod = ctx.get_module("a", null, 1); 239 assertNotNull(mod); 240 241 Data_Node root = new Data_Node(ctx, "/a:x/bar-gggg", "a", LYD_ANYDATA_CONSTSTRING, 0); 242 assertNotNull(root); 243 assertEquals("x", root.schema().name()); 244 assertEquals("bar-gggg", root.child().schema().name()); 245 246 Data_Node node = root.new_path(ctx, "def-leaf", "def", LYD_ANYDATA_CONSTSTRING, LYD_PATH_OPT_DFLT); 247 assertNotNull(node); 248 assertEquals("def-leaf", node.schema().name()); 249 assertEquals(1, node.dflt()); 250 251 node = root.new_path(ctx, "def-leaf", "def", LYD_ANYDATA_CONSTSTRING, 0); 252 assertNotNull(node); 253 assertEquals("def-leaf", node.schema().name()); 254 assertEquals(0, node.dflt()); 255 256 node = root.new_path(ctx, "bubba", "b", LYD_ANYDATA_CONSTSTRING, 0); 257 assertNotNull(node); 258 assertEquals("bubba", node.schema().name()); 259 260 node = root.new_path(ctx, "/a:x/number32", "3", LYD_ANYDATA_CONSTSTRING, 0); 261 assertNotNull(node); 262 assertEquals("number32", node.schema().name()); 263 264 node = root.new_path(ctx, "/a:l[key1='1'][key2='2']/value", null, LYD_ANYDATA_CONSTSTRING, 0); 265 assertNotNull(node); 266 assertEquals("l", node.schema().name()); 267 assertEquals("key1", node.child().schema().name()); 268 assertEquals("key2", node.child().next().schema().name()); 269 assertEquals("value", node.child().next().next().schema().name()); 270 } catch (Exception e) { 271 fail(e.getMessage()); 272 } 273 } 274 275 @Test test_ly_data_node_insert()276 public void test_ly_data_node_insert() { 277 String yang_folder = Constants.TESTS_DIR + "/api/files"; 278 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 279 280 try { 281 Context ctx = new Context(yang_folder); 282 assertNotNull(ctx); 283 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 284 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 285 assertNotNull(root); 286 Data_Node new_node = new Data_Node(root, root.schema().module(), "number32", "200"); 287 assertNotNull(new_node); 288 int rc = root.insert(new_node); 289 assertEquals(0, rc); 290 assertEquals("number32", root.child().prev().schema().name()); 291 } catch (Exception e) { 292 fail(e.getMessage()); 293 } 294 } 295 296 @Test test_ly_data_node_insert_sibling()297 public void test_ly_data_node_insert_sibling() { 298 String yang_folder = Constants.TESTS_DIR + "/api/files"; 299 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 300 301 try { 302 Context ctx = new Context(yang_folder); 303 assertNotNull(ctx); 304 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 305 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 306 assertNotNull(root); 307 308 Data_Node last = root.prev(); 309 Data_Node new_node = new Data_Node(null, root.schema().module(), "y", "test"); 310 assertNotNull(new_node); 311 int rc = root.insert_sibling(new_node); 312 assertEquals(0, rc); 313 assertNotEquals(last.schema().name(), root.prev().schema().name()); 314 assertEquals("y", root.prev().schema().name()); 315 } catch (Exception e) { 316 fail(e.getMessage()); 317 } 318 } 319 320 @Test test_ly_data_node_insert_before()321 public void test_ly_data_node_insert_before() { 322 String yang_folder = Constants.TESTS_DIR + "/api/files"; 323 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 324 325 try { 326 Context ctx = new Context(yang_folder); 327 assertNotNull(ctx); 328 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 329 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 330 assertNotNull(root); 331 332 Data_Node last = root.prev(); 333 Data_Node new_node = new Data_Node(null, root.schema().module(), "y", "test"); 334 assertNotNull(new_node); 335 int rc = root.insert_before(new_node); 336 assertEquals(0, rc); 337 assertNotEquals(last.schema().name(), root.prev().schema().name()); 338 assertEquals("y", root.prev().schema().name()); 339 } catch (Exception e) { 340 fail(e.getMessage()); 341 } 342 } 343 344 @Test test_ly_data_node_insert_after()345 public void test_ly_data_node_insert_after() { 346 String yang_folder = Constants.TESTS_DIR + "/api/files"; 347 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 348 349 try { 350 Context ctx = new Context(yang_folder); 351 assertNotNull(ctx); 352 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 353 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 354 assertNotNull(root); 355 356 Data_Node last = root.next(); 357 Data_Node new_node = new Data_Node(null, root.schema().module(), "y", "test"); 358 assertNotNull(new_node); 359 int rc = root.insert_after(new_node); 360 assertEquals(0, rc); 361 assertNotEquals(last.schema().name(), root.next().schema().name()); 362 assertEquals("y", root.next().schema().name()); 363 } catch (Exception e) { 364 fail(e.getMessage()); 365 } 366 } 367 368 @Test test_ly_data_node_schema_sort()369 public void test_ly_data_node_schema_sort() { 370 String yang_folder = Constants.TESTS_DIR + "/api/files"; 371 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 372 373 try { 374 Context ctx = new Context(yang_folder); 375 assertNotNull(ctx); 376 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 377 ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 378 Module mod = ctx.get_module("a", null, 1); 379 assertNotNull(mod); 380 381 Data_Node root = new Data_Node(null, mod, "l"); 382 assertNotNull(root); 383 Data_Node node = new Data_Node(root, mod, "key1", "1"); 384 assertNotNull(node); 385 node = new Data_Node(root, mod, "key2", "2"); 386 assertNotNull(node); 387 388 node = new Data_Node(null, mod, "x"); 389 assertNotNull(node); 390 int rc = root.insert_after(node); 391 assertEquals(0, rc); 392 node = root.next(); 393 394 Data_Node node2 = new Data_Node(node, mod, "bubba", "a"); 395 assertNotNull(node2); 396 node2 = new Data_Node(node, mod, "bar-gggg", "b"); 397 assertNotNull(node2); 398 node2 = new Data_Node(node, mod, "number64", "64"); 399 assertNotNull(node2); 400 node2 = new Data_Node(node, mod, "number32", "32"); 401 assertNotNull(node2); 402 403 rc = root.schema_sort(1); 404 assertEquals(0, rc); 405 406 root = node; 407 assertEquals("x", root.schema().name()); 408 assertEquals("l", root.next().schema().name()); 409 410 assertEquals("bar-gggg", root.child().schema().name()); 411 assertEquals("bubba", root.child().next().schema().name()); 412 assertEquals("number32", root.child().next().next().schema().name()); 413 assertEquals("number64", root.child().next().next().next().schema().name()); 414 } catch (Exception e) { 415 fail(e.getMessage()); 416 } 417 } 418 419 @Test test_ly_data_node_find_path()420 public void test_ly_data_node_find_path() { 421 String yang_folder = Constants.TESTS_DIR + "/api/files"; 422 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 423 424 try { 425 Context ctx = new Context(yang_folder); 426 assertNotNull(ctx); 427 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 428 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 429 assertNotNull(root); 430 431 Data_Node node = root.child(); 432 assertNotNull(node); 433 Set set = node.find_path("/a:x/bubba"); 434 assertNotNull(set); 435 assertEquals(1, set.number()); 436 } catch (Exception e) { 437 fail(e.getMessage()); 438 } 439 } 440 441 @Test test_ly_data_node_find_instance()442 public void test_ly_data_node_find_instance() { 443 String yang_folder = Constants.TESTS_DIR + "/api/files"; 444 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 445 446 try { 447 Context ctx = new Context(yang_folder); 448 assertNotNull(ctx); 449 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 450 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 451 assertNotNull(root); 452 453 Data_Node node = root.child(); 454 assertNotNull(node); 455 Set set = node.find_instance(node.schema()); 456 assertNotNull(set); 457 assertEquals(1, set.number()); 458 } catch (Exception e) { 459 fail(e.getMessage()); 460 } 461 } 462 463 @Test test_ly_data_node_validate()464 public void test_ly_data_node_validate() { 465 String yang_folder = Constants.TESTS_DIR + "/api/files"; 466 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 467 468 try { 469 Context ctx = new Context(yang_folder); 470 assertNotNull(ctx); 471 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 472 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 473 assertNotNull(root); 474 475 int rc = root.validate(LYD_OPT_CONFIG, ctx); 476 assertEquals(0, rc); 477 Data_Node new_node = new Data_Node(root, root.schema().module(), "number32", "1"); 478 assertNotNull(new_node); 479 rc = root.insert(new_node); 480 assertEquals(0, rc); 481 rc = root.validate(LYD_OPT_CONFIG, ctx); 482 assertEquals(0, rc); 483 } catch (Exception e) { 484 fail(e.getMessage()); 485 } 486 } 487 488 @Test test_ly_data_node_unlink()489 public void test_ly_data_node_unlink() { 490 String yang_folder = Constants.TESTS_DIR + "/api/files"; 491 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 492 493 try { 494 Context ctx = new Context(yang_folder); 495 assertNotNull(ctx); 496 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 497 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 498 assertNotNull(root); 499 500 Data_Node node = root.child(); 501 Data_Node new_node = new Data_Node(root, root.schema().module(), "number32", "1"); 502 assertNotNull(new_node); 503 int rc = root.insert(new_node); 504 assertEquals(0, rc); 505 506 assertEquals("number32", node.prev().schema().name()); 507 508 rc = node.prev().unlink(); 509 assertEquals(0, rc); 510 511 assertNotEquals("number32", node.prev().schema().name()); 512 } catch (Exception e) { 513 fail(e.getMessage()); 514 } 515 } 516 517 @Test test_ly_data_node_print_mem_xml()518 public void test_ly_data_node_print_mem_xml() { 519 String yang_folder = Constants.TESTS_DIR + "/api/files"; 520 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 521 522 try { 523 Context ctx = new Context(yang_folder); 524 assertNotNull(ctx); 525 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 526 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 527 assertNotNull(root); 528 529 String result = root.print_mem(LYD_XML, 0); 530 assertEquals(result_xml, result); 531 } catch (Exception e) { 532 fail(e.getMessage()); 533 } 534 } 535 536 @Test test_ly_data_node_print_mem_xml_format()537 public void test_ly_data_node_print_mem_xml_format() { 538 String yang_folder = Constants.TESTS_DIR + "/api/files"; 539 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 540 541 try { 542 Context ctx = new Context(yang_folder); 543 assertNotNull(ctx); 544 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 545 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 546 assertNotNull(root); 547 548 String result = root.print_mem(LYD_XML, LYP_FORMAT); 549 assertEquals(result_xml_format, result); 550 } catch (Exception e) { 551 fail(e.getMessage()); 552 } 553 } 554 555 @Test test_ly_data_node_print_mem_json()556 public void test_ly_data_node_print_mem_json() { 557 String yang_folder = Constants.TESTS_DIR + "/api/files"; 558 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 559 560 try { 561 Context ctx = new Context(yang_folder); 562 assertNotNull(ctx); 563 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 564 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 565 assertNotNull(root); 566 567 String result = root.print_mem(LYD_JSON, LYP_FORMAT); 568 assertEquals(result_json, result); 569 } catch (Exception e) { 570 fail(e.getMessage()); 571 } 572 } 573 574 @Test test_ly_data_node_path()575 public void test_ly_data_node_path() { 576 String yang_folder = Constants.TESTS_DIR + "/api/files"; 577 String config_file = Constants.TESTS_DIR + "/api/files/a.xml"; 578 579 try { 580 Context ctx = new Context(yang_folder); 581 assertNotNull(ctx); 582 ctx.parse_module_mem(lys_module_a, LYS_IN_YIN); 583 Data_Node root = ctx.parse_data_path(config_file, LYD_XML, LYD_OPT_CONFIG | LYD_OPT_STRICT); 584 assertNotNull(root); 585 586 String path = root.path(); 587 assertNotNull(path); 588 assertEquals("/a:x", path); 589 path = root.child().path(); 590 assertNotNull(path); 591 assertEquals("/a:x/bubba", path); 592 } catch (Exception e) { 593 fail(e.getMessage()); 594 } 595 } 596 main(String[] args)597 public static void main(String[] args) { 598 new TreeDataTest(); 599 } 600 601 } 602