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;
12 import java.io.IOException;
13 import java.net.URISyntaxException;
15 import javax.ws.rs.WebApplicationException;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
21 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.Node;
23 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
25 public class XmlAndJsonToCnSnLeafRefTest extends YangAndXmlAndDataSchemaLoader {
28 public static void initialize() {
29 dataLoad("/leafref/yang", 2, "leafref-module", "cont");
33 public void loadXmlToCnSn() throws WebApplicationException, IOException, URISyntaxException {
34 CompositeNode cnSn = TestUtils.readInputToCnSn("/leafref/xml/xmldata.xml", XmlToCompositeNodeProvider.INSTANCE);
35 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
36 verifyContPredicate(cnSn, "/ns:cont/ns:lf1", "/cont/lf1", "/ns:cont/ns:lf1", "../lf1");
40 public void loadJsonToCnSn() throws WebApplicationException, IOException, URISyntaxException {
41 CompositeNode cnSn = TestUtils.readInputToCnSn("/leafref/json/jsondata.json",
42 JsonToCompositeNodeProvider.INSTANCE);
43 TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
44 verifyContPredicate(cnSn, "/leafref-module:cont/leafref-module:lf1", "/leafref-module:cont/leafref-module:lf1",
45 "/referenced-module:cont/referenced-module:lf1", "/leafref-module:cont/leafref-module:lf1");
48 private void verifyContPredicate(CompositeNode cnSn, String... values) throws URISyntaxException {
49 Object lf2Value = null;
50 Object lf3Value = null;
51 Object lf4Value = null;
52 Object lf5Value = null;
54 for (Node<?> node : cnSn.getValue()) {
55 if (node.getNodeType().getLocalName().equals("lf2")) {
56 lf2Value = ((SimpleNode<?>) node).getValue();
57 } else if (node.getNodeType().getLocalName().equals("lf3")) {
58 lf3Value = ((SimpleNode<?>) node).getValue();
59 } else if (node.getNodeType().getLocalName().equals("lf4")) {
60 lf4Value = ((SimpleNode<?>) node).getValue();
61 } else if (node.getNodeType().getLocalName().equals("lf5")) {
62 lf5Value = ((SimpleNode<?>) node).getValue();
65 assertEquals(values[0], lf2Value);
66 assertEquals(values[1], lf3Value);
67 assertEquals(values[2], lf4Value);
68 assertEquals(values[3], lf5Value);