2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
10 import static org.junit.Assert.assertTrue;
12 import java.io.IOException;
14 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.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;
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
31 public class CnSnToXmlWithChoiceTest extends YangAndXmlAndDataSchemaLoader {
33 public static void initialization() {
34 dataLoad("/cnsn-to-xml/choice", 1, "module-with-choice", "cont");
38 public void cnSnToXmlWithYangChoice() {
39 String xmlOutput = "";
41 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
42 prepareCnStructForYangData("lf1", "String data1"), modules, dataSchemaNode,
43 StructuredDataToXmlProvider.INSTANCE);
44 } catch (WebApplicationException | IOException e) {
47 assertTrue(xmlOutput.contains("<lf1>String data1</lf1>"));
50 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
51 prepareCnStructForYangData("lf2", "String data2"), modules, dataSchemaNode,
52 StructuredDataToXmlProvider.INSTANCE);
53 } catch (WebApplicationException | IOException e) {
55 assertTrue(xmlOutput.contains("<lf2>String data2</lf2>"));
59 private CompositeNode prepareCnStructForYangData(String lfName, Object data) {
60 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
61 ModifyAction.CREATE, null);
63 MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(lfName), cont, data,
64 ModifyAction.CREATE, null);
65 cont.getChildren().add(lf1);