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 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;
24 import static junit.framework.TestCase.assertEquals;
26 public class PathUtilsTest {
29 public void toStringNodeIdentifier(){
30 PathArgument pathArgument = nodeIdentifier();
32 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test";
34 assertEquals(expected , PathUtils.toString(pathArgument));
38 public void toStringAugmentationIdentifier(){
39 String expected = "AugmentationIdentifier{childNames=[(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics]}";
41 PathArgument pathArgument = augmentationIdentifier();
43 assertEquals(expected, PathUtils.toString(pathArgument));
47 public void toStringNodeWithValue(){
49 PathArgument pathArgument = nodeWithValue();
51 String expected = "(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test[100]";
53 assertEquals(expected, PathUtils.toString(pathArgument));
58 public void toStringNodeIdentifierWithPredicates(){
60 PathArgument pathArgument = nodeIdentifierWithPredicates();
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}]";
64 assertEquals(expected, PathUtils.toString(pathArgument));
68 public void toStringYangInstanceIdentifier(){
70 YangInstanceIdentifier path =
71 YangInstanceIdentifier.create(nodeIdentifier())
72 .node(nodeIdentifierWithPredicates())
73 .node(augmentationIdentifier()).node(nodeWithValue());
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]";
81 assertEquals(expected, PathUtils.toString(path));
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]";
92 YangInstanceIdentifier yangInstanceIdentifier =
93 PathUtils.toYangInstanceIdentifier(expected);
95 String actual = PathUtils.toString(yangInstanceIdentifier);
97 assertEquals(expected, actual);
101 private static NodeIdentifier nodeIdentifier(){
102 return new NodeIdentifier(TestModel.TEST_QNAME);
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"));
108 return new AugmentationIdentifier(childNames);
111 private static NodeWithValue<?> nodeWithValue(){
112 return new NodeWithValue<>(TestModel.TEST_QNAME, Integer.valueOf(100));
115 private static NodeIdentifierWithPredicates nodeIdentifierWithPredicates(){
116 Map<QName, Object> keys = new HashMap<>();
118 keys.put(TestModel.ID_QNAME, Integer.valueOf(100));
120 return new NodeIdentifierWithPredicates(TestModel.TEST_QNAME, keys);