2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.node.utils;
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;
19 import static junit.framework.TestCase.assertEquals;
21 public class PathUtilsTest {
24 public void toStringNodeIdentifier(){
25 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
27 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
29 assertEquals(expected , PathUtils.toString(pathArgument));
33 public void toStringAugmentationIdentifier(){
34 String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
36 YangInstanceIdentifier.PathArgument pathArgument = augmentationIdentifier();
38 assertEquals(expected, PathUtils.toString(pathArgument));
42 public void toStringNodeWithValue(){
44 YangInstanceIdentifier.PathArgument pathArgument = nodeWithValue();
46 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
48 assertEquals(expected, PathUtils.toString(pathArgument));
53 public void toStringNodeIdentifierWithPredicates(){
55 YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifierWithPredicates();
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}]";
59 assertEquals(expected, PathUtils.toString(pathArgument));
63 public void toStringYangInstanceIdentifier(){
65 YangInstanceIdentifier path =
66 YangInstanceIdentifier.create(nodeIdentifier())
67 .node(nodeIdentifierWithPredicates())
68 .node(augmentationIdentifier()).node(nodeWithValue());
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]";
76 assertEquals(expected, PathUtils.toString(path));
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]";
87 YangInstanceIdentifier yangInstanceIdentifier =
88 PathUtils.toYangInstanceIdentifier(expected);
90 String actual = PathUtils.toString(yangInstanceIdentifier);
92 assertEquals(expected, actual);
96 private YangInstanceIdentifier.NodeIdentifier nodeIdentifier(){
97 return new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME);
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"));
103 return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
106 private YangInstanceIdentifier.NodeWithValue nodeWithValue(){
107 return new YangInstanceIdentifier.NodeWithValue(TestModel.TEST_QNAME, Integer.valueOf(100));
110 private YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
111 Map<QName, Object> keys = new HashMap<>();
113 keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
115 return new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);