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.json.to.cnsn.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
17 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
18 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
19 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
20 import org.opendaylight.yangtools.yang.data.api.Node;
21 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
23 public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
26 public static void initialize() {
27 dataLoad("/json-to-cnsn/leafref");
31 * JSON values which represents leafref are always loaded to simple node as string
34 public void jsonIdentityrefToCompositeNode() {
35 CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/leafref/json/data.json", false,
36 JsonToCompositeNodeProvider.INSTANCE);
37 assertNotNull(compositeNode);
38 TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
40 assertEquals("cont", compositeNode.getNodeType().getLocalName());
42 SimpleNode<?> lf2 = null;
43 for (Node<?> childNode : compositeNode.getValue()) {
44 if (childNode instanceof SimpleNode) {
45 if (childNode.getNodeType().getLocalName().equals("lf2")) {
46 lf2 = (SimpleNode<?>) childNode;
53 assertTrue(lf2.getValue() instanceof String);
54 assertEquals("121", lf2.getValue());