2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
10 import static org.junit.Assert.assertTrue;
12 import java.io.IOException;
13 import java.util.Collections;
15 import javax.ws.rs.WebApplicationException;
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;
34 public class CnSnToXmlNotExistingLeafTypeTest {
36 private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
40 public void incorrectTopLevelElementTest() {
42 boolean nullPointerExceptionRaised = false;
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;
51 assertTrue(nullPointerExceptionRaised);
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);
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);
73 contBuild.addChildNode(leafBuild);
74 return contBuild.build();