20467e5b3183ef89a67ab9b30ae12b68a44533c9
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / BindingGeneratorImplTest.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.generator.impl;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
18 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
19 import org.opendaylight.mdsal.binding.model.api.Type;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22
23 public class BindingGeneratorImplTest {
24
25     @Test
26     public void isisTotpologyStatementParserTest()  {
27         SchemaContext context = YangParserTestUtils.parseYangResources(BindingGeneratorImplTest.class,
28             "/isis-topology/network-topology@2013-10-21.yang", "/isis-topology/isis-topology@2013-10-21.yang",
29             "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
30         assertNotNull(context);
31
32         List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
33         assertFalse(generateTypes.isEmpty());
34     }
35
36     @Test
37     public void choiceNodeGenerationTest() {
38         SchemaContext context = YangParserTestUtils.parseYangResource("/binding-generator-impl-test/choice-test.yang");
39
40         List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
41
42         GeneratedType choiceTestData = null;
43         GeneratedType myRootContainer = null;
44         GeneratedType myList = null;
45         GeneratedType myContainer = null;
46         GeneratedType myList2 = null;
47         GeneratedType myContainer2 = null;
48
49         for (Type type : generateTypes) {
50             switch (type.getName()) {
51             case "ChoiceTestData":
52                 choiceTestData = (GeneratedType) type;
53                 break;
54             case "Myrootcontainer":
55                 myRootContainer = (GeneratedType) type;
56                 break;
57             case "Mylist":
58                 myList = (GeneratedType) type;
59                 break;
60             case "Mylist2":
61                 myList2 = (GeneratedType) type;
62                 break;
63             case "Mycontainer":
64                 myContainer = (GeneratedType) type;
65                 break;
66             case "Mycontainer2":
67                 myContainer2 = (GeneratedType) type;
68                 break;
69             }
70         }
71
72         assertNotNull(choiceTestData);
73         assertNotNull(myRootContainer);
74         assertNotNull(myList);
75         assertNotNull(myContainer);
76         assertNotNull(myList2);
77         assertNotNull(myContainer2);
78
79         List<Type> implements1 = myContainer.getImplements();
80         Type childOfParamType = null;
81         for (Type type : implements1) {
82             if (type.getName().equals("ChildOf")) {
83                 childOfParamType = ((ParameterizedType) type)
84                         .getActualTypeArguments()[0];
85                 break;
86             }
87         }
88         assertNotNull(childOfParamType);
89         assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
90
91         implements1 = myList.getImplements();
92         childOfParamType = null;
93         for (Type type : implements1) {
94             if (type.getName().equals("ChildOf")) {
95                 childOfParamType = ((ParameterizedType) type)
96                         .getActualTypeArguments()[0];
97                 break;
98             }
99         }
100         assertNotNull(childOfParamType);
101         assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
102
103         implements1 = myContainer2.getImplements();
104         childOfParamType = null;
105         for (Type type : implements1) {
106             if (type.getName().equals("ChildOf")) {
107                 childOfParamType = ((ParameterizedType) type)
108                         .getActualTypeArguments()[0];
109                 break;
110             }
111         }
112         assertNotNull(childOfParamType);
113         assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
114
115         implements1 = myList2.getImplements();
116         childOfParamType = null;
117         for (Type type : implements1) {
118             if (type.getName().equals("ChildOf")) {
119                 childOfParamType = ((ParameterizedType) type)
120                         .getActualTypeArguments()[0];
121                 break;
122             }
123         }
124         assertNotNull(childOfParamType);
125         assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
126
127     }
128
129     @Test
130     public void notificationGenerationTest() {
131         SchemaContext context = YangParserTestUtils.parseYangResource(
132             "/binding-generator-impl-test/notification-test.yang");
133
134         List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
135
136         GeneratedType foo = null;
137         for (Type type : generateTypes) {
138             if (type.getName().equals("Foo")) {
139                 foo = (GeneratedType) type;
140                 break;
141             }
142         }
143
144         Type childOf = null;
145         Type dataObject = null;
146         List<Type> impl = foo.getImplements();
147         for (Type type : impl) {
148             switch (type.getName()) {
149             case "ChildOf":
150                 childOf = type;
151                 break;
152             case "DataObject":
153                 dataObject = type;
154                 break;
155             }
156         }
157
158         assertNull(childOf);
159         assertNotNull(dataObject);
160     }
161
162 }