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.nn.to.xml.test;
10 import java.io.ByteArrayOutputStream;
11 import java.io.OutputStream;
12 import javax.ws.rs.core.MediaType;
13 import org.junit.Test;
14 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
15 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
16 import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
17 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
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.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
23 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
24 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
25 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
30 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
32 public class NnToXmlNotExistingLeafTypeTest extends AbstractBodyReaderTest {
34 public NnToXmlNotExistingLeafTypeTest() throws NoSuchFieldException,
39 @Test(expected = NullPointerException.class)
40 public void incorrectTopLevelElementTest() throws Exception {
41 final NormalizedNodeXmlBodyWriter xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
42 final OutputStream output = new ByteArrayOutputStream();
44 final NormalizedNodeContext normalizedNodeContext = prepareNNC(prepareDataSchemaNode());
45 xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null,
46 mediaType, null, output);
50 private NormalizedNodeContext prepareNNC(final DataSchemaNode dataSchemaNode) {
51 final QName cont = QName.create("simple:uri", "2012-12-17", "cont");
52 final QName lf = QName.create("simple:uri", "2012-12-17", "lf1");
54 final DataSchemaNode contSchema = ((ContainerSchemaNode) dataSchemaNode)
55 .getDataChildByName(cont);
56 final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataCont = Builders
57 .containerBuilder((ContainerSchemaNode) contSchema);
59 final DataSchemaNode lfSchema = ((ContainerSchemaNode) dataSchemaNode)
60 .getDataChildByName(lf);
62 dataCont.withChild(Builders.leafBuilder((LeafSchemaNode) lfSchema)
63 .withValue("any value").build());
65 final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
66 new InstanceIdentifierContext<DataSchemaNode>(null, contSchema,
67 null, (SchemaContext) dataSchemaNode), dataCont.build());
69 return testNormalizedNodeContext;
72 private DataSchemaNode prepareDataSchemaNode() {
73 final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder(
74 "module", 1, TestUtils.buildQName("cont", "simple:uri",
76 final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module",
77 2, TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"),
79 leafBuild.setType(new DummyType());
80 leafBuild.setConfiguration(true);
82 contBuild.addChildNode(leafBuild);
83 return contBuild.build();
87 protected MediaType getMediaType() {