1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.*;
5 import java.io.FileNotFoundException;
6 import java.io.InputStream;
9 import org.junit.BeforeClass;
10 import org.junit.Test;
11 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
12 import org.opendaylight.controller.sal.restconf.impl.JsonMapper;
13 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
14 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 public class JsonMapperTest {
20 private static final ControllerContext controllerContext = new ControllerContext();
23 public static void init() throws FileNotFoundException {
24 Set<Module> allModules = TestUtils.loadModules(JsonMapperTest.class.getResource("/full-versions/yangs").getPath());
25 SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
26 controllerContext.setSchemas(schemaContext);
30 public void test() throws FileNotFoundException {
31 InputStream xmlStream = JsonMapperTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");
32 CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode(xmlStream);
33 DataSchemaNode loadedSchemaNode = controllerContext.toInstanceIdentifier("ietf-interfaces:interfaces/interface/eth0").getSchemaNode();
34 JsonMapper jsonMapper = new JsonMapper();
35 String json = jsonMapper.convert(loadedSchemaNode, loadedCompositeNode);