1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.IOException;
7 import javax.ws.rs.WebApplicationException;
9 import org.junit.BeforeClass;
10 import org.junit.Test;
11 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
12 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
13 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
14 import org.opendaylight.yangtools.yang.data.api.*;
15 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
19 * CnSn = Composite node and Simple node data structure Class contains test of
20 * serializing simple nodes data values according data types from YANG schema to
24 public class CnSnToXmlWithChoiceTest extends YangAndXmlAndDataSchemaLoader {
26 public static void initialization() {
27 dataLoad("/cnsn-to-xml/choice", 1, "module-with-choice", "cont");
31 public void cnSnToXmlWithYangChoice() {
32 String xmlOutput = "";
34 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
35 prepareCnStructForYangData("lf1", "String data1"), modules, dataSchemaNode,
36 StructuredDataToXmlProvider.INSTANCE);
37 } catch (WebApplicationException | IOException e) {
40 assertTrue(xmlOutput.contains("<lf1>String data1</lf1>"));
43 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
44 prepareCnStructForYangData("lf2", "String data2"), modules, dataSchemaNode,
45 StructuredDataToXmlProvider.INSTANCE);
46 } catch (WebApplicationException | IOException e) {
48 assertTrue(xmlOutput.contains("<lf2>String data2</lf2>"));
52 private CompositeNode prepareCnStructForYangData(String lfName, Object data) {
53 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
54 ModifyAction.CREATE, null);
56 MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(lfName), cont, data,
57 ModifyAction.CREATE, null);
58 cont.getChildren().add(lf1);