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 static junit.framework.TestCase.assertEquals;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.HashMap;
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;
27 public class PathUtilsTest {
30 public void toStringNodeIdentifier() {
31 PathArgument pathArgument = nodeIdentifier();
34 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
36 assertEquals(expected , PathUtils.toString(pathArgument));
40 public void toStringAugmentationIdentifier() {
42 "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)"
43 + "flow-table-statistics]}";
45 PathArgument pathArgument = augmentationIdentifier();
47 assertEquals(expected, PathUtils.toString(pathArgument));
51 public void toStringNodeWithValue() {
53 PathArgument pathArgument = nodeWithValue();
56 "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
58 assertEquals(expected, PathUtils.toString(pathArgument));
63 public void toStringNodeIdentifierWithPredicates() {
65 PathArgument pathArgument = nodeIdentifierWithPredicates();
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}]";
71 assertEquals(expected, PathUtils.toString(pathArgument));
75 public void toStringYangInstanceIdentifier() {
77 YangInstanceIdentifier path =
78 YangInstanceIdentifier.create(nodeIdentifier())
79 .node(nodeIdentifierWithPredicates())
80 .node(augmentationIdentifier()).node(nodeWithValue());
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]";
91 assertEquals(expected, PathUtils.toString(path));
96 public void toYangInstanceIdentifier() {
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]";
105 YangInstanceIdentifier yangInstanceIdentifier =
106 PathUtils.toYangInstanceIdentifier(expected);
108 String actual = PathUtils.toString(yangInstanceIdentifier);
110 assertEquals(expected, actual);
114 private static NodeIdentifier nodeIdentifier() {
115 return new NodeIdentifier(TestModel.TEST_QNAME);
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"));
122 return new AugmentationIdentifier(childNames);
125 private static NodeWithValue<?> nodeWithValue() {
126 return new NodeWithValue<>(TestModel.TEST_QNAME, Integer.valueOf(100));
129 private static NodeIdentifierWithPredicates nodeIdentifierWithPredicates() {
130 Map<QName, Object> keys = new HashMap<>();
132 keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
134 return new NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);