Merge "Prevent ConfigPusher from killing its thread"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / xml / test / CnSnToXmlWithChoiceTest.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.assertTrue;
11
12 import java.io.IOException;
13
14 import javax.ws.rs.WebApplicationException;
15
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.test.TestUtils;
20 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
21 import org.opendaylight.yangtools.yang.data.api.*;
22 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
23
24 /**
25  * 
26  * CnSn = Composite node and Simple node data structure Class contains test of
27  * serializing simple nodes data values according data types from YANG schema to
28  * XML file
29  * 
30  */
31 public class CnSnToXmlWithChoiceTest extends YangAndXmlAndDataSchemaLoader {
32     @BeforeClass
33     public static void initialization() {
34         dataLoad("/cnsn-to-xml/choice", 1, "module-with-choice", "cont");
35     }
36
37     @Test
38     public void cnSnToXmlWithYangChoice() {
39         String xmlOutput = "";
40         try {
41             xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
42                     prepareCnStructForYangData("lf1", "String data1"), modules, dataSchemaNode,
43                     StructuredDataToXmlProvider.INSTANCE);
44         } catch (WebApplicationException | IOException e) {
45         }
46
47         assertTrue(xmlOutput.contains("<lf1>String data1</lf1>"));
48
49         try {
50             xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
51                     prepareCnStructForYangData("lf2", "String data2"), modules, dataSchemaNode,
52                     StructuredDataToXmlProvider.INSTANCE);
53         } catch (WebApplicationException | IOException e) {
54         }
55         assertTrue(xmlOutput.contains("<lf2>String data2</lf2>"));
56
57     }
58
59     private CompositeNode prepareCnStructForYangData(String lfName, Object data) {
60         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
61                 ModifyAction.CREATE, null);
62
63         MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(lfName), cont, data,
64                 ModifyAction.CREATE, null);
65         cont.getChildren().add(lf1);
66         cont.init();
67
68         return cont;
69     }
70
71 }