Merge "BUG-509: introduce Version concept"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / xml / to / cnsn / test / XmlToCnSnTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.restconf.impl.xml.to.cnsn.test;
9
10 import static org.junit.Assert.*;
11
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
16 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
17 import org.opendaylight.yangtools.yang.data.api.*;
18
19 public class XmlToCnSnTest extends YangAndXmlAndDataSchemaLoader {
20
21     @BeforeClass
22     public static void initialize() {
23         dataLoad("/xml-to-cnsn/leafref");
24     }
25
26     @Test
27     public void testXmlLeafrefToCnSn() {
28         CompositeNode compositeNode = TestUtils.readInputToCnSn("/xml-to-cnsn/leafref/xml/data.xml", false,
29                 XmlToCompositeNodeProvider.INSTANCE);
30         assertNotNull(compositeNode);
31         assertNotNull(dataSchemaNode);
32         TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath);
33
34         assertEquals("cont", compositeNode.getNodeType().getLocalName());
35
36         SimpleNode<?> lf2 = null;
37         for (Node<?> childNode : compositeNode.getChildren()) {
38             if (childNode instanceof SimpleNode) {
39                 if (childNode.getNodeType().getLocalName().equals("lf2")) {
40                     lf2 = (SimpleNode<?>) childNode;
41                     break;
42                 }
43             }
44         }
45
46         assertNotNull(lf2);
47         assertTrue(lf2.getValue() instanceof String);
48         assertEquals("121", (String) lf2.getValue());
49     }
50
51 }