More test for improving of code coverage + test refactoring
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / xml / test / CnSnToXmlNotExistingLeafTypeTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.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.Ignore;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
16 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
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 CnSnToXmlNotExistingLeafTypeTest {
27
28     private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
29
30     @Ignore
31     @Test
32     public void incorrectTopLevelElementTest() {
33
34         String xmlOutput = null;
35         try {
36             xmlOutput = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
37                     (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
38         } catch (WebApplicationException | IOException e) {
39             LOG.error("WebApplicationException or IOException was raised");
40         }
41         assertNotNull(xmlOutput);
42         assertTrue(xmlOutput.contains("<lf1>any value</lf1>"));
43
44     }
45
46     private CompositeNode prepareCompositeNode() {
47         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
48                 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
49         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
50                 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
51         cont.getChildren().add(lf1);
52         cont.init();
53         return cont;
54     }
55
56     private DataSchemaNode prepareDataSchemaNode() {
57         ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
58                 "simple:uri", "2012-12-17"), null);
59         LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
60                 "simple:uri", "2012-12-17"), null);
61         leafBuild.setType(new DummyType());
62         leafBuild.setConfiguration(true);
63
64         contBuild.addChildNode(leafBuild);
65         return contBuild.build(null);
66
67     }
68
69 }