1 package org.opendaylight.controller.cluster.datastore.node.utils;
4 import org.opendaylight.controller.cluster.datastore.util.TestModel;
5 import org.opendaylight.yangtools.yang.common.QName;
6 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
8 import java.util.HashMap;
9 import java.util.HashSet;
13 import static junit.framework.TestCase.assertEquals;
15 public class PathUtilsTest {
18 public void toStringNodeIdentifier(){
19 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
21 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
23 assertEquals(expected , PathUtils.toString(pathArgument));
27 public void toStringAugmentationIdentifier(){
28 String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
30 YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
32 assertEquals(expected, PathUtils.toString(pathArgument));
36 public void toStringNodeWithValue(){
38 YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
40 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
42 assertEquals(expected, PathUtils.toString(pathArgument));
47 public void toStringNodeIdentifierWithPredicates(){
49 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
51 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]";
53 assertEquals(expected, PathUtils.toString(pathArgument));
57 public void toStringYangInstanceIdentifier(){
59 YangInstanceIdentifier path =
60 YangInstanceIdentifier.create(nodeIdentifier())
61 .node(nodeIdentifierWithPredicates())
62 .node(augmentationIdentifier()).node(nodeWithValue());
65 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
66 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]/" +
67 "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
68 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
70 assertEquals(expected, PathUtils.toString(path));
75 public void toYangInstanceIdentifier(){
76 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
77 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]/" +
78 "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
79 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
81 YangInstanceIdentifier yangInstanceIdentifier =
82 PathUtils.toYangInstanceIdentifier(expected);
84 String actual = PathUtils.toString(yangInstanceIdentifier);
86 assertEquals(expected, actual);
90 private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
91 return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
94 private YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier(){
95 Set<QName> childNames = new HashSet();
96 childNames.add(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
98 return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
101 private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
102 return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
105 private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
106 Map<QName, Object> keys = new HashMap<>();
108 keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
110 return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);