3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 package org.opendaylight.controller.cluster.datastore.util;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.HashSet;
22 import java.util.List;
24 public class InstanceIdentifierUtilsTest {
26 private static QName TEST_QNAME =
28 .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test");
29 private static QName NODE_WITH_VALUE_QNAME =
31 .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)value");
32 private static QName NODE_WITH_PREDICATES_QNAME =
34 .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)pred");
35 private static QName NAME_QNAME =
37 .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)name");
40 public void testSerializationOfNodeIdentifier() {
41 YangInstanceIdentifier.PathArgument p1 =
42 new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
44 List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
48 YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
50 NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
51 InstanceIdentifierUtils.toSerializable(expected);
53 YangInstanceIdentifier actual =
54 InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
57 Assert.assertEquals(expected.getLastPathArgument(),
58 actual.getLastPathArgument());
64 public void testSerializationOfNodeWithValue() {
73 private void withValue(Object value) {
74 YangInstanceIdentifier.PathArgument p1 =
75 new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
77 YangInstanceIdentifier.PathArgument p2 =
78 new YangInstanceIdentifier.NodeWithValue(NODE_WITH_VALUE_QNAME, value);
81 List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
86 YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
88 NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
89 InstanceIdentifierUtils.toSerializable(expected);
91 YangInstanceIdentifier actual =
92 InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
95 Assert.assertEquals(expected.getLastPathArgument(),
96 actual.getLastPathArgument());
101 public void testSerializationOfNodeIdentifierWithPredicates() {
103 withPredicates((short) 1);
104 withPredicates((long) 2);
106 withPredicates(true);
110 private void withPredicates(Object value) {
111 YangInstanceIdentifier.PathArgument p1 =
112 new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
114 YangInstanceIdentifier.PathArgument p2 =
115 new YangInstanceIdentifier.NodeIdentifierWithPredicates(
116 NODE_WITH_PREDICATES_QNAME, NAME_QNAME, value);
119 List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
124 YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
126 NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
127 InstanceIdentifierUtils.toSerializable(expected);
129 YangInstanceIdentifier actual =
130 InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
133 Assert.assertEquals(expected.getLastPathArgument(),
134 actual.getLastPathArgument());
138 public void testAugmentationIdentifier() {
139 YangInstanceIdentifier.PathArgument p1 =
140 new YangInstanceIdentifier.AugmentationIdentifier(new HashSet(
141 Arrays.asList(TEST_QNAME)));
143 List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
147 YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
149 NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
150 InstanceIdentifierUtils.toSerializable(expected);
152 YangInstanceIdentifier actual =
153 InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
156 Assert.assertEquals(expected.getLastPathArgument(),
157 actual.getLastPathArgument());