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.assertNotNull;
11 import static org.junit.Assert.assertTrue;
13 import java.io.IOException;
14 import java.util.Collections;
17 import javax.ws.rs.WebApplicationException;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
22 import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
23 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
24 import org.opendaylight.yangtools.yang.data.api.*;
25 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
29 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class CnSnToXmlNotExistingLeafTypeTest {
35 private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class);
39 public void incorrectTopLevelElementTest() {
41 boolean nullPointerExceptionRaised = false;
43 TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
44 (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(), StructuredDataToXmlProvider.INSTANCE);
45 } catch (WebApplicationException | IOException e) {
46 LOG.error("WebApplicationException or IOException was raised");
47 } catch (NullPointerException e) {
48 nullPointerExceptionRaised = true;
50 assertTrue(nullPointerExceptionRaised);
54 private CompositeNode prepareCompositeNode() {
55 MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
56 TestUtils.buildQName("cont", "simple:uri", "2012-12-17"), null, null, ModifyAction.CREATE, null);
57 MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(
58 TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), cont, "any value", ModifyAction.CREATE, null);
59 cont.getChildren().add(lf1);
64 private DataSchemaNode prepareDataSchemaNode() {
65 ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
66 "simple:uri", "2012-12-17"), null);
67 LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1",
68 "simple:uri", "2012-12-17"), null);
69 leafBuild.setType(new DummyType());
70 leafBuild.setConfiguration(true);
72 contBuild.addChildNode(leafBuild);
73 return contBuild.build();