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.json.test;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import java.io.IOException;
14 import java.util.Collections;
17 import javax.ws.rs.WebApplicationException;
19 import org.junit.BeforeClass;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
23 import org.opendaylight.controller.sal.restconf.impl.test.*;
24 import org.opendaylight.yangtools.yang.data.api.*;
25 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
29 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
35 private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
38 public static void initialize() {
39 dataLoad("/cnsn-to-json/simple-data-types");
45 public void incorrectTopLevelElementTest() {
47 String jsonOutput = null;
49 jsonOutput = TestUtils
50 .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
51 (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
52 StructuredDataToJsonProvider.INSTANCE);
53 } catch (WebApplicationException | IOException e) {
54 LOG.error("WebApplicationException or IOException was raised");
56 assertNotNull(jsonOutput);
57 assertTrue(jsonOutput.contains("\"lf1\": \"\""));
60 private CompositeNode prepareCompositeNode() {
61 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
62 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
63 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
64 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
65 cont.getChildren().add(lf1);
70 private DataSchemaNode prepareDataSchemaNode() {
71 ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
72 "simple:uri", "2012-12-17"), null);
73 LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
74 "simple:uri", "2012-12-17"), null);
75 leafBuild.setType(new DummyType());
76 leafBuild.setConfiguration(true);
78 contBuild.addChildNode(leafBuild);
79 return contBuild.build();