Delete netconf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / nn / to / xml / test / NnToXmlNotExistingLeafTypeTest.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.nn.to.xml.test;
9
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.controller.sal.rest.impl.NormalizedNodeXmlBodyWriter;
15 import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
16 import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
17 import org.opendaylight.controller.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;
31
32 public class NnToXmlNotExistingLeafTypeTest extends AbstractBodyReaderTest {
33
34     public NnToXmlNotExistingLeafTypeTest() throws NoSuchFieldException,
35             SecurityException {
36         super();
37     }
38
39     @Test(expected = NullPointerException.class)
40     public void incorrectTopLevelElementTest() throws Exception {
41         final NormalizedNodeXmlBodyWriter xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
42         final OutputStream output = new ByteArrayOutputStream();
43
44         final NormalizedNodeContext normalizedNodeContext = prepareNNC(prepareDataSchemaNode());
45         xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null,
46                     mediaType, null, output);
47
48     }
49
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");
53
54         final DataSchemaNode contSchema = ((ContainerSchemaNode) dataSchemaNode)
55                 .getDataChildByName(cont);
56         final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataCont = Builders
57                 .containerBuilder((ContainerSchemaNode) contSchema);
58
59         final DataSchemaNode lfSchema = ((ContainerSchemaNode) dataSchemaNode)
60                 .getDataChildByName(lf);
61
62         dataCont.withChild(Builders.leafBuilder((LeafSchemaNode) lfSchema)
63                 .withValue("any value").build());
64
65         final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(
66                 new InstanceIdentifierContext<DataSchemaNode>(null, contSchema,
67                         null, (SchemaContext) dataSchemaNode), dataCont.build());
68
69         return testNormalizedNodeContext;
70     }
71
72     private DataSchemaNode prepareDataSchemaNode() {
73         final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder(
74                 "module", 1, TestUtils.buildQName("cont", "simple:uri",
75                         "2012-12-17"), null);
76         final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module",
77                 2, TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"),
78                 null);
79         leafBuild.setType(new DummyType());
80         leafBuild.setConfiguration(true);
81
82         contBuild.addChildNode(leafBuild);
83         return contBuild.build();
84     }
85
86     @Override
87     protected MediaType getMediaType() {
88         return null;
89     }
90
91 }