Merge "Added uses to extends list. Groupings in YANG are used through key word uses...
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / test / java / org / opendaylight / controller / sal / binding / generator / impl / GeneratedTypesTest.java
1 /*
2  * Copyright (c) 2013 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.binding.generator.impl;
9
10 import static org.junit.Assert.*;
11 import static org.junit.Assert.assertEquals;
12
13 import java.io.File;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.Set;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
21 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
24 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
25 import org.opendaylight.controller.sal.binding.model.api.Type;
26 import org.opendaylight.controller.yang.model.api.Module;
27 import org.opendaylight.controller.yang.model.api.SchemaContext;
28 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
29 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
30
31 public class GeneratedTypesTest {
32
33     private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
34         final YangModelParser parser = new YangParserImpl();
35
36         final List<File> inputFiles = new ArrayList<File>();
37         for (int i = 0; i < yangFiles.length; ++i) {
38             inputFiles.add(new File(yangFiles[i]));
39         }
40
41         final Set<Module> modules = parser.parseYangModels(inputFiles);
42         return parser.resolveSchemaContext(modules);
43     }
44
45     @Test
46     public void testMultipleModulesResolving() {
47         final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath();
48         final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath();
49         final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath);
50         assertNotNull(context);
51
52         final BindingGenerator bindingGen = new BindingGeneratorImpl();
53         final List<Type> genTypes = bindingGen.generateTypes(context);
54
55         assertNotNull(genTypes);
56         assertEquals(29, genTypes.size());
57     }
58
59     @Test
60     public void testLeafrefResolving() {
61         final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
62                 .getPath();
63         final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
64                 .getPath();
65         // final String ifTypePath = getClass().getResource(
66         // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
67         final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang")
68                 .getPath();
69         final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
70                 .getPath();
71
72         assertNotNull(topologyPath);
73         assertNotNull(interfacesPath);
74         // assertTrue(ifTypePath != null);
75         assertNotNull(inetTypesPath);
76         assertNotNull(yangTypesPath);
77
78         // final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, ifTypePath,
79         // inetTypesPath, yangTypesPath);
80         final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
81                 yangTypesPath);
82         assertNotNull(context);
83         assertEquals(4, context.getModules().size());
84
85         final BindingGenerator bindingGen = new BindingGeneratorImpl();
86         final List<Type> genTypes = bindingGen.generateTypes(context);
87
88         assertEquals(57, genTypes.size());
89         assertNotNull(genTypes);
90
91         GeneratedTransferObject gtIfcKey = null;
92         GeneratedType gtIfc = null;
93         GeneratedType gtNetworkLink = null;
94         GeneratedType gtSource = null;
95         GeneratedType gtDest = null;
96         GeneratedType gtTunnel = null;
97         GeneratedTransferObject gtTunnelKey = null;
98         GeneratedType gtTopology = null;
99         for (final Type type : genTypes) {
100             String name = type.getName();
101             if ("InterfaceKey".equals(name)) {
102                 gtIfcKey = (GeneratedTransferObject) type;
103             } else if ("Interface".equals(name)) {
104                 gtIfc = (GeneratedType) type;
105             } else if ("NetworkLink".equals(name)) {
106                 gtNetworkLink = (GeneratedType) type;
107             } else if ("SourceNode".equals(name)) {
108                 gtSource = (GeneratedType) type;
109             } else if ("DestinationNode".equals(name)) {
110                 gtDest = (GeneratedType) type;
111             } else if ("Tunnel".equals(name)) {
112                 gtTunnel = (GeneratedType) type;
113             } else if ("TunnelKey".equals(name)) {
114                 gtTunnelKey = (GeneratedTransferObject) type;
115             } else if ("Topology".equals(name)) {
116                 gtTopology = (GeneratedType) type;
117             }
118         }
119
120         assertNotNull(gtIfcKey);
121         assertNotNull(gtIfc);
122         assertNotNull(gtNetworkLink);
123         assertNotNull(gtSource);
124         assertNotNull(gtDest);
125         assertNotNull(gtTunnel);
126         assertNotNull(gtTunnelKey);
127         assertNotNull(gtTopology);
128
129         // Topology
130         final List<MethodSignature> gtTopoMethods = gtTopology.getMethodDefinitions();
131         assertNotNull(gtTopoMethods);
132         MethodSignature condLeafref = null;
133         for (final MethodSignature method : gtTopoMethods) {
134             if (method.getName().equals("getCondLeafref")) {
135                 condLeafref = method;
136             }
137         }
138         assertNotNull(condLeafref);
139         Type condLeafRT = condLeafref.getReturnType();
140         assertNotNull(condLeafRT);
141         assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName());
142
143         // InterfaceId
144         final List<GeneratedProperty> gtIfcKeyProps = gtIfcKey.getProperties();
145         assertNotNull(gtIfcKeyProps);
146         GeneratedProperty ifcIdProp = null;
147         for (final GeneratedProperty property : gtIfcKeyProps) {
148             if (property.getName().equals("InterfaceId")) {
149                 ifcIdProp = property;
150             }
151         }
152         assertNotNull(ifcIdProp);
153         Type ifcIdPropType = ifcIdProp.getReturnType();
154         assertNotNull(ifcIdPropType);
155         assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName());
156
157         // Interface
158         final List<MethodSignature> gtIfcMethods = gtIfc.getMethodDefinitions();
159         assertNotNull(gtIfcMethods);
160         MethodSignature getIfcKey = null;
161         MethodSignature getHigherLayerIf = null;
162         for (final MethodSignature method : gtIfcMethods) {
163             if (method.getName().equals("getInterfaceKey")) {
164                 getIfcKey = method;
165             } else if (method.getName().equals("getHigherLayerIf")) {
166                 getHigherLayerIf = method;
167             }
168         }
169         assertNotNull(getIfcKey);
170         Type getIfcKeyType = getIfcKey.getReturnType();
171         assertNotNull(getIfcKeyType);
172         assertNotSame("java.lang.Void", getIfcKeyType);
173         assertEquals("InterfaceKey", getIfcKeyType.getName());
174
175         assertNotNull(getHigherLayerIf);
176         Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
177         assertNotNull(getHigherLayerIfType);
178         assertNotSame("java.lang.Void", getHigherLayerIfType);
179         assertEquals("List", getHigherLayerIfType.getName());
180
181         // NetworkLink
182         final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions();
183         assertNotNull(gtNetworkLinkMethods);
184         MethodSignature getIfc = null;
185         for (MethodSignature method : gtNetworkLinkMethods) {
186             if (method.getName().equals("getInterface")) {
187                 getIfc = method;
188             }
189         }
190         assertNotNull(getIfc);
191         Type getIfcType = getIfc.getReturnType();
192         assertNotNull(getIfcType);
193         assertNotSame("java.lang.Void", getIfcType);
194         assertEquals("String", getIfcType.getName());
195
196         // SourceNode
197         final List<MethodSignature> gtSourceMethods = gtSource.getMethodDefinitions();
198         assertNotNull(gtSourceMethods);
199         MethodSignature getIdSource = null;
200         for (MethodSignature method : gtSourceMethods) {
201             if (method.getName().equals("getId")) {
202                 getIdSource = method;
203             }
204         }
205         assertNotNull(getIdSource);
206         Type getIdType = getIdSource.getReturnType();
207         assertNotNull(getIdType);
208         assertNotSame("java.lang.Void", getIdType);
209         assertEquals("Uri", getIdType.getName());
210
211         // DestinationNode
212         final List<MethodSignature> gtDestMethods = gtDest.getMethodDefinitions();
213         assertNotNull(gtDestMethods);
214         MethodSignature getIdDest = null;
215         for (MethodSignature method : gtDestMethods) {
216             if (method.getName().equals("getId")) {
217                 getIdDest = method;
218             }
219         }
220         assertNotNull(getIdDest);
221         Type getIdDestType = getIdDest.getReturnType();
222         assertNotNull(getIdDestType);
223         assertNotSame("java.lang.Void", getIdDestType);
224         assertEquals("Uri", getIdDestType.getName());
225
226         // Tunnel
227         final List<MethodSignature> gtTunnelMethods = gtTunnel.getMethodDefinitions();
228         assertNotNull(gtTunnelMethods);
229         MethodSignature getTunnelKey = null;
230         for (MethodSignature method : gtTunnelMethods) {
231             if (method.getName().equals("getTunnelKey")) {
232                 getTunnelKey = method;
233             }
234         }
235         assertNotNull(getTunnelKey);
236         Type getTunnelKeyType = getTunnelKey.getReturnType();
237         assertNotNull(getTunnelKeyType);
238         assertNotSame("java.lang.Void", getTunnelKeyType);
239         assertEquals("TunnelKey", getTunnelKeyType.getName());
240
241         // TunnelKey
242         final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey.getProperties();
243         assertNotNull(gtTunnelKeyProps);
244         GeneratedProperty tunnelId = null;
245         for (final GeneratedProperty property : gtTunnelKeyProps) {
246             if (property.getName().equals("TunnelId")) {
247                 tunnelId = property;
248             }
249         }
250         assertNotNull(tunnelId);
251         Type tunnelIdType = tunnelId.getReturnType();
252         assertNotNull(tunnelIdType);
253         assertNotSame("java.lang.Void", tunnelIdType);
254         assertEquals("Uri", tunnelIdType.getName());
255     }
256
257     @Test
258     public void testContainerResolving() {
259         final String filePath = getClass().getResource("/simple-container-demo.yang").getPath();
260         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
261         assert (context != null);
262
263         final BindingGenerator bindingGen = new BindingGeneratorImpl();
264         final List<Type> genTypes = bindingGen.generateTypes(context);
265
266         assertNotNull(genTypes);
267         assertEquals(4, genTypes.size());
268
269         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
270         final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
271
272         assertEquals("SimpleContainer", simpleContainer.getName());
273         assertEquals("NestedContainer", nestedContainer.getName());
274         assertEquals(3, simpleContainer.getMethodDefinitions().size());
275         assertEquals(2, nestedContainer.getMethodDefinitions().size());
276
277         int getFooMethodCounter = 0;
278         int getBarMethodCounter = 0;
279         int getNestedContainerCounter = 0;
280
281         String getFooMethodReturnTypeName = "";
282         String getBarMethodReturnTypeName = "";
283         String getNestedContainerReturnTypeName = "";
284         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
285             if (method.getName().equals("getFoo")) {
286                 getFooMethodCounter++;
287                 getFooMethodReturnTypeName = method.getReturnType().getName();
288             }
289
290             if (method.getName().equals("getBar")) {
291                 getBarMethodCounter++;
292                 getBarMethodReturnTypeName = method.getReturnType().getName();
293             }
294
295             if (method.getName().equals("getNestedContainer")) {
296                 getNestedContainerCounter++;
297                 getNestedContainerReturnTypeName = method.getReturnType().getName();
298             }
299         }
300
301         assertEquals(1, getFooMethodCounter);
302         assertEquals("Integer", getFooMethodReturnTypeName);
303
304         assertEquals(1, getBarMethodCounter);
305         assertEquals("String", getBarMethodReturnTypeName);
306
307         assertEquals(1, getNestedContainerCounter);
308         assertEquals("NestedContainer", getNestedContainerReturnTypeName);
309
310         getFooMethodCounter = 0;
311         getBarMethodCounter = 0;
312
313         getFooMethodReturnTypeName = "";
314         getBarMethodReturnTypeName = "";
315
316         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
317
318             if (method.getName().equals("getFoo")) {
319                 getFooMethodCounter++;
320                 getFooMethodReturnTypeName = method.getReturnType().getName();
321             }
322
323             if (method.getName().equals("getBar")) {
324                 getBarMethodCounter++;
325                 getBarMethodReturnTypeName = method.getReturnType().getName();
326             }
327         }
328
329         assertEquals(1, getFooMethodCounter);
330         assertEquals("Short", getFooMethodReturnTypeName);
331
332         assertEquals(1, getBarMethodCounter);
333         assertEquals("String", getBarMethodReturnTypeName);
334     }
335
336     @Test
337     public void testLeafListResolving() {
338         final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
339         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
340         assertNotNull(context);
341
342         final BindingGenerator bindingGen = new BindingGeneratorImpl();
343         final List<Type> genTypes = bindingGen.generateTypes(context);
344
345         assertNotNull(genTypes);
346         assertEquals(4, genTypes.size());
347
348         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
349         final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
350
351         assertEquals("SimpleContainer", simpleContainer.getName());
352         assertEquals("NestedContainer", nestedContainer.getName());
353         assertEquals(3, simpleContainer.getMethodDefinitions().size());
354         assertEquals(2, nestedContainer.getMethodDefinitions().size());
355
356         int getFooMethodCounter = 0;
357         int getBarMethodCounter = 0;
358         int getNestedContainerCounter = 0;
359
360         String getFooMethodReturnTypeName = "";
361         String getBarMethodReturnTypeName = "";
362         String getNestedContainerReturnTypeName = "";
363         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
364             if (method.getName().equals("getFoo")) {
365                 getFooMethodCounter++;
366                 getFooMethodReturnTypeName = method.getReturnType().getName();
367             }
368
369             if (method.getName().equals("getBar")) {
370                 getBarMethodCounter++;
371                 getBarMethodReturnTypeName = method.getReturnType().getName();
372             }
373
374             if (method.getName().equals("getNestedContainer")) {
375                 getNestedContainerCounter++;
376                 getNestedContainerReturnTypeName = method.getReturnType().getName();
377             }
378         }
379
380         assertEquals(1, getFooMethodCounter);
381         assertEquals("List", getFooMethodReturnTypeName);
382
383         assertEquals(1, getBarMethodCounter);
384         assertEquals("String", getBarMethodReturnTypeName);
385
386         assertEquals(1, getNestedContainerCounter);
387         assertEquals("NestedContainer", getNestedContainerReturnTypeName);
388
389         getFooMethodCounter = 0;
390         getBarMethodCounter = 0;
391
392         getFooMethodReturnTypeName = "";
393         getBarMethodReturnTypeName = "";
394
395         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
396             if (method.getName().equals("getFoo")) {
397                 getFooMethodCounter++;
398                 getFooMethodReturnTypeName = method.getReturnType().getName();
399             }
400
401             if (method.getName().equals("getBar")) {
402                 getBarMethodCounter++;
403                 getBarMethodReturnTypeName = method.getReturnType().getName();
404             }
405         }
406
407         assertEquals(1, getFooMethodCounter);
408         assertEquals("Short", getFooMethodReturnTypeName);
409
410         assertEquals(1, getBarMethodCounter);
411         assertEquals("List", getBarMethodReturnTypeName);
412     }
413
414     @Test
415     public void testListResolving() {
416         final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
417         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
418         assertNotNull(context);
419
420         final BindingGenerator bindingGen = new BindingGeneratorImpl();
421         final List<Type> genTypes = bindingGen.generateTypes(context);
422
423         assertNotNull(genTypes);
424         assertEquals(6, genTypes.size());
425
426         int listParentContainerMethodsCount = 0;
427         int simpleListMethodsCount = 0;
428         int listChildContainerMethodsCount = 0;
429         int listKeyClassCount = 0;
430
431         int getSimpleListKeyMethodCount = 0;
432         int getListChildContainerMethodCount = 0;
433         int getFooMethodCount = 0;
434         int setFooMethodCount = 0;
435         int getSimpleLeafListMethodCount = 0;
436         int setSimpleLeafListMethodCount = 0;
437         int getBarMethodCount = 0;
438
439         String getSimpleListKeyMethodReturnTypeName = "";
440         String getListChildContainerMethodReturnTypeName = "";
441
442         int listKeyClassPropertyCount = 0;
443         String listKeyClassPropertyName = "";
444         String listKeyClassPropertyTypeName = "";
445         boolean listKeyClassPropertyReadOnly = false;
446
447         int hashMethodParameterCount = 0;
448         String hashMethodParameterName = "";
449         String hashMethodParameterReturnTypeName = "";
450
451         int equalMethodParameterCount = 0;
452         String equalMethodParameterName = "";
453         String equalMethodParameterReturnTypeName = "";
454
455         for (final Type type : genTypes) {
456             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
457                 final GeneratedType genType = (GeneratedType) type;
458                 if (genType.getName().equals("ListParentContainer")) {
459                     listParentContainerMethodsCount = genType.getMethodDefinitions().size();
460                 } else if (genType.getName().equals("SimpleList")) {
461                     simpleListMethodsCount = genType.getMethodDefinitions().size();
462                     final List<MethodSignature> methods = genType.getMethodDefinitions();
463                     for (final MethodSignature method : methods) {
464                         if (method.getName().equals("getSimpleListKey")) {
465                             getSimpleListKeyMethodCount++;
466                             getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
467                         } else if (method.getName().equals("getListChildContainer")) {
468                             getListChildContainerMethodCount++;
469                             getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
470                         } else if (method.getName().equals("getFoo")) {
471                             getFooMethodCount++;
472                         } else if (method.getName().equals("setFoo")) {
473                             setFooMethodCount++;
474                         } else if (method.getName().equals("getSimpleLeafList")) {
475                             getSimpleLeafListMethodCount++;
476                         } else if (method.getName().equals("setSimpleLeafList")) {
477                             setSimpleLeafListMethodCount++;
478                         } else if (method.getName().equals("getBar")) {
479                             getBarMethodCount++;
480                         }
481                     }
482                 } else if (genType.getName().equals("ListChildContainer")) {
483                     listChildContainerMethodsCount = genType.getMethodDefinitions().size();
484                 }
485             } else if (type instanceof GeneratedTransferObject) {
486                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
487                 final List<GeneratedProperty> properties = genTO.getProperties();
488                 final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
489                 final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
490
491                 listKeyClassCount++;
492                 listKeyClassPropertyCount = properties.size();
493                 listKeyClassPropertyName = properties.get(0).getName();
494                 listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
495                 listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
496
497                 hashMethodParameterCount = hashProps.size();
498                 hashMethodParameterName = hashProps.get(0).getName();
499                 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
500
501                 equalMethodParameterCount = equalProps.size();
502                 equalMethodParameterName = equalProps.get(0).getName();
503                 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
504
505             }
506         }
507
508         assertEquals(1, listParentContainerMethodsCount);
509         assertEquals(1, listChildContainerMethodsCount);
510         assertEquals(1, getSimpleListKeyMethodCount);
511         assertEquals(1, listKeyClassCount);
512
513         assertEquals(1, listKeyClassPropertyCount);
514         assertEquals("ListKey", listKeyClassPropertyName);
515         assertEquals("Byte", listKeyClassPropertyTypeName);
516         assertEquals(true, listKeyClassPropertyReadOnly);
517         assertEquals(1, hashMethodParameterCount);
518         assertEquals("ListKey", hashMethodParameterName);
519         assertEquals("Byte", hashMethodParameterReturnTypeName);
520         assertEquals(1, equalMethodParameterCount);
521         assertEquals("ListKey", equalMethodParameterName);
522         assertEquals("Byte", equalMethodParameterReturnTypeName);
523
524         assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
525
526         assertEquals(1, getListChildContainerMethodCount);
527         assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
528         assertEquals(1, getFooMethodCount);
529         assertEquals(0, setFooMethodCount);
530         assertEquals(1, getSimpleLeafListMethodCount);
531         assertEquals(0, setSimpleLeafListMethodCount);
532         assertEquals(1, getBarMethodCount);
533
534         assertEquals(5, simpleListMethodsCount);
535     }
536
537     @Test
538     public void testListCompositeKeyResolving() {
539         final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
540         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
541
542         assertNotNull(context);
543
544         final BindingGenerator bindingGen = new BindingGeneratorImpl();
545         final List<Type> genTypes = bindingGen.generateTypes(context);
546
547         assertNotNull(genTypes);
548         assertEquals(8, genTypes.size());
549
550         int genTypesCount = 0;
551         int genTOsCount = 0;
552
553         int compositeKeyListKeyPropertyCount = 0;
554         int compositeKeyListKeyCount = 0;
555         int innerListKeyPropertyCount = 0;
556
557         for (final Type type : genTypes) {
558             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
559                 genTypesCount++;
560             } else if (type instanceof GeneratedTransferObject) {
561                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
562
563                 if (genTO.getName().equals("CompositeKeyListKey")) {
564                     compositeKeyListKeyCount++;
565                     final List<GeneratedProperty> properties = genTO.getProperties();
566                     for (final GeneratedProperty prop : properties) {
567                         if (prop.getName().equals("Key1")) {
568                             compositeKeyListKeyPropertyCount++;
569                         } else if (prop.getName().equals("Key2")) {
570                             compositeKeyListKeyPropertyCount++;
571                         }
572                     }
573                     genTOsCount++;
574                 } else if (genTO.getName().equals("InnerListKey")) {
575                     final List<GeneratedProperty> properties = genTO.getProperties();
576                     innerListKeyPropertyCount = properties.size();
577                     genTOsCount++;
578                 }
579             }
580         }
581         assertEquals(1, compositeKeyListKeyCount);
582         assertEquals(2, compositeKeyListKeyPropertyCount);
583
584         assertEquals(1, innerListKeyPropertyCount);
585
586         assertEquals(6, genTypesCount);
587         assertEquals(2, genTOsCount);
588     }
589
590     @Test
591     public void testGeneratedTypes() {
592         final String filePath = getClass().getResource("/demo-topology.yang").getPath();
593         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
594         assertNotNull(context);
595
596         final BindingGenerator bindingGen = new BindingGeneratorImpl();
597         final List<Type> genTypes = bindingGen.generateTypes(context);
598
599         assertNotNull(genTypes);
600         assertEquals(15, genTypes.size());
601
602         int genTypesCount = 0;
603         int genTOsCount = 0;
604         for (final Type type : genTypes) {
605             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
606                 genTypesCount++;
607             } else if (type instanceof GeneratedTransferObject) {
608                 genTOsCount++;
609             }
610         }
611
612         assertEquals(12, genTypesCount);
613         assertEquals(3, genTOsCount);
614     }
615 }