Solved bugs and added tests in sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / JsonMapperTest.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.*;
4
5 import java.io.FileNotFoundException;
6 import java.io.InputStream;
7 import java.util.Set;
8
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;
17
18 public class JsonMapperTest {
19
20     private static final ControllerContext controllerContext = new ControllerContext();
21
22     @BeforeClass
23     public static void init() throws FileNotFoundException {
24         Set<Module> allModules = TestUtils.loadModules(JsonMapperTest.class.getResource("/full-versions/yangs").getPath());
25         assertEquals(4, allModules.size());
26         SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
27         controllerContext.setSchemas(schemaContext);
28     }
29
30     @Test
31     public void test() throws FileNotFoundException {
32         InputStream xmlStream = JsonMapperTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");
33         CompositeNode loadedCompositeNode = TestUtils.loadCompositeNode(xmlStream);
34         DataSchemaNode loadedSchemaNode = controllerContext.toInstanceIdentifier("ietf-interfaces:interfaces/interface/eth0").getSchemaNode();
35         JsonMapper jsonMapper = new JsonMapper();
36         String json = jsonMapper.convert(loadedSchemaNode, loadedCompositeNode);
37     }
38
39 }