1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.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.BeforeClass;
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
16 import org.opendaylight.controller.sal.restconf.impl.test.*;
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 CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
28 private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
31 public static void initialize() {
32 dataLoad("/cnsn-to-json/simple-data-types");
38 public void incorrectTopLevelElementTest() {
40 String jsonOutput = null;
42 jsonOutput = TestUtils
43 .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
44 (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
45 StructuredDataToJsonProvider.INSTANCE);
46 } catch (WebApplicationException | IOException e) {
47 LOG.error("WebApplicationException or IOException was raised");
49 assertNotNull(jsonOutput);
50 assertTrue(jsonOutput.contains("\"lf1\": \"\""));
53 private CompositeNode prepareCompositeNode() {
54 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
55 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
56 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
57 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
58 cont.getChildren().add(lf1);
63 private DataSchemaNode prepareDataSchemaNode() {
64 ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
65 "simple:uri", "2012-12-17"), null);
66 LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
67 "simple:uri", "2012-12-17"), null);
68 leafBuild.setType(new DummyType());
69 leafBuild.setConfiguration(true);
71 contBuild.addChildNode(leafBuild);
72 return contBuild.build();