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