1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.IOException;
9 import javax.activation.UnsupportedDataTypeException;
10 import javax.ws.rs.WebApplicationException;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
16 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
19 import org.opendaylight.yangtools.yang.model.api.*;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class CnSnToJsonIncorrectTopLevelTest extends YangAndXmlAndDataSchemaLoader {
25 private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonIncorrectTopLevelTest.class);
28 public static void initialize() {
29 dataLoad("/cnsn-to-json/simple-data-types");
32 private class IncorrectDataSchema implements DataSchemaNode, DataNodeContainer {
35 public String getDescription() {
36 // TODO Auto-generated method stub
41 public SchemaPath getPath() {
42 // TODO Auto-generated method stub
47 public QName getQName() {
48 // TODO Auto-generated method stub
53 public String getReference() {
54 // TODO Auto-generated method stub
59 public Status getStatus() {
60 // TODO Auto-generated method stub
65 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
66 // TODO Auto-generated method stub
71 public Set<DataSchemaNode> getChildNodes() {
72 // TODO Auto-generated method stub
77 public DataSchemaNode getDataChildByName(QName arg0) {
78 // TODO Auto-generated method stub
83 public DataSchemaNode getDataChildByName(String arg0) {
84 // TODO Auto-generated method stub
89 public Set<GroupingDefinition> getGroupings() {
90 // TODO Auto-generated method stub
95 public Set<TypeDefinition<?>> getTypeDefinitions() {
96 // TODO Auto-generated method stub
101 public Set<UsesNode> getUses() {
102 // TODO Auto-generated method stub
107 public ConstraintDefinition getConstraints() {
108 // TODO Auto-generated method stub
113 public YangNode getParent() {
114 // TODO Auto-generated method stub
119 public boolean isAddedByUses() {
120 // TODO Auto-generated method stub
125 public boolean isAugmenting() {
126 // TODO Auto-generated method stub
131 public boolean isConfiguration() {
132 // TODO Auto-generated method stub
139 public void incorrectTopLevelElementTest() {
141 CompositeNode compositeNode = TestUtils.loadCompositeNode("/cnsn-to-json/simple-data-types/xml/data.xml");
142 DataSchemaNode incorrectDataSchema = null;
143 incorrectDataSchema = new IncorrectDataSchema();
145 TestUtils.normalizeCompositeNode(compositeNode, modules, "simple-data-types:cont");
147 boolean exceptionRaised = false;
149 TestUtils.writeCompNodeWithSchemaContextToOutput(compositeNode, modules, incorrectDataSchema,
150 StructuredDataToJsonProvider.INSTANCE);
151 } catch (UnsupportedDataTypeException e) {
152 exceptionRaised = true;
153 } catch (WebApplicationException | IOException e) {
154 LOG.error("WebApplicationException or IOException was raised");
157 assertTrue(exceptionRaised);