Fix raw type warnings
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / utils / PathUtilsTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.datastore.node.utils;
10
11 import com.google.common.collect.ImmutableSet;
12 import org.junit.Test;
13 import org.opendaylight.controller.cluster.datastore.util.TestModel;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Set;
24 import static junit.framework.TestCase.assertEquals;
25
26 public class PathUtilsTest {
27
28     @Test
29     public void toStringNodeIdentifier(){
30         PathArgument pathArgument = nodeIdentifier();
31
32         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
33
34         assertEquals(expected , PathUtils.toString(pathArgument));
35     }
36
37     @Test
38     public void toStringAugmentationIdentifier(){
39         String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
40
41         PathArgument pathArgument = augmentationIdentifier();
42
43         assertEquals(expected, PathUtils.toString(pathArgument));
44     }
45
46     @Test
47     public void toStringNodeWithValue(){
48
49         PathArgument pathArgument = nodeWithValue();
50
51         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
52
53         assertEquals(expected, PathUtils.toString(pathArgument));
54     }
55
56
57     @Test
58     public void toStringNodeIdentifierWithPredicates(){
59
60         PathArgument pathArgument = nodeIdentifierWithPredicates();
61
62         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}]";
63
64         assertEquals(expected, PathUtils.toString(pathArgument));
65     }
66
67     @Test
68     public void toStringYangInstanceIdentifier(){
69
70         YangInstanceIdentifier path =
71             YangInstanceIdentifier.create(nodeIdentifier())
72                 .node(nodeIdentifierWithPredicates())
73                 .node(augmentationIdentifier()).node(nodeWithValue());
74
75
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         assertEquals(expected, PathUtils.toString(path));
82
83     }
84
85     @Test
86     public void toYangInstanceIdentifier(){
87         String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/" +
88             "(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}]/" +
89             "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}/" +
90             "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
91
92         YangInstanceIdentifier yangInstanceIdentifier =
93             PathUtils.toYangInstanceIdentifier(expected);
94
95         String actual = PathUtils.toString(yangInstanceIdentifier);
96
97         assertEquals(expected, actual);
98
99     }
100
101     private static NodeIdentifier nodeIdentifier(){
102         return new NodeIdentifier(TestModel.TEST_QNAME);
103     }
104
105     private static AugmentationIdentifier augmentationIdentifier(){
106         Set<QName> childNames = ImmutableSet.of(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
107
108         return new AugmentationIdentifier(childNames);
109     }
110
111     private static NodeWithValue<?> nodeWithValue(){
112         return new NodeWithValue<>(TestModel.TEST_QNAME, Integer.valueOf(100));
113     }
114
115     private static NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
116         Map<QName, Object> keys = new HashMap<>();
117
118         keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
119
120         return new NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
121     }
122 }