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