Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / xml / test / CnSnToXmlNotExistingLeafTypeTest.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.xml.test;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.io.IOException;
13 import java.util.Collections;
14 import javax.ws.rs.WebApplicationException;
15 import org.junit.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
18 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
19 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
20 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
21 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
22 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
23 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
24 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
28 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class CnSnToXmlNotExistingLeafTypeTest {
33
34     private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
35
36     @Ignore
37     @Test
38     public void incorrectTopLevelElementTest() {
39
40         boolean nullPointerExceptionRaised = false;
41         try {
42             TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(), Collections.<Module> emptySet(),
43                     prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
44         } catch (WebApplicationException | IOException e) {
45             LOG.error("WebApplicationException or IOException was raised");
46         } catch (NullPointerException e) {
47             nullPointerExceptionRaised = true;
48         }
49         assertTrue(nullPointerExceptionRaised);
50
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.getValue().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         return contBuild.build();
73     }
74
75 }