Fix CS warnings in sal-clustering-commons and enable enforcement
[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 static junit.framework.TestCase.assertEquals;
12
13 import com.google.common.collect.ImmutableSet;
14 import java.util.HashMap;
15 import java.util.Map;
16 import java.util.Set;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.datastore.util.TestModel;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
26
27 public class PathUtilsTest {
28
29     @Test
30     public void toStringNodeIdentifier() {
31         PathArgument pathArgument = nodeIdentifier();
32
33         String expected =
34             "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
35
36         assertEquals(expected , PathUtils.toString(pathArgument));
37     }
38
39     @Test
40     public void toStringAugmentationIdentifier() {
41         String expected =
42             "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)"
43             + "flow-table-statistics]}";
44
45         PathArgument pathArgument = augmentationIdentifier();
46
47         assertEquals(expected, PathUtils.toString(pathArgument));
48     }
49
50     @Test
51     public void toStringNodeWithValue() {
52
53         PathArgument pathArgument = nodeWithValue();
54
55         String expected =
56                 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
57
58         assertEquals(expected, PathUtils.toString(pathArgument));
59     }
60
61
62     @Test
63     public void toStringNodeIdentifierWithPredicates() {
64
65         PathArgument pathArgument = nodeIdentifierWithPredicates();
66
67         String expected =
68                 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test["
69                 + "{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]";
70
71         assertEquals(expected, PathUtils.toString(pathArgument));
72     }
73
74     @Test
75     public void toStringYangInstanceIdentifier() {
76
77         YangInstanceIdentifier path =
78             YangInstanceIdentifier.create(nodeIdentifier())
79                 .node(nodeIdentifierWithPredicates())
80                 .node(augmentationIdentifier()).node(nodeWithValue());
81
82
83         String expected =
84             "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/"
85             + "(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)id=100}]/"
87             + "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)"
88             + "flow-table-statistics]}/"
89             + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
90
91         assertEquals(expected, PathUtils.toString(path));
92
93     }
94
95     @Test
96     public void toYangInstanceIdentifier() {
97         String expected =
98             "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/"
99             + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test["
100             + "{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=100}]/"
101             + "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)"
102             + "flow-table-statistics]}/"
103             + "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
104
105         YangInstanceIdentifier yangInstanceIdentifier =
106             PathUtils.toYangInstanceIdentifier(expected);
107
108         String actual = PathUtils.toString(yangInstanceIdentifier);
109
110         assertEquals(expected, actual);
111
112     }
113
114     private static NodeIdentifier nodeIdentifier() {
115         return new NodeIdentifier(TestModel.TEST_QNAME);
116     }
117
118     private static AugmentationIdentifier augmentationIdentifier() {
119         Set<QName> childNames = ImmutableSet.of(QNameFactory.create(
120                 "(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
121
122         return new AugmentationIdentifier(childNames);
123     }
124
125     private static NodeWithValue<?> nodeWithValue() {
126         return new NodeWithValue<>(TestModel.TEST_QNAME, Integer.valueOf(100));
127     }
128
129     private static NodeIdentifierWithPredicates nodeIdentifierWithPredicates() {
130         Map<QName, Object> keys = new HashMap<>();
131
132         keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
133
134         return new NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);
135     }
136 }