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 CompositeNode compositeNode = TestUtils.readInputToCnSn("/xml-to-cnsn/leafref/xml/data.xml", false,
36 XmlToCompositeNodeProvider.INSTANCE);
37 assertNotNull(compositeNode);
38 assertNotNull(dataSchemaNode);
39 TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath);
41 assertEquals("cont", compositeNode.getNodeType().getLocalName());
43 SimpleNode<?> lf2 = null;
44 for (Node<?> childNode : compositeNode.getValue()) {
45 if (childNode instanceof SimpleNode) {
46 if (childNode.getNodeType().getLocalName().equals("lf2")) {
47 lf2 = (SimpleNode<?>) childNode;
54 assertTrue(lf2.getValue() instanceof String);
55 assertEquals("121", lf2.getValue());
59 public void testXmlBlankInput() throws Exception {
60 InputStream inputStream = new ByteArrayInputStream("".getBytes());
61 CompositeNode compositeNode = XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null,
64 assertNull(compositeNode);
68 public void testXmlBlankInputUnmarkableStream() throws Exception {
69 InputStream inputStream = new ByteArrayInputStream("".getBytes()) {
71 public boolean markSupported() {
75 CompositeNode compositeNode = XmlToCompositeNodeProvider.INSTANCE.readFrom(null, null, null, null, null,
78 assertNull(compositeNode);