BUG-868: migrate users of CompositeNode.getChildren()
[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
15 import javax.ws.rs.WebApplicationException;
16
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
20 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
21 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
22 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
23 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
24 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
25 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
26 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
27 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.Module;
29 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
30 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class CnSnToXmlNotExistingLeafTypeTest {
35
36     private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
37
38     @Ignore
39     @Test
40     public void incorrectTopLevelElementTest() {
41
42         boolean nullPointerExceptionRaised = false;
43         try {
44             TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
45                     Collections.<Module>emptySet(), prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
46         } catch (WebApplicationException | IOException e) {
47             LOG.error("WebApplicationException or IOException was raised");
48         } catch (NullPointerException e) {
49             nullPointerExceptionRaised = true;
50         }
51         assertTrue(nullPointerExceptionRaised);
52
53     }
54
55     private CompositeNode prepareCompositeNode() {
56         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
57                 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
58         MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
59                 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
60         cont.getValue().add(lf1);
61         cont.init();
62         return cont;
63     }
64
65     private DataSchemaNode prepareDataSchemaNode() {
66         ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
67                 "simple:uri", "2012-12-17"), null);
68         LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
69                 "simple:uri", "2012-12-17"), null);
70         leafBuild.setType(new DummyType());
71         leafBuild.setConfiguration(true);
72
73         contBuild.addChildNode(leafBuild);
74         return contBuild.build();
75     }
76
77 }