2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.binding.generator.impl;
10 import static org.junit.Assert.*;
13 import java.util.ArrayList;
14 import java.util.List;
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;
29 public class GeneratedTypesTest {
31 private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
32 final YangModelParser parser = new YangParserImpl();
34 final List<File> inputFiles = new ArrayList<File>();
35 for (int i = 0; i < yangFiles.length; ++i) {
36 inputFiles.add(new File(yangFiles[i]));
39 final Set<Module> modules = parser.parseYangModels(inputFiles);
40 return parser.resolveSchemaContext(modules);
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);
50 final BindingGenerator bindingGen = new BindingGeneratorImpl();
51 final List<Type> genTypes = bindingGen.generateTypes(context);
53 assertNotNull(genTypes);
54 assertEquals(29, genTypes.size());
58 public void testLeafrefResolving() {
59 final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
61 final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
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")
67 final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
70 assertNotNull(topologyPath);
71 assertNotNull(interfacesPath);
72 // assertTrue(ifTypePath != null);
73 assertNotNull(inetTypesPath);
74 assertNotNull(yangTypesPath);
76 // final SchemaContext context = resolveSchemaContextFromFiles(
77 // topologyPath, interfacesPath, ifTypePath, inetTypesPath,
79 final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
81 assertNotNull(context);
82 assertEquals(4, context.getModules().size());
84 final BindingGenerator bindingGen = new BindingGeneratorImpl();
85 final List<Type> genTypes = bindingGen.generateTypes(context);
87 assertEquals(57, genTypes.size());
88 assertNotNull(genTypes);
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;
116 assertNotNull(gtIfcKey);
117 assertNotNull(gtIfc);
118 assertNotNull(gtNetworkLink);
119 assertNotNull(gtSource);
120 assertNotNull(gtDest);
121 assertNotNull(gtTunnel);
122 assertNotNull(gtTunnelKey);
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;
133 assertNotNull(ifcIdProp);
134 Type ifcIdPropType = ifcIdProp.getReturnType();
135 assertNotNull(ifcIdPropType);
136 assertFalse(ifcIdPropType.equals("java.lang.Void"));
137 assertEquals(ifcIdPropType.getName(), "String");
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")) {
147 } else if (method.getName().equals("getHigherLayerIf")) {
148 getHigherLayerIf = method;
151 assertNotNull(getIfcKey);
152 Type getIfcKeyType = getIfcKey.getReturnType();
153 assertNotNull(getIfcKeyType);
154 assertFalse(getIfcKeyType.equals("java.lang.Void"));
155 assertEquals(getIfcKeyType.getName(), "InterfaceKey");
157 assertNotNull(getHigherLayerIf);
158 Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
159 assertNotNull(getHigherLayerIfType);
160 assertFalse(getHigherLayerIfType.equals("java.lang.Void"));
161 assertEquals(getHigherLayerIfType.getName(), "List");
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")) {
172 assertNotNull(getIfc);
173 Type getIfcType = getIfc.getReturnType();
174 assertNotNull(getIfcType);
175 assertFalse(getIfcType.equals("java.lang.Void"));
176 assertEquals(getIfcType.getName(), "String");
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;
187 assertNotNull(getIdSource);
188 Type getIdType = getIdSource.getReturnType();
189 assertNotNull(getIdType);
190 assertFalse(getIdType.equals("java.lang.Void"));
191 assertEquals(getIdType.getName(), "Uri");
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")) {
202 assertNotNull(getIdDest);
203 Type getIdDestType = getIdDest.getReturnType();
204 assertNotNull(getIdDestType);
205 assertFalse(getIdDestType.equals("java.lang.Void"));
206 assertEquals(getIdDestType.getName(), "Uri");
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;
217 assertNotNull(getTunnelKey);
218 Type getTunnelKeyType = getTunnelKey.getReturnType();
219 assertNotNull(getTunnelKeyType);
220 assertFalse(getTunnelKeyType.equals("java.lang.Void"));
221 assertEquals(getTunnelKeyType.getName(), "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")) {
232 assertNotNull(tunnelId);
233 Type tunnelIdType = tunnelId.getReturnType();
234 assertNotNull(tunnelIdType);
235 assertFalse(tunnelIdType.equals("java.lang.Void"));
236 assertEquals(tunnelIdType.getName(), "Uri");
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);
245 final BindingGenerator bindingGen = new BindingGeneratorImpl();
246 final List<Type> genTypes = bindingGen.generateTypes(context);
248 assertNotNull(genTypes);
249 assertEquals(4, genTypes.size());
251 final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
252 final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
254 assertEquals("SimpleContainer", simpleContainer.getName());
255 assertEquals("NestedContainer", nestedContainer.getName());
256 assertEquals(5, simpleContainer.getMethodDefinitions().size());
257 assertEquals(4, nestedContainer.getMethodDefinitions().size());
259 int setFooMethodCounter = 0;
260 int getFooMethodCounter = 0;
261 int getBarMethodCounter = 0;
262 int getNestedContainerCounter = 0;
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();
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();
282 if (method.getName().equals("getBar")) {
283 getBarMethodCounter++;
284 getBarMethodReturnTypeName = method.getReturnType().getName();
287 if (method.getName().equals("getNestedContainer")) {
288 getNestedContainerCounter++;
289 getNestedContainerReturnTypeName = method.getReturnType().getName();
293 assertEquals(getFooMethodCounter, 1);
294 assertEquals(getFooMethodReturnTypeName, "Integer");
296 assertEquals(setFooMethodCounter, 1);
297 assertEquals(setFooMethodInputParamName, "foo");
298 assertEquals(setFooMethodInputParamTypeName, "Integer");
300 assertEquals(getBarMethodCounter, 1);
301 assertEquals(getBarMethodReturnTypeName, "String");
303 assertEquals(getNestedContainerCounter, 1);
304 assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
306 setFooMethodCounter = 0;
307 getFooMethodCounter = 0;
308 getBarMethodCounter = 0;
309 int setBarMethodCounter = 0;
311 getFooMethodReturnTypeName = "";
312 setFooMethodInputParamName = "";
313 setFooMethodInputParamTypeName = "";
314 getBarMethodReturnTypeName = "";
315 String setBarMethodInputParamName = "";
316 String setBarMethodInputParamTypeName = "";
318 for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
320 if (method.getName().equals("getFoo")) {
321 getFooMethodCounter++;
322 getFooMethodReturnTypeName = method.getReturnType().getName();
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();
332 if (method.getName().equals("getBar")) {
333 getBarMethodCounter++;
334 getBarMethodReturnTypeName = method.getReturnType().getName();
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();
345 assertEquals(1, getFooMethodCounter);
346 assertEquals(getFooMethodReturnTypeName, "Short");
348 assertEquals(1, setFooMethodCounter);
349 assertEquals(setFooMethodInputParamName, "foo");
350 assertEquals(setFooMethodInputParamTypeName, "Short");
352 assertEquals(1, getBarMethodCounter);
353 assertEquals(getBarMethodReturnTypeName, "String");
355 assertEquals(1, setBarMethodCounter);
356 assertEquals(setBarMethodInputParamName, "bar");
357 assertEquals(setBarMethodInputParamTypeName, "String");
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);
366 final BindingGenerator bindingGen = new BindingGeneratorImpl();
367 final List<Type> genTypes = bindingGen.generateTypes(context);
369 assertNotNull(genTypes);
370 assertEquals(4, genTypes.size());
372 final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
373 final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
375 assertEquals("SimpleContainer", simpleContainer.getName());
376 assertEquals("NestedContainer", nestedContainer.getName());
377 assertEquals(5, simpleContainer.getMethodDefinitions().size());
378 assertEquals(3, nestedContainer.getMethodDefinitions().size());
380 int setFooMethodCounter = 0;
381 int getFooMethodCounter = 0;
382 int getBarMethodCounter = 0;
383 int getNestedContainerCounter = 0;
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();
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();
403 if (method.getName().equals("getBar")) {
404 getBarMethodCounter++;
405 getBarMethodReturnTypeName = method.getReturnType().getName();
408 if (method.getName().equals("getNestedContainer")) {
409 getNestedContainerCounter++;
410 getNestedContainerReturnTypeName = method.getReturnType().getName();
414 assertEquals(1, getFooMethodCounter);
415 assertEquals(getFooMethodReturnTypeName, "List");
417 assertEquals(1, setFooMethodCounter);
418 assertEquals(setFooMethodInputParamName, "foo");
419 assertEquals(setFooMethodInputParamTypeName, "List");
421 assertEquals(1, getBarMethodCounter);
422 assertEquals(getBarMethodReturnTypeName, "String");
424 assertEquals(1, getNestedContainerCounter);
425 assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
427 setFooMethodCounter = 0;
428 getFooMethodCounter = 0;
429 getBarMethodCounter = 0;
431 getFooMethodReturnTypeName = "";
432 setFooMethodInputParamName = "";
433 setFooMethodInputParamTypeName = "";
434 getBarMethodReturnTypeName = "";
436 for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
437 if (method.getName().equals("getFoo")) {
438 getFooMethodCounter++;
439 getFooMethodReturnTypeName = method.getReturnType().getName();
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();
449 if (method.getName().equals("getBar")) {
450 getBarMethodCounter++;
451 getBarMethodReturnTypeName = method.getReturnType().getName();
455 assertEquals(1, getFooMethodCounter);
456 assertEquals(getFooMethodReturnTypeName, "Short");
458 assertEquals(1, setFooMethodCounter);
459 assertEquals(setFooMethodInputParamName, "foo");
460 assertEquals(setFooMethodInputParamTypeName, "Short");
462 assertEquals(1, getBarMethodCounter);
463 assertEquals(getBarMethodReturnTypeName, "List");
467 public void testListResolving() {
468 final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
469 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
470 assertNotNull(context);
472 final BindingGenerator bindingGen = new BindingGeneratorImpl();
473 final List<Type> genTypes = bindingGen.generateTypes(context);
475 assertNotNull(genTypes);
476 assertEquals(6, genTypes.size());
478 int genTypesCount = 0;
481 int listParentContainerMethodsCount = 0;
482 int simpleListMethodsCount = 0;
483 int listChildContainerMethodsCount = 0;
484 int listKeyClassCount = 0;
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;
494 String getSimpleListKeyMethodReturnTypeName = "";
495 String getListChildContainerMethodReturnTypeName = "";
497 int listKeyClassPropertyCount = 0;
498 String listKeyClassPropertyName = "";
499 String listKeyClassPropertyTypeName = "";
500 boolean listKeyClassPropertyReadOnly = false;
502 int hashMethodParameterCount = 0;
503 String hashMethodParameterName = "";
504 String hashMethodParameterReturnTypeName = "";
506 int equalMethodParameterCount = 0;
507 String equalMethodParameterName = "";
508 String equalMethodParameterReturnTypeName = "";
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();
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")) {
528 } else if (method.getName().equals("setFoo")) {
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")) {
539 } else if (genType.getName().equals("ListChildContainer")) {
540 listChildContainerMethodsCount = genType.getMethodDefinitions().size();
543 } else if (type instanceof GeneratedTransferObject) {
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();
551 listKeyClassPropertyCount = properties.size();
552 listKeyClassPropertyName = properties.get(0).getName();
553 listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
554 listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
556 hashMethodParameterCount = hashProps.size();
557 hashMethodParameterName = hashProps.get(0).getName();
558 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
560 equalMethodParameterCount = equalProps.size();
561 equalMethodParameterName = equalProps.get(0).getName();
562 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
567 assertEquals(2, listParentContainerMethodsCount);
568 assertEquals(2, listChildContainerMethodsCount);
569 assertEquals(1, getSimpleListKeyMethodCount);
570 assertEquals(1, listKeyClassCount);
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);
583 assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
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);
593 assertEquals(8, simpleListMethodsCount);
597 public void testListCompositeKeyResolving() {
598 final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
599 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
601 assertNotNull(context);
603 final BindingGenerator bindingGen = new BindingGeneratorImpl();
604 final List<Type> genTypes = bindingGen.generateTypes(context);
606 assertNotNull(genTypes);
607 assertEquals(8, genTypes.size());
609 int genTypesCount = 0;
612 int compositeKeyListKeyPropertyCount = 0;
613 int compositeKeyListKeyCount = 0;
614 int innerListKeyPropertyCount = 0;
616 for (final Type type : genTypes) {
617 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
619 } else if (type instanceof GeneratedTransferObject) {
620 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
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++;
633 } else if (genTO.getName().equals("InnerListKey")) {
634 final List<GeneratedProperty> properties = genTO.getProperties();
635 innerListKeyPropertyCount = properties.size();
640 assertEquals(1, compositeKeyListKeyCount);
641 assertEquals(2, compositeKeyListKeyPropertyCount);
643 assertEquals(1, innerListKeyPropertyCount);
645 assertEquals(6, genTypesCount);
646 assertEquals(2, genTOsCount);
650 public void testGeneratedTypes() {
651 final String filePath = getClass().getResource("/demo-topology.yang").getPath();
652 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
653 assertNotNull(context);
655 final BindingGenerator bindingGen = new BindingGeneratorImpl();
656 final List<Type> genTypes = bindingGen.generateTypes(context);
658 assertNotNull(genTypes);
659 assertEquals(15, genTypes.size());
661 int genTypesCount = 0;
663 for (final Type type : genTypes) {
664 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
666 } else if (type instanceof GeneratedTransferObject) {
671 assertEquals(12, genTypesCount);
672 assertEquals(3, genTOsCount);