Added model generation from ietf-topology models
[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(26, 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(51, 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("getInterfaceKey")) {\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("getTunnelKey")) {\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         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);\r
268         final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);\r
269 \r
270         assertEquals("SimpleContainer", simpleContainer.getName());\r
271         assertEquals("NestedContainer", nestedContainer.getName());\r
272         assertEquals(3, simpleContainer.getMethodDefinitions().size());\r
273         assertEquals(2, nestedContainer.getMethodDefinitions().size());\r
274 \r
275         int getFooMethodCounter = 0;\r
276         int getBarMethodCounter = 0;\r
277         int getNestedContainerCounter = 0;\r
278 \r
279         String getFooMethodReturnTypeName = "";\r
280         String getBarMethodReturnTypeName = "";\r
281         String getNestedContainerReturnTypeName = "";\r
282         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {\r
283             if (method.getName().equals("getFoo")) {\r
284                 getFooMethodCounter++;\r
285                 getFooMethodReturnTypeName = method.getReturnType().getName();\r
286             }\r
287 \r
288             if (method.getName().equals("getBar")) {\r
289                 getBarMethodCounter++;\r
290                 getBarMethodReturnTypeName = method.getReturnType().getName();\r
291             }\r
292 \r
293             if (method.getName().equals("getNestedContainer")) {\r
294                 getNestedContainerCounter++;\r
295                 getNestedContainerReturnTypeName = method.getReturnType().getName();\r
296             }\r
297         }\r
298 \r
299         assertEquals(1, getFooMethodCounter);\r
300         assertEquals("Integer", getFooMethodReturnTypeName);\r
301 \r
302         assertEquals(1, getBarMethodCounter);\r
303         assertEquals("String", getBarMethodReturnTypeName);\r
304 \r
305         assertEquals(1, getNestedContainerCounter);\r
306         assertEquals("NestedContainer", getNestedContainerReturnTypeName);\r
307 \r
308         getFooMethodCounter = 0;\r
309         getBarMethodCounter = 0;\r
310 \r
311         getFooMethodReturnTypeName = "";\r
312         getBarMethodReturnTypeName = "";\r
313 \r
314         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {\r
315 \r
316             if (method.getName().equals("getFoo")) {\r
317                 getFooMethodCounter++;\r
318                 getFooMethodReturnTypeName = method.getReturnType().getName();\r
319             }\r
320 \r
321             if (method.getName().equals("getBar")) {\r
322                 getBarMethodCounter++;\r
323                 getBarMethodReturnTypeName = method.getReturnType().getName();\r
324             }\r
325         }\r
326 \r
327         assertEquals(1, getFooMethodCounter);\r
328         assertEquals("Short", getFooMethodReturnTypeName);\r
329 \r
330         assertEquals(1, getBarMethodCounter);\r
331         assertEquals("String", getBarMethodReturnTypeName);\r
332     }\r
333 \r
334     @Test\r
335     public void testLeafListResolving() {\r
336         final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();\r
337         final SchemaContext context = resolveSchemaContextFromFiles(filePath);\r
338         assertNotNull(context);\r
339 \r
340         final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
341         final List<Type> genTypes = bindingGen.generateTypes(context);\r
342 \r
343         assertNotNull(genTypes);\r
344         assertEquals(3, genTypes.size());\r
345 \r
346         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);\r
347         final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);\r
348 \r
349         assertEquals("SimpleContainer", simpleContainer.getName());\r
350         assertEquals("NestedContainer", nestedContainer.getName());\r
351         assertEquals(3, simpleContainer.getMethodDefinitions().size());\r
352         assertEquals(2, nestedContainer.getMethodDefinitions().size());\r
353 \r
354         int getFooMethodCounter = 0;\r
355         int getBarMethodCounter = 0;\r
356         int getNestedContainerCounter = 0;\r
357 \r
358         String getFooMethodReturnTypeName = "";\r
359         String getBarMethodReturnTypeName = "";\r
360         String getNestedContainerReturnTypeName = "";\r
361         for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {\r
362             if (method.getName().equals("getFoo")) {\r
363                 getFooMethodCounter++;\r
364                 getFooMethodReturnTypeName = method.getReturnType().getName();\r
365             }\r
366 \r
367             if (method.getName().equals("getBar")) {\r
368                 getBarMethodCounter++;\r
369                 getBarMethodReturnTypeName = method.getReturnType().getName();\r
370             }\r
371 \r
372             if (method.getName().equals("getNestedContainer")) {\r
373                 getNestedContainerCounter++;\r
374                 getNestedContainerReturnTypeName = method.getReturnType().getName();\r
375             }\r
376         }\r
377 \r
378         assertEquals(1, getFooMethodCounter);\r
379         assertEquals("List", getFooMethodReturnTypeName);\r
380 \r
381         assertEquals(1, getBarMethodCounter);\r
382         assertEquals("String", getBarMethodReturnTypeName);\r
383 \r
384         assertEquals(1, getNestedContainerCounter);\r
385         assertEquals("NestedContainer", getNestedContainerReturnTypeName);\r
386 \r
387         getFooMethodCounter = 0;\r
388         getBarMethodCounter = 0;\r
389 \r
390         getFooMethodReturnTypeName = "";\r
391         getBarMethodReturnTypeName = "";\r
392 \r
393         for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {\r
394             if (method.getName().equals("getFoo")) {\r
395                 getFooMethodCounter++;\r
396                 getFooMethodReturnTypeName = method.getReturnType().getName();\r
397             }\r
398 \r
399             if (method.getName().equals("getBar")) {\r
400                 getBarMethodCounter++;\r
401                 getBarMethodReturnTypeName = method.getReturnType().getName();\r
402             }\r
403         }\r
404 \r
405         assertEquals(1, getFooMethodCounter);\r
406         assertEquals("Short", getFooMethodReturnTypeName);\r
407 \r
408         assertEquals(1, getBarMethodCounter);\r
409         assertEquals("List", getBarMethodReturnTypeName);\r
410     }\r
411 \r
412     @Test\r
413     public void testListResolving() {\r
414         final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();\r
415         final SchemaContext context = resolveSchemaContextFromFiles(filePath);\r
416         assertNotNull(context);\r
417 \r
418         final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
419         final List<Type> genTypes = bindingGen.generateTypes(context);\r
420 \r
421         assertNotNull(genTypes);\r
422         assertEquals(5, genTypes.size());\r
423 \r
424         int listParentContainerMethodsCount = 0;\r
425         int simpleListMethodsCount = 0;\r
426         int listChildContainerMethodsCount = 0;\r
427         int listKeyClassCount = 0;\r
428 \r
429         int getSimpleListKeyMethodCount = 0;\r
430         int getListChildContainerMethodCount = 0;\r
431         int getFooMethodCount = 0;\r
432         int setFooMethodCount = 0;\r
433         int getSimpleLeafListMethodCount = 0;\r
434         int setSimpleLeafListMethodCount = 0;\r
435         int getBarMethodCount = 0;\r
436 \r
437         String getSimpleListKeyMethodReturnTypeName = "";\r
438         String getListChildContainerMethodReturnTypeName = "";\r
439 \r
440         int listKeyClassPropertyCount = 0;\r
441         String listKeyClassPropertyName = "";\r
442         String listKeyClassPropertyTypeName = "";\r
443         boolean listKeyClassPropertyReadOnly = false;\r
444 \r
445         int hashMethodParameterCount = 0;\r
446         String hashMethodParameterName = "";\r
447         String hashMethodParameterReturnTypeName = "";\r
448 \r
449         int equalMethodParameterCount = 0;\r
450         String equalMethodParameterName = "";\r
451         String equalMethodParameterReturnTypeName = "";\r
452 \r
453         for (final Type type : genTypes) {\r
454             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {\r
455                 final GeneratedType genType = (GeneratedType) type;\r
456                 if (genType.getName().equals("ListParentContainer")) {\r
457                     listParentContainerMethodsCount = genType.getMethodDefinitions().size();\r
458                 } else if (genType.getName().equals("SimpleList")) {\r
459                     simpleListMethodsCount = genType.getMethodDefinitions().size();\r
460                     final List<MethodSignature> methods = genType.getMethodDefinitions();\r
461                     for (final MethodSignature method : methods) {\r
462                         if (method.getName().equals("getSimpleListKey")) {\r
463                             getSimpleListKeyMethodCount++;\r
464                             getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();\r
465                         } else if (method.getName().equals("getListChildContainer")) {\r
466                             getListChildContainerMethodCount++;\r
467                             getListChildContainerMethodReturnTypeName = method.getReturnType().getName();\r
468                         } else if (method.getName().equals("getFoo")) {\r
469                             getFooMethodCount++;\r
470                         } else if (method.getName().equals("setFoo")) {\r
471                             setFooMethodCount++;\r
472                         } else if (method.getName().equals("getSimpleLeafList")) {\r
473                             getSimpleLeafListMethodCount++;\r
474                         } else if (method.getName().equals("setSimpleLeafList")) {\r
475                             setSimpleLeafListMethodCount++;\r
476                         } else if (method.getName().equals("getBar")) {\r
477                             getBarMethodCount++;\r
478                         }\r
479                     }\r
480                 } else if (genType.getName().equals("ListChildContainer")) {\r
481                     listChildContainerMethodsCount = genType.getMethodDefinitions().size();\r
482                 }\r
483             } else if (type instanceof GeneratedTransferObject) {\r
484                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;\r
485                 final List<GeneratedProperty> properties = genTO.getProperties();\r
486                 final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();\r
487                 final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();\r
488 \r
489                 listKeyClassCount++;\r
490                 listKeyClassPropertyCount = properties.size();\r
491                 listKeyClassPropertyName = properties.get(0).getName();\r
492                 listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();\r
493                 listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();\r
494 \r
495                 hashMethodParameterCount = hashProps.size();\r
496                 hashMethodParameterName = hashProps.get(0).getName();\r
497                 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();\r
498 \r
499                 equalMethodParameterCount = equalProps.size();\r
500                 equalMethodParameterName = equalProps.get(0).getName();\r
501                 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();\r
502 \r
503             }\r
504         }\r
505 \r
506         assertEquals(1, listParentContainerMethodsCount);\r
507         assertEquals(1, listChildContainerMethodsCount);\r
508         assertEquals(1, getSimpleListKeyMethodCount);\r
509         assertEquals(1, listKeyClassCount);\r
510 \r
511         assertEquals(1, listKeyClassPropertyCount);\r
512         assertEquals("ListKey", listKeyClassPropertyName);\r
513         assertEquals("Byte", listKeyClassPropertyTypeName);\r
514         assertEquals(true, listKeyClassPropertyReadOnly);\r
515         assertEquals(1, hashMethodParameterCount);\r
516         assertEquals("ListKey", hashMethodParameterName);\r
517         assertEquals("Byte", hashMethodParameterReturnTypeName);\r
518         assertEquals(1, equalMethodParameterCount);\r
519         assertEquals("ListKey", equalMethodParameterName);\r
520         assertEquals("Byte", equalMethodParameterReturnTypeName);\r
521 \r
522         assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);\r
523 \r
524         assertEquals(1, getListChildContainerMethodCount);\r
525         assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);\r
526         assertEquals(1, getFooMethodCount);\r
527         assertEquals(0, setFooMethodCount);\r
528         assertEquals(1, getSimpleLeafListMethodCount);\r
529         assertEquals(0, setSimpleLeafListMethodCount);\r
530         assertEquals(1, getBarMethodCount);\r
531 \r
532         assertEquals(5, simpleListMethodsCount);\r
533     }\r
534 \r
535     @Test\r
536     public void testListCompositeKeyResolving() {\r
537         final String filePath = getClass().getResource("/list-composite-key.yang").getPath();\r
538         final SchemaContext context = resolveSchemaContextFromFiles(filePath);\r
539 \r
540         assertNotNull(context);\r
541 \r
542         final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
543         final List<Type> genTypes = bindingGen.generateTypes(context);\r
544 \r
545         assertNotNull(genTypes);\r
546         assertEquals(7, genTypes.size());\r
547 \r
548         int genTypesCount = 0;\r
549         int genTOsCount = 0;\r
550 \r
551         int compositeKeyListKeyPropertyCount = 0;\r
552         int compositeKeyListKeyCount = 0;\r
553         int innerListKeyPropertyCount = 0;\r
554 \r
555         for (final Type type : genTypes) {\r
556             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {\r
557                 genTypesCount++;\r
558             } else if (type instanceof GeneratedTransferObject) {\r
559                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;\r
560 \r
561                 if (genTO.getName().equals("CompositeKeyListKey")) {\r
562                     compositeKeyListKeyCount++;\r
563                     final List<GeneratedProperty> properties = genTO.getProperties();\r
564                     for (final GeneratedProperty prop : properties) {\r
565                         if (prop.getName().equals("Key1")) {\r
566                             compositeKeyListKeyPropertyCount++;\r
567                         } else if (prop.getName().equals("Key2")) {\r
568                             compositeKeyListKeyPropertyCount++;\r
569                         }\r
570                     }\r
571                     genTOsCount++;\r
572                 } else if (genTO.getName().equals("InnerListKey")) {\r
573                     final List<GeneratedProperty> properties = genTO.getProperties();\r
574                     innerListKeyPropertyCount = properties.size();\r
575                     genTOsCount++;\r
576                 }\r
577             }\r
578         }\r
579         assertEquals(1, compositeKeyListKeyCount);\r
580         assertEquals(2, compositeKeyListKeyPropertyCount);\r
581 \r
582         assertEquals(1, innerListKeyPropertyCount);\r
583 \r
584         assertEquals(5, genTypesCount);\r
585         assertEquals(2, genTOsCount);\r
586     }\r
587 \r
588     @Test\r
589     public void testGeneratedTypes() {\r
590         final String filePath = getClass().getResource("/demo-topology.yang").getPath();\r
591         final SchemaContext context = resolveSchemaContextFromFiles(filePath);\r
592         assertNotNull(context);\r
593 \r
594         final BindingGenerator bindingGen = new BindingGeneratorImpl();\r
595         final List<Type> genTypes = bindingGen.generateTypes(context);\r
596 \r
597         assertNotNull(genTypes);\r
598         assertEquals(14, genTypes.size());\r
599 \r
600         int genTypesCount = 0;\r
601         int genTOsCount = 0;\r
602         for (final Type type : genTypes) {\r
603             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {\r
604                 genTypesCount++;\r
605             } else if (type instanceof GeneratedTransferObject) {\r
606                 genTOsCount++;\r
607             }\r
608         }\r
609 \r
610         assertEquals(11, genTypesCount);\r
611         assertEquals(3, genTOsCount);\r
612     }\r
613 }\r