Merge "BUG-1953: fix SAL compatility layer"
[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 toStringNodeIdentifier(){
19         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
20
21         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
22
23         assertEquals(expected , PathUtils.toString(pathArgument));
24     }
25
26     @Test
27     public void toStringAugmentationIdentifier(){
28         String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
29
30         YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
31
32         assertEquals(expected, PathUtils.toString(pathArgument));
33     }
34
35     @Test
36     public void toStringNodeWithValue(){
37
38         YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
39
40         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
41
42         assertEquals(expected, PathUtils.toString(pathArgument));
43     }
44
45
46     @Test
47     public void toStringNodeIdentifierWithPredicates(){
48
49         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
50
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}]";
52
53         assertEquals(expected, PathUtils.toString(pathArgument));
54     }
55
56     @Test
57     public void toStringYangInstanceIdentifier(){
58
59         YangInstanceIdentifier path =
60             YangInstanceIdentifier.create(nodeIdentifier())
61                 .node(nodeIdentifierWithPredicates())
62                 .node(augmentationIdentifier()).node(nodeWithValue());
63
64
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]";
69
70         assertEquals(expected, PathUtils.toString(path));
71
72     }
73
74     @Test
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]";
80
81         YangInstanceIdentifier yangInstanceIdentifier =
82             PathUtils.toYangInstanceIdentifier(expected);
83
84         String actual = PathUtils.toString(yangInstanceIdentifier);
85
86         assertEquals(expected, actual);
87
88     }
89
90     private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
91         return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
92     }
93
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"));
97
98         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
99     }
100
101     private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
102         return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
103     }
104
105     private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
106         Map<QName, Object> keys = new HashMap<>();
107
108         keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
109
110         return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
111     }
112 }