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.CompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
23 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
24 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
25 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
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
34 public class CnSnToXmlWithChoiceTest extends YangAndXmlAndDataSchemaLoader {
36 public static void initialization() {
37 dataLoad("/cnsn-to-xml/choice", 1, "module-with-choice", "cont");
41 public void cnSnToXmlWithYangChoice() {
42 String xmlOutput = "";
44 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
45 prepareCnStructForYangData("lf1", "String data1"), modules, dataSchemaNode,
46 StructuredDataToXmlProvider.INSTANCE);
47 } catch (WebApplicationException | IOException e) {
50 assertTrue(xmlOutput.contains("<lf1>String data1</lf1>"));
53 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(
54 prepareCnStructForYangData("lf2", "String data2"), modules, dataSchemaNode,
55 StructuredDataToXmlProvider.INSTANCE);
56 } catch (WebApplicationException | IOException e) {
58 assertTrue(xmlOutput.contains("<lf2>String data2</lf2>"));
62 private CompositeNode prepareCnStructForYangData(final String lfName, final Object data) {
63 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
64 ModifyAction.CREATE, null);
66 MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(lfName), cont, data,
67 ModifyAction.CREATE, null);
68 cont.getValue().add(lf1);