1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.io.IOException;
7 import java.util.Collections;
10 import javax.ws.rs.WebApplicationException;
12 import org.junit.Ignore;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
16 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
17 import org.opendaylight.yangtools.yang.data.api.*;
18 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
22 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class CnSnToXmlNotExistingLeafTypeTest {
28 private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
32 public void incorrectTopLevelElementTest() {
34 String xmlOutput = null;
36 xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
37 (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
38 } catch (WebApplicationException | IOException e) {
39 LOG.error("WebApplicationException or IOException was raised");
41 assertNotNull(xmlOutput);
42 assertTrue(xmlOutput.contains("<lf1>any value</lf1>"));
46 private CompositeNode prepareCompositeNode() {
47 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
48 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
49 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
50 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
51 cont.getChildren().add(lf1);
56 private DataSchemaNode prepareDataSchemaNode() {
57 ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
58 "simple:uri", "2012-12-17"), null);
59 LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
60 "simple:uri", "2012-12-17"), null);
61 leafBuild.setType(new DummyType());
62 leafBuild.setConfiguration(true);
64 contBuild.addChildNode(leafBuild);
65 return contBuild.build(null);