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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.