Minor changes in md-sal tests.
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonNotExistingLeafTypeTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.IOException;
7 import java.util.Collections;
8 import java.util.Set;
9
10 import javax.ws.rs.WebApplicationException;
11
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;
25
26 public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
27
28     private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
29
30     @BeforeClass
31     public static void initialize() {
32         dataLoad("/cnsn-to-json/simple-data-types");
33     }
34
35     // FIXME
36     @Ignore
37     @Test
38     public void incorrectTopLevelElementTest() {
39
40         String jsonOutput = null;
41         try {
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");
48         }
49         assertNotNull(jsonOutput);
50         assertTrue(jsonOutput.contains("\"lf1\": \"\""));
51     }
52
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);
59         cont.init();
60         return cont;
61     }
62
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);
70
71         contBuild.addChildNode(leafBuild);
72         // FIXME: build method does not accept any arguments
73         //return contBuild.build(null);
74         return null;
75     }
76
77 }