Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / xml / test / CnSnInstanceIdentifierToXmlTest.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.cnsn.to.xml.test;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import java.io.IOException;
13 import java.net.URI;
14 import java.net.URISyntaxException;
15 import javax.ws.rs.WebApplicationException;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
19 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
20 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
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
25 /**
26  *
27  * CnSn = Composite node and Simple node data structure Class contains test of serializing simple nodes data values
28  * according data types from YANG schema to XML file
29  *
30  */
31 public class CnSnInstanceIdentifierToXmlTest extends YangAndXmlAndDataSchemaLoader {
32
33     @BeforeClass
34     public static void initialization() throws URISyntaxException {
35         dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
36     }
37
38     @Test
39     public void snAsYangInstanceIdentifier() throws WebApplicationException, IOException, URISyntaxException {
40         CompositeNode cnSnData = prepareCnStructForYangData();
41         String xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSnData, modules, dataSchemaNode,
42                 StructuredDataToXmlProvider.INSTANCE);
43         assertNotNull(xmlOutput);
44     }
45
46     private CompositeNode prepareCnStructForYangData() throws URISyntaxException {
47         CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont");
48         CompositeNodeWrapper cont1 = new CompositeNodeWrapper(new URI("augment:module"), "cont1");
49         cont.addValue(cont1);
50         SimpleNodeWrapper lf11 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf11", "/cont/cont1/lf12");
51         SimpleNodeWrapper lf12 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf12", "lf12 value");
52         cont1.addValue(lf11);
53         cont1.addValue(lf12);
54         cont.unwrap();
55         return cont;
56     }
57
58 }