1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.io.IOException;
7 import java.util.Collections;
10 import javax.ws.rs.WebApplicationException;
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;
26 public class CnSnToXmlNotExistingLeafTypeTest {
28 private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
32 public void incorrectTopLevelElementTest() {
34 boolean nullPointerExceptionRaised = false;
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;
43 assertTrue(nullPointerExceptionRaised);
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);
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);
65 contBuild.addChildNode(leafBuild);
66 return contBuild.build();