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.xml.to.cnsn.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import java.io.ByteArrayInputStream;
16 import java.io.InputStream;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
21 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
22 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
23 import org.opendaylight.yangtools.yang.data.api.Node;
24 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
26 public class XmlToCnSnTest extends YangAndXmlAndDataSchemaLoader {
29 public static void initialize() {
30 dataLoad("/xml-to-cnsn/leafref");
34 public void testXmlLeafrefToCnSn() {
35 Node<?> node = TestUtils.readInputToCnSn("/xml-to-cnsn/leafref/xml/data.xml", false,
36 XmlToCompositeNodeProvider.INSTANCE);
37 assertTrue(node instanceof CompositeNode);
38 CompositeNode compositeNode = (CompositeNode)node;
41 assertNotNull(dataSchemaNode);
42 TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath);
44 assertEquals("cont", compositeNode.getNodeType().getLocalName());
46 SimpleNode<?> lf2 = null;
47 for (Node<?> childNode : compositeNode.getValue()) {
48 if (childNode instanceof SimpleNode) {
49 if (childNode.getNodeType().getLocalName().equals("lf2")) {
50 lf2 = (SimpleNode<?>) childNode;
57 assertEquals(121, lf2.getValue());
61 public void testXmlBlankInput() throws Exception {
62 InputStream inputStream = new ByteArrayInputStream("".getBytes());
64 XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null, inputStream);
70 public void testXmlBlankInputUnmarkableStream() throws Exception {
71 InputStream inputStream = new ByteArrayInputStream("".getBytes()) {
73 public boolean markSupported() {
78 XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null, inputStream);