Added following mapping:
[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(5, simpleContainer.getMethodDefinitions().size());
257         assertEquals(4, 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         assertEquals(setFooMethodCounter, 1);
297         assertEquals(setFooMethodInputParamName, "foo");
298         assertEquals(setFooMethodInputParamTypeName, "Integer");
299
300         assertEquals(getBarMethodCounter, 1);
301         assertEquals(getBarMethodReturnTypeName, "String");
302
303         assertEquals(getNestedContainerCounter, 1);
304         assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
305
306         setFooMethodCounter = 0;
307         getFooMethodCounter = 0;
308         getBarMethodCounter = 0;
309         int setBarMethodCounter = 0;
310
311         getFooMethodReturnTypeName = "";
312         setFooMethodInputParamName = "";
313         setFooMethodInputParamTypeName = "";
314         getBarMethodReturnTypeName = "";
315         String setBarMethodInputParamName = "";
316         String setBarMethodInputParamTypeName = "";
317
318         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
319
320             if (method.getName().equals("getFoo")) {
321                 getFooMethodCounter++;
322                 getFooMethodReturnTypeName = method.getReturnType().getName();
323             }
324
325             if (method.getName().equals("setFoo")) {
326                 setFooMethodCounter++;
327                 final MethodSignature.Parameter param = method.getParameters().get(0);
328                 setFooMethodInputParamName = param.getName();
329                 setFooMethodInputParamTypeName = param.getType().getName();
330             }
331
332             if (method.getName().equals("getBar")) {
333                 getBarMethodCounter++;
334                 getBarMethodReturnTypeName = method.getReturnType().getName();
335             }
336
337             if (method.getName().equals("setBar")) {
338                 setBarMethodCounter++;
339                 final MethodSignature.Parameter param = method.getParameters().get(0);
340                 setBarMethodInputParamName = param.getName();
341                 setBarMethodInputParamTypeName = param.getType().getName();
342             }
343         }
344
345         assertEquals(1, getFooMethodCounter);
346         assertEquals(getFooMethodReturnTypeName, "Short");
347
348         assertEquals(1, setFooMethodCounter);
349         assertEquals(setFooMethodInputParamName, "foo");
350         assertEquals(setFooMethodInputParamTypeName, "Short");
351
352         assertEquals(1, getBarMethodCounter);
353         assertEquals(getBarMethodReturnTypeName, "String");
354
355         assertEquals(1, setBarMethodCounter);
356         assertEquals(setBarMethodInputParamName, "bar");
357         assertEquals(setBarMethodInputParamTypeName, "String");
358     }
359
360     @Test
361     public void testLeafListResolving() {
362         final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
363         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
364         assertNotNull(context);
365
366         final BindingGenerator bindingGen = new BindingGeneratorImpl();
367         final List<Type> genTypes = bindingGen.generateTypes(context);
368
369         assertNotNull(genTypes);
370         assertEquals(4, genTypes.size());
371
372         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
373         final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
374
375         assertEquals("SimpleContainer", simpleContainer.getName());
376         assertEquals("NestedContainer", nestedContainer.getName());
377         assertEquals(5, simpleContainer.getMethodDefinitions().size());
378         assertEquals(3, nestedContainer.getMethodDefinitions().size());
379
380         int setFooMethodCounter = 0;
381         int getFooMethodCounter = 0;
382         int getBarMethodCounter = 0;
383         int getNestedContainerCounter = 0;
384
385         String getFooMethodReturnTypeName = "";
386         String setFooMethodInputParamName = "";
387         String setFooMethodInputParamTypeName = "";
388         String getBarMethodReturnTypeName = "";
389         String getNestedContainerReturnTypeName = "";
390         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
391             if (method.getName().equals("getFoo")) {
392                 getFooMethodCounter++;
393                 getFooMethodReturnTypeName = method.getReturnType().getName();
394             }
395
396             if (method.getName().equals("setFoo")) {
397                 setFooMethodCounter++;
398                 final MethodSignature.Parameter param = method.getParameters().get(0);
399                 setFooMethodInputParamName = param.getName();
400                 setFooMethodInputParamTypeName = param.getType().getName();
401             }
402
403             if (method.getName().equals("getBar")) {
404                 getBarMethodCounter++;
405                 getBarMethodReturnTypeName = method.getReturnType().getName();
406             }
407
408             if (method.getName().equals("getNestedContainer")) {
409                 getNestedContainerCounter++;
410                 getNestedContainerReturnTypeName = method.getReturnType().getName();
411             }
412         }
413
414         assertEquals(1, getFooMethodCounter);
415         assertEquals(getFooMethodReturnTypeName, "List");
416
417         assertEquals(1, setFooMethodCounter);
418         assertEquals(setFooMethodInputParamName, "foo");
419         assertEquals(setFooMethodInputParamTypeName, "List");
420
421         assertEquals(1, getBarMethodCounter);
422         assertEquals(getBarMethodReturnTypeName, "String");
423
424         assertEquals(1, getNestedContainerCounter);
425         assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
426
427         setFooMethodCounter = 0;
428         getFooMethodCounter = 0;
429         getBarMethodCounter = 0;
430
431         getFooMethodReturnTypeName = "";
432         setFooMethodInputParamName = "";
433         setFooMethodInputParamTypeName = "";
434         getBarMethodReturnTypeName = "";
435
436         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
437             if (method.getName().equals("getFoo")) {
438                 getFooMethodCounter++;
439                 getFooMethodReturnTypeName = method.getReturnType().getName();
440             }
441
442             if (method.getName().equals("setFoo")) {
443                 setFooMethodCounter++;
444                 final MethodSignature.Parameter param = method.getParameters().get(0);
445                 setFooMethodInputParamName = param.getName();
446                 setFooMethodInputParamTypeName = param.getType().getName();
447             }
448
449             if (method.getName().equals("getBar")) {
450                 getBarMethodCounter++;
451                 getBarMethodReturnTypeName = method.getReturnType().getName();
452             }
453         }
454
455         assertEquals(1, getFooMethodCounter);
456         assertEquals(getFooMethodReturnTypeName, "Short");
457
458         assertEquals(1, setFooMethodCounter);
459         assertEquals(setFooMethodInputParamName, "foo");
460         assertEquals(setFooMethodInputParamTypeName, "Short");
461
462         assertEquals(1, getBarMethodCounter);
463         assertEquals(getBarMethodReturnTypeName, "List");
464     }
465
466     @Test
467     public void testListResolving() {
468         final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
469         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
470         assertNotNull(context);
471
472         final BindingGenerator bindingGen = new BindingGeneratorImpl();
473         final List<Type> genTypes = bindingGen.generateTypes(context);
474
475         assertNotNull(genTypes);
476         assertEquals(6, genTypes.size());
477
478         int genTypesCount = 0;
479         int genTOsCount = 0;
480
481         int listParentContainerMethodsCount = 0;
482         int simpleListMethodsCount = 0;
483         int listChildContainerMethodsCount = 0;
484         int listKeyClassCount = 0;
485
486         int getSimpleListKeyMethodCount = 0;
487         int getListChildContainerMethodCount = 0;
488         int getFooMethodCount = 0;
489         int setFooMethodCount = 0;
490         int getSimpleLeafListMethodCount = 0;
491         int setSimpleLeafListMethodCount = 0;
492         int getBarMethodCount = 0;
493
494         String getSimpleListKeyMethodReturnTypeName = "";
495         String getListChildContainerMethodReturnTypeName = "";
496
497         int listKeyClassPropertyCount = 0;
498         String listKeyClassPropertyName = "";
499         String listKeyClassPropertyTypeName = "";
500         boolean listKeyClassPropertyReadOnly = false;
501
502         int hashMethodParameterCount = 0;
503         String hashMethodParameterName = "";
504         String hashMethodParameterReturnTypeName = "";
505
506         int equalMethodParameterCount = 0;
507         String equalMethodParameterName = "";
508         String equalMethodParameterReturnTypeName = "";
509
510         for (final Type type : genTypes) {
511             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
512                 final GeneratedType genType = (GeneratedType) type;
513                 if (genType.getName().equals("ListParentContainer")) {
514                     listParentContainerMethodsCount = genType.getMethodDefinitions().size();
515                     genTypesCount++;
516                 } else if (genType.getName().equals("SimpleList")) {
517                     simpleListMethodsCount = genType.getMethodDefinitions().size();
518                     final List<MethodSignature> methods = genType.getMethodDefinitions();
519                     for (final MethodSignature method : methods) {
520                         if (method.getName().equals("getSimpleListKey")) {
521                             getSimpleListKeyMethodCount++;
522                             getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
523                         } else if (method.getName().equals("getListChildContainer")) {
524                             getListChildContainerMethodCount++;
525                             getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
526                         } else if (method.getName().equals("getFoo")) {
527                             getFooMethodCount++;
528                         } else if (method.getName().equals("setFoo")) {
529                             setFooMethodCount++;
530                         } else if (method.getName().equals("getSimpleLeafList")) {
531                             getSimpleLeafListMethodCount++;
532                         } else if (method.getName().equals("setSimpleLeafList")) {
533                             setSimpleLeafListMethodCount++;
534                         } else if (method.getName().equals("getBar")) {
535                             getBarMethodCount++;
536                         }
537                     }
538                     genTypesCount++;
539                 } else if (genType.getName().equals("ListChildContainer")) {
540                     listChildContainerMethodsCount = genType.getMethodDefinitions().size();
541                     genTypesCount++;
542                 }
543             } else if (type instanceof GeneratedTransferObject) {
544                 genTOsCount++;
545                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
546                 final List<GeneratedProperty> properties = genTO.getProperties();
547                 final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
548                 final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
549
550                 listKeyClassCount++;
551                 listKeyClassPropertyCount = properties.size();
552                 listKeyClassPropertyName = properties.get(0).getName();
553                 listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
554                 listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
555
556                 hashMethodParameterCount = hashProps.size();
557                 hashMethodParameterName = hashProps.get(0).getName();
558                 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
559
560                 equalMethodParameterCount = equalProps.size();
561                 equalMethodParameterName = equalProps.get(0).getName();
562                 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
563
564             }
565         }
566
567         assertEquals(2, listParentContainerMethodsCount);
568         assertEquals(2, listChildContainerMethodsCount);
569         assertEquals(1, getSimpleListKeyMethodCount);
570         assertEquals(1, listKeyClassCount);
571
572         assertEquals(1, listKeyClassPropertyCount);
573         assertEquals("ListKey", listKeyClassPropertyName);
574         assertEquals("Byte", listKeyClassPropertyTypeName);
575         assertEquals(true, listKeyClassPropertyReadOnly);
576         assertEquals(1, hashMethodParameterCount);
577         assertEquals("ListKey", hashMethodParameterName);
578         assertEquals("Byte", hashMethodParameterReturnTypeName);
579         assertEquals(1, equalMethodParameterCount);
580         assertEquals("ListKey", equalMethodParameterName);
581         assertEquals("Byte", equalMethodParameterReturnTypeName);
582
583         assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
584
585         assertEquals(1, getListChildContainerMethodCount);
586         assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
587         assertEquals(1, getFooMethodCount);
588         assertEquals(1, setFooMethodCount);
589         assertEquals(1, getSimpleLeafListMethodCount);
590         assertEquals(1, setSimpleLeafListMethodCount);
591         assertEquals(1, getBarMethodCount);
592
593         assertEquals(8, simpleListMethodsCount);
594     }
595
596     @Test
597     public void testListCompositeKeyResolving() {
598         final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
599         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
600
601         assertNotNull(context);
602
603         final BindingGenerator bindingGen = new BindingGeneratorImpl();
604         final List<Type> genTypes = bindingGen.generateTypes(context);
605
606         assertNotNull(genTypes);
607         assertEquals(8, genTypes.size());
608
609         int genTypesCount = 0;
610         int genTOsCount = 0;
611
612         int compositeKeyListKeyPropertyCount = 0;
613         int compositeKeyListKeyCount = 0;
614         int innerListKeyPropertyCount = 0;
615
616         for (final Type type : genTypes) {
617             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
618                 genTypesCount++;
619             } else if (type instanceof GeneratedTransferObject) {
620                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
621
622                 if (genTO.getName().equals("CompositeKeyListKey")) {
623                     compositeKeyListKeyCount++;
624                     final List<GeneratedProperty> properties = genTO.getProperties();
625                     for (final GeneratedProperty prop : properties) {
626                         if (prop.getName().equals("Key1")) {
627                             compositeKeyListKeyPropertyCount++;
628                         } else if (prop.getName().equals("Key2")) {
629                             compositeKeyListKeyPropertyCount++;
630                         }
631                     }
632                     genTOsCount++;
633                 } else if (genTO.getName().equals("InnerListKey")) {
634                     final List<GeneratedProperty> properties = genTO.getProperties();
635                     innerListKeyPropertyCount = properties.size();
636                     genTOsCount++;
637                 }
638             }
639         }
640         assertEquals(1, compositeKeyListKeyCount);
641         assertEquals(2, compositeKeyListKeyPropertyCount);
642
643         assertEquals(1, innerListKeyPropertyCount);
644
645         assertEquals(6, genTypesCount);
646         assertEquals(2, genTOsCount);
647     }
648
649     @Test
650     public void testGeneratedTypes() {
651         final String filePath = getClass().getResource("/demo-topology.yang").getPath();
652         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
653         assertNotNull(context);
654
655         final BindingGenerator bindingGen = new BindingGeneratorImpl();
656         final List<Type> genTypes = bindingGen.generateTypes(context);
657
658         assertNotNull(genTypes);
659         assertEquals(15, genTypes.size());
660
661         int genTypesCount = 0;
662         int genTOsCount = 0;
663         for (final Type type : genTypes) {
664             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
665                 genTypesCount++;
666             } else if (type instanceof GeneratedTransferObject) {
667                 genTOsCount++;
668             }
669         }
670
671         assertEquals(12, genTypesCount);
672         assertEquals(3, genTOsCount);
673     }
674 }