Fix a few eclipse-reported warnings
[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 import java.util.Set;
16
17 import javax.ws.rs.WebApplicationException;
18
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.DummyType;
24 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
25 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
26 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
27 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
28 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
29 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
30 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
31 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
32 import org.opendaylight.yangtools.yang.model.api.Module;
33 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
34 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
39
40     private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
41
42     @BeforeClass
43     public static void initialize() {
44         dataLoad("/cnsn-to-json/simple-data-types");
45     }
46
47     @Test
48     public void incorrectTopLevelElementTest() throws WebApplicationException, IOException {
49         String jsonOutput = null;
50         jsonOutput = TestUtils
51                 .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
52                         (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
53                         StructuredDataToJsonProvider.INSTANCE);
54         assertNotNull(jsonOutput);
55         assertTrue(jsonOutput.contains("\"lf1\": \"\""));
56     }
57
58     private CompositeNode prepareCompositeNode() {
59         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
60                 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
61         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
62                 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
63         cont.getChildren().add(lf1);
64         cont.init();
65         return cont;
66     }
67
68     private DataSchemaNode prepareDataSchemaNode() {
69         ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
70                 "simple:uri", "2012-12-17"), null);
71         LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
72                 "simple:uri", "2012-12-17"), null);
73         leafBuild.setType(new DummyType());
74         leafBuild.setConfiguration(true);
75
76         contBuild.addChildNode(leafBuild);
77         return contBuild.build();
78     }
79
80 }