BUG-868: migrate users of CompositeNode.getChildren()
[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.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
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;
22
23 public class XmlToCnSnTest extends YangAndXmlAndDataSchemaLoader {
24
25     @BeforeClass
26     public static void initialize() {
27         dataLoad("/xml-to-cnsn/leafref");
28     }
29
30     @Test
31     public void testXmlLeafrefToCnSn() {
32         CompositeNode compositeNode = TestUtils.readInputToCnSn("/xml-to-cnsn/leafref/xml/data.xml", false,
33                 XmlToCompositeNodeProvider.INSTANCE);
34         assertNotNull(compositeNode);
35         assertNotNull(dataSchemaNode);
36         TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath);
37
38         assertEquals("cont", compositeNode.getNodeType().getLocalName());
39
40         SimpleNode<?> lf2 = null;
41         for (Node<?> childNode : compositeNode.getValue()) {
42             if (childNode instanceof SimpleNode) {
43                 if (childNode.getNodeType().getLocalName().equals("lf2")) {
44                     lf2 = (SimpleNode<?>) childNode;
45                     break;
46                 }
47             }
48         }
49
50         assertNotNull(lf2);
51         assertTrue(lf2.getValue() instanceof String);
52         assertEquals("121", lf2.getValue());
53     }
54
55 }