Adjust to yangtools-2.0.0 changes
[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(false)
33                 .generateTypes(context);
34
35         assertFalse(generateTypes.isEmpty());
36     }
37
38     @Test
39     public void choiceNodeGenerationTest() {
40         SchemaContext context = YangParserTestUtils.parseYangResource("/binding-generator-impl-test/choice-test.yang");
41
42         List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
43
44         GeneratedType choiceTestData = null;
45         GeneratedType myRootContainer = null;
46         GeneratedType myList = null;
47         GeneratedType myContainer = null;
48         GeneratedType myList2 = null;
49         GeneratedType myContainer2 = null;
50
51         for (Type type : generateTypes) {
52             switch (type.getName()) {
53             case "ChoiceTestData":
54                 choiceTestData = (GeneratedType) type;
55                 break;
56             case "Myrootcontainer":
57                 myRootContainer = (GeneratedType) type;
58                 break;
59             case "Mylist":
60                 myList = (GeneratedType) type;
61                 break;
62             case "Mylist2":
63                 myList2 = (GeneratedType) type;
64                 break;
65             case "Mycontainer":
66                 myContainer = (GeneratedType) type;
67                 break;
68             case "Mycontainer2":
69                 myContainer2 = (GeneratedType) type;
70                 break;
71             }
72         }
73
74         assertNotNull(choiceTestData);
75         assertNotNull(myRootContainer);
76         assertNotNull(myList);
77         assertNotNull(myContainer);
78         assertNotNull(myList2);
79         assertNotNull(myContainer2);
80
81         List<Type> implements1 = myContainer.getImplements();
82         Type childOfParamType = null;
83         for (Type type : implements1) {
84             if (type.getName().equals("ChildOf")) {
85                 childOfParamType = ((ParameterizedType) type)
86                         .getActualTypeArguments()[0];
87                 break;
88             }
89         }
90         assertNotNull(childOfParamType);
91         assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
92
93         implements1 = myList.getImplements();
94         childOfParamType = null;
95         for (Type type : implements1) {
96             if (type.getName().equals("ChildOf")) {
97                 childOfParamType = ((ParameterizedType) type)
98                         .getActualTypeArguments()[0];
99                 break;
100             }
101         }
102         assertNotNull(childOfParamType);
103         assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
104
105         implements1 = myContainer2.getImplements();
106         childOfParamType = null;
107         for (Type type : implements1) {
108             if (type.getName().equals("ChildOf")) {
109                 childOfParamType = ((ParameterizedType) type)
110                         .getActualTypeArguments()[0];
111                 break;
112             }
113         }
114         assertNotNull(childOfParamType);
115         assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
116
117         implements1 = myList2.getImplements();
118         childOfParamType = null;
119         for (Type type : implements1) {
120             if (type.getName().equals("ChildOf")) {
121                 childOfParamType = ((ParameterizedType) type)
122                         .getActualTypeArguments()[0];
123                 break;
124             }
125         }
126         assertNotNull(childOfParamType);
127         assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
128
129     }
130
131     @Test
132     public void notificationGenerationTest() {
133         SchemaContext context = YangParserTestUtils.parseYangResource(
134             "/binding-generator-impl-test/notification-test.yang");
135
136         List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
137
138         GeneratedType foo = null;
139         for (Type type : generateTypes) {
140             if (type.getName().equals("Foo")) {
141                 foo = (GeneratedType) type;
142                 break;
143             }
144         }
145
146         Type childOf = null;
147         Type dataObject = null;
148         List<Type> impl = foo.getImplements();
149         for (Type type : impl) {
150             switch (type.getName()) {
151             case "ChildOf":
152                 childOf = type;
153                 break;
154             case "DataObject":
155                 dataObject = type;
156                 break;
157             }
158         }
159
160         assertNull(childOf);
161         assertNotNull(dataObject);
162     }
163
164 }