Added test cases for each .proto file to ensure
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / json / to / cnsn / test / JsonIdentityrefToCnSnTest.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.json.to.cnsn.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.List;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
18 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
19 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.Node;
23 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
24
25 public class JsonIdentityrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
26
27     @BeforeClass
28     public static void initialize() {
29         dataLoad("/json-to-cnsn/identityref", 2, "identityref-module", "cont");
30     }
31
32     @Test
33     public void jsonIdentityrefToCompositeNode() {
34         CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/identityref/json/data.json", false,
35                 JsonToCompositeNodeProvider.INSTANCE);
36         assertNotNull(compositeNode);
37
38         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
39
40         assertEquals("cont", compositeNode.getNodeType().getLocalName());
41
42         List<Node<?>> childs = compositeNode.getValue();
43         assertEquals(1, childs.size());
44         Node<?> nd = childs.iterator().next();
45         assertTrue(nd instanceof CompositeNode);
46         assertEquals("cont1", nd.getNodeType().getLocalName());
47
48         childs = ((CompositeNode) nd).getValue();
49         assertEquals(4, childs.size());
50         SimpleNode<?> lf11 = null;
51         SimpleNode<?> lf12 = null;
52         SimpleNode<?> lf13 = null;
53         SimpleNode<?> lf14 = null;
54         for (Node<?> child : childs) {
55             assertTrue(child instanceof SimpleNode);
56             if (child.getNodeType().getLocalName().equals("lf11")) {
57                 lf11 = (SimpleNode<?>) child;
58             } else if (child.getNodeType().getLocalName().equals("lf12")) {
59                 lf12 = (SimpleNode<?>) child;
60             } else if (child.getNodeType().getLocalName().equals("lf13")) {
61                 lf13 = (SimpleNode<?>) child;
62             } else if (child.getNodeType().getLocalName().equals("lf14")) {
63                 lf14 = (SimpleNode<?>) child;
64             }
65         }
66
67         assertTrue(lf11.getValue() instanceof QName);
68         assertEquals("iden", ((QName) lf11.getValue()).getLocalName());
69         assertEquals("identity:module", ((QName) lf11.getValue()).getNamespace().toString());
70
71         assertTrue(lf12.getValue() instanceof QName);
72         assertEquals("iden_local", ((QName) lf12.getValue()).getLocalName());
73         assertEquals("identityref:module", ((QName) lf12.getValue()).getNamespace().toString());
74
75         assertTrue(lf13.getValue() instanceof QName);
76         assertEquals("iden_local", ((QName) lf13.getValue()).getLocalName());
77         assertEquals("identityref:module", ((QName) lf13.getValue()).getNamespace().toString());
78
79         assertTrue(lf14.getValue() instanceof QName);
80         assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
81         assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());
82     }
83
84 }