Merge "BUG-1568 Remove ganymed Ssh client adapter"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / utils / PathUtilsTest.java
1 package org.opendaylight.controller.cluster.datastore.node.utils;
2
3 import org.junit.Test;
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;
7
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.Map;
11 import java.util.Set;
12
13 import static junit.framework.TestCase.assertEquals;
14
15 public class PathUtilsTest {
16
17     @Test
18     public void getParentPath(){
19         assertEquals("", PathUtils.getParentPath("foobar"));
20         assertEquals("", PathUtils.getParentPath("/a"));
21         assertEquals("/a", PathUtils.getParentPath("/a/b"));
22         assertEquals("/a/b", PathUtils.getParentPath("/a/b/c"));
23         assertEquals("/a/b", PathUtils.getParentPath("a/b/c"));
24     }
25
26     @Test
27     public void toStringNodeIdentifier(){
28         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
29
30         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
31
32         assertEquals(expected , PathUtils.toString(pathArgument));
33     }
34
35     @Test
36     public void toStringAugmentationIdentifier(){
37         String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
38
39         YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
40
41         assertEquals(expected, PathUtils.toString(pathArgument));
42     }
43
44     @Test
45     public void toStringNodeWithValue(){
46
47         YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
48
49         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
50
51         assertEquals(expected, PathUtils.toString(pathArgument));
52     }
53
54
55     @Test
56     public void toStringNodeIdentifierWithPredicates(){
57
58         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
59
60         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}]";
61
62         assertEquals(expected, PathUtils.toString(pathArgument));
63     }
64
65     @Test
66     public void toStringYangInstanceIdentifier(){
67
68         YangInstanceIdentifier path =
69             YangInstanceIdentifier.create(nodeIdentifier())
70                 .node(nodeIdentifierWithPredicates())
71                 .node(augmentationIdentifier()).node(nodeWithValue());
72
73
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]";
78
79         assertEquals(expected, PathUtils.toString(path));
80
81     }
82
83     @Test
84     public void toYangInstanceIdentifier(){
85         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
86             "(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}]/" +
87             "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
88             "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
89
90         YangInstanceIdentifier yangInstanceIdentifier =
91             PathUtils.toYangInstanceIdentifier(expected);
92
93         String actual = PathUtils.toString(yangInstanceIdentifier);
94
95         assertEquals(expected, actual);
96
97     }
98
99     private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
100         return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
101     }
102
103     private YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier(){
104         Set<QName> childNames = new HashSet();
105         childNames.add(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
106
107         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
108     }
109
110     private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
111         return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
112     }
113
114     private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
115         Map<QName, Object> keys = new HashMap<>();
116
117         keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
118
119         return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
120     }
121 }