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;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
21 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
22 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
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.SimpleNode;
27 public class XmlToCnSnTest extends YangAndXmlAndDataSchemaLoader {
30 public static void initialize() {
31 dataLoad("/xml-to-cnsn/leafref");
35 public void testXmlLeafrefToCnSn() {
36 CompositeNode compositeNode = TestUtils.readInputToCnSn("/xml-to-cnsn/leafref/xml/data.xml", false,
37 XmlToCompositeNodeProvider.INSTANCE);
38 assertNotNull(compositeNode);
39 assertNotNull(dataSchemaNode);
40 TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath);
42 assertEquals("cont", compositeNode.getNodeType().getLocalName());
44 SimpleNode<?> lf2 = null;
45 for (Node<?> childNode : compositeNode.getValue()) {
46 if (childNode instanceof SimpleNode) {
47 if (childNode.getNodeType().getLocalName().equals("lf2")) {
48 lf2 = (SimpleNode<?>) childNode;
55 assertTrue(lf2.getValue() instanceof String);
56 assertEquals("121", lf2.getValue());
60 public void testXmlBlankInput() throws Exception{
61 InputStream inputStream = new ByteArrayInputStream( "".getBytes() );
62 CompositeNode compositeNode =
63 XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null, inputStream);
65 assertNull( compositeNode );
69 public void testXmlBlankInputUnmarkableStream() throws Exception{
70 InputStream inputStream = new ByteArrayInputStream( "".getBytes() ){
72 public boolean markSupported() {
76 CompositeNode compositeNode =
77 XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null, inputStream);
79 assertNull( compositeNode );