5a81b326ab30a130bce2c0265f425166115e60fa
[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
16 import javax.ws.rs.WebApplicationException;
17
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
21 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
22 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
23 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
24 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
25 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
26
27 /**
28  * 
29  * CnSn = Composite node and Simple node data structure Class contains test of
30  * serializing simple nodes data values according data types from YANG schema to
31  * XML file
32  * 
33  */
34 public class CnSnInstanceIdentifierToXmlTest extends YangAndXmlAndDataSchemaLoader {
35     
36     @BeforeClass
37     public static void initialization() throws URISyntaxException {
38         dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
39     }
40
41     @Test
42     public void snAsYangInstanceIdentifier() throws WebApplicationException, IOException, URISyntaxException {
43         CompositeNode cnSnData = prepareCnStructForYangData( );
44         String xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSnData, modules, dataSchemaNode,
45                 StructuredDataToXmlProvider.INSTANCE);
46         assertNotNull(xmlOutput);
47     }
48
49     private CompositeNode prepareCnStructForYangData() throws URISyntaxException {
50         CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont");
51         CompositeNodeWrapper cont1 = new CompositeNodeWrapper(new URI("augment:module"), "cont1");
52         cont.addValue(cont1);
53         SimpleNodeWrapper lf11 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf11", "/cont/cont1/lf12");
54         SimpleNodeWrapper lf12 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf12", "lf12 value");
55         cont1.addValue(lf11);
56         cont1.addValue(lf12);
57         cont.unwrap();
58         return cont;
59     }
60
61 }