Fix non-generic references to HashSet
[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 com.google.common.collect.ImmutableSet;
4 import org.junit.Test;
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;
9 import java.util.Map;
10 import java.util.Set;
11 import static junit.framework.TestCase.assertEquals;
12
13 public class PathUtilsTest {
14
15     @Test
16     public void toStringNodeIdentifier(){
17         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
18
19         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
20
21         assertEquals(expected , PathUtils.toString(pathArgument));
22     }
23
24     @Test
25     public void toStringAugmentationIdentifier(){
26         String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
27
28         YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
29
30         assertEquals(expected, PathUtils.toString(pathArgument));
31     }
32
33     @Test
34     public void toStringNodeWithValue(){
35
36         YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
37
38         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
39
40         assertEquals(expected, PathUtils.toString(pathArgument));
41     }
42
43
44     @Test
45     public void toStringNodeIdentifierWithPredicates(){
46
47         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
48
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}]";
50
51         assertEquals(expected, PathUtils.toString(pathArgument));
52     }
53
54     @Test
55     public void toStringYangInstanceIdentifier(){
56
57         YangInstanceIdentifier path =
58             YangInstanceIdentifier.create(nodeIdentifier())
59                 .node(nodeIdentifierWithPredicates())
60                 .node(augmentationIdentifier()).node(nodeWithValue());
61
62
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]";
67
68         assertEquals(expected, PathUtils.toString(path));
69
70     }
71
72     @Test
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]";
78
79         YangInstanceIdentifier yangInstanceIdentifier =
80             PathUtils.toYangInstanceIdentifier(expected);
81
82         String actual = PathUtils.toString(yangInstanceIdentifier);
83
84         assertEquals(expected, actual);
85
86     }
87
88     private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
89         return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
90     }
91
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"));
94
95         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
96     }
97
98     private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
99         return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
100     }
101
102     private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
103         Map<QName, Object> keys = new HashMap<>();
104
105         keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
106
107         return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
108     }
109 }