sal-rest-connector 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         boolean nullPointerExceptionRaised = false;
35         try {
36             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         } catch (NullPointerException e) {
41             nullPointerExceptionRaised = true;
42         }
43         assertTrue(nullPointerExceptionRaised);
44
45     }
46
47     private CompositeNode prepareCompositeNode() {
48         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
49                 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
50         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
51                 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
52         cont.getChildren().add(lf1);
53         cont.init();
54         return cont;
55     }
56
57     private DataSchemaNode prepareDataSchemaNode() {
58         ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
59                 "simple:uri", "2012-12-17"), null);
60         LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
61                 "simple:uri", "2012-12-17"), null);
62         leafBuild.setType(new DummyType());
63         leafBuild.setConfiguration(true);
64
65         contBuild.addChildNode(leafBuild);
66         return contBuild.build(null);
67
68     }
69
70 }