2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.sal.restconf.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
16 import javax.ws.rs.WebApplicationException;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
21 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
24 import org.opendaylight.yangtools.yang.data.api.Node;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
29 final QName refContQName = QName.create("referenced:module", "2014-04-17", "cont");
30 final QName refLf1QName = QName.create(refContQName, "lf1");
31 final QName contQName = QName.create("leafref:module", "2014-04-17", "cont");
32 final QName lf1QName = QName.create(contQName, "lf1");
33 final QName lf2QName = QName.create(contQName, "lf2");
34 final QName lf3QName = QName.create(contQName, "lf3");
37 public static void initialize() {
38 dataLoad("/leafref/yang", 2, "leafref-module", "cont");
42 public void loadXmlToCnSn() throws WebApplicationException, IOException, URISyntaxException {
43 Node<?> node = TestUtils.readInputToCnSn("/leafref/xml/xmldata.xml", XmlToCompositeNodeProvider.INSTANCE);
45 assertTrue(node instanceof CompositeNode);
46 CompositeNode cnSn = (CompositeNode)node;
48 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
50 verifyContPredicate(cnSn, "lf4", YangInstanceIdentifier.builder().node(refContQName).node(refLf1QName).build());
51 verifyContPredicate(cnSn, "lf2", YangInstanceIdentifier.builder().node(contQName).node(lf1QName).build());
52 verifyContPredicate(cnSn, "lf3", YangInstanceIdentifier.builder().node(contQName).node(lf2QName).build());
53 verifyContPredicate(cnSn, "lf5", YangInstanceIdentifier.builder().node(contQName).node(lf3QName).build());
57 public void loadJsonToCnSn() throws WebApplicationException, IOException, URISyntaxException {
58 Node<?> node = TestUtils.readInputToCnSn("/leafref/json/jsondata.json",
59 JsonToCompositeNodeProvider.INSTANCE);
60 assertTrue(node instanceof CompositeNode);
61 CompositeNode cnSn = (CompositeNode)node;
63 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
65 verifyContPredicate(cnSn, "lf4", YangInstanceIdentifier.builder().node(refContQName).node(refLf1QName).build());
66 verifyContPredicate(cnSn, "lf2", YangInstanceIdentifier.builder().node(contQName).node(lf1QName).build());
67 verifyContPredicate(cnSn, "lf3", YangInstanceIdentifier.builder().node(contQName).node(lf2QName).build());
68 verifyContPredicate(cnSn, "lf5", YangInstanceIdentifier.builder().node(contQName).node(lf3QName).build());
71 private void verifyContPredicate(CompositeNode cnSn, String leafName, Object value) throws URISyntaxException {
74 for (final Node<?> node : cnSn.getValue()) {
75 if (node.getNodeType().getLocalName().equals(leafName)) {
76 parsed = node.getValue();
80 assertEquals(value, parsed);