Merge "BUG-509: introduce Version concept"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonNotExistingLeafTypeTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12
13 import java.io.IOException;
14 import java.util.Collections;
15
16 import javax.ws.rs.WebApplicationException;
17
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
21 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
22 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
23 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
24 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
25 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
26 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
27 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
28 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
29 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
30 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
31 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
36
37     private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
38
39     @BeforeClass
40     public static void initialize() {
41         dataLoad("/cnsn-to-json/simple-data-types");
42     }
43
44     @Test
45     public void incorrectTopLevelElementTest() throws WebApplicationException, IOException {
46         String jsonOutput = null;
47         jsonOutput = TestUtils
48                 .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
49                         Collections.EMPTY_SET, prepareDataSchemaNode(),
50                         StructuredDataToJsonProvider.INSTANCE);
51         assertNotNull(jsonOutput);
52         assertTrue(jsonOutput.contains("\"lf1\": \"\""));
53     }
54
55     private CompositeNode prepareCompositeNode() {
56         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
57                 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
58         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
59                 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
60         cont.getChildren().add(lf1);
61         cont.init();
62         return cont;
63     }
64
65     private DataSchemaNode prepareDataSchemaNode() {
66         ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
67                 "simple:uri", "2012-12-17"), null);
68         LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
69                 "simple:uri", "2012-12-17"), null);
70         leafBuild.setType(new DummyType());
71         leafBuild.setConfiguration(true);
72
73         contBuild.addChildNode(leafBuild);
74         return contBuild.build();
75     }
76
77 }