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.Test;
14 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.*;
16 import org.opendaylight.yangtools.yang.data.api.*;
17 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
21 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
27 private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
30 public static void initialize() {
31 dataLoad("/cnsn-to-json/simple-data-types");
35 public void incorrectTopLevelElementTest() {
37 String jsonOutput = null;
39 jsonOutput = TestUtils
40 .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
41 (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
42 StructuredDataToJsonProvider.INSTANCE);
43 } catch (WebApplicationException | IOException e) {
44 LOG.error("WebApplicationException or IOException was raised");
46 assertNotNull(jsonOutput);
47 assertTrue(jsonOutput.contains("\"lf1\": \"\""));
50 private CompositeNode prepareCompositeNode() {
51 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
52 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
53 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
54 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
55 cont.getChildren().add(lf1);
60 private DataSchemaNode prepareDataSchemaNode() {
61 ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
62 "simple:uri", "2012-12-17"), null);
63 LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
64 "simple:uri", "2012-12-17"), null);
65 leafBuild.setType(new DummyType());
66 leafBuild.setConfiguration(true);
68 contBuild.addChildNode(leafBuild);
69 return contBuild.build(null);