1 package org.opendaylight.controller.cluster.datastore.node.utils;
3 import com.google.common.collect.ImmutableSet;
5 import org.opendaylight.controller.cluster.datastore.util.TestModel;
6 import org.opendaylight.yangtools.yang.common.QName;
7 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
8 import java.util.HashMap;
11 import static junit.framework.TestCase.assertEquals;
13 public class PathUtilsTest {
16 public void toStringNodeIdentifier(){
17 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
19 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
21 assertEquals(expected , PathUtils.toString(pathArgument));
25 public void toStringAugmentationIdentifier(){
26 String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
28 YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
30 assertEquals(expected, PathUtils.toString(pathArgument));
34 public void toStringNodeWithValue(){
36 YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
38 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
40 assertEquals(expected, PathUtils.toString(pathArgument));
45 public void toStringNodeIdentifierWithPredicates(){
47 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
49 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}]";
51 assertEquals(expected, PathUtils.toString(pathArgument));
55 public void toStringYangInstanceIdentifier(){
57 YangInstanceIdentifier path =
58 YangInstanceIdentifier.create(nodeIdentifier())
59 .node(nodeIdentifierWithPredicates())
60 .node(augmentationIdentifier()).node(nodeWithValue());
63 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
64 "(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}]/" +
65 "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
66 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
68 assertEquals(expected, PathUtils.toString(path));
73 public void toYangInstanceIdentifier(){
74 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
75 "(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}]/" +
76 "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
77 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
79 YangInstanceIdentifier yangInstanceIdentifier =
80 PathUtils.toYangInstanceIdentifier(expected);
82 String actual = PathUtils.toString(yangInstanceIdentifier);
84 assertEquals(expected, actual);
88 private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
89 return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
92 private YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier(){
93 Set<QName> childNames = ImmutableSet.of(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
95 return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
98 private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
99 return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
102 private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
103 Map<QName, Object> keys = new HashMap<>();
105 keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
107 return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);