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