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(3, simpleContainer.getMethodDefinitions().size());
257 assertEquals(2, 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 // TODO no setter methods, because 'config' is default true
297 // assertEquals(setFooMethodCounter, 1);
298 // assertEquals(setFooMethodInputParamName, "foo");
299 // assertEquals(setFooMethodInputParamTypeName, "Integer");
301 assertEquals(getBarMethodCounter, 1);
302 assertEquals(getBarMethodReturnTypeName, "String");
304 assertEquals(getNestedContainerCounter, 1);
305 assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
307 setFooMethodCounter = 0;
308 getFooMethodCounter = 0;
309 getBarMethodCounter = 0;
310 int setBarMethodCounter = 0;
312 getFooMethodReturnTypeName = "";
313 setFooMethodInputParamName = "";
314 setFooMethodInputParamTypeName = "";
315 getBarMethodReturnTypeName = "";
316 String setBarMethodInputParamName = "";
317 String setBarMethodInputParamTypeName = "";
319 for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
321 if (method.getName().equals("getFoo")) {
322 getFooMethodCounter++;
323 getFooMethodReturnTypeName = method.getReturnType().getName();
326 if (method.getName().equals("setFoo")) {
327 setFooMethodCounter++;
328 final MethodSignature.Parameter param = method.getParameters().get(0);
329 setFooMethodInputParamName = param.getName();
330 setFooMethodInputParamTypeName = param.getType().getName();
333 if (method.getName().equals("getBar")) {
334 getBarMethodCounter++;
335 getBarMethodReturnTypeName = method.getReturnType().getName();
338 if (method.getName().equals("setBar")) {
339 setBarMethodCounter++;
340 final MethodSignature.Parameter param = method.getParameters().get(0);
341 setBarMethodInputParamName = param.getName();
342 setBarMethodInputParamTypeName = param.getType().getName();
346 assertEquals(1, getFooMethodCounter);
347 assertEquals(getFooMethodReturnTypeName, "Short");
349 // TODO no setter methods, because 'config' is default true
350 // assertEquals(1, setFooMethodCounter);
351 // assertEquals(setFooMethodInputParamName, "foo");
352 // assertEquals(setFooMethodInputParamTypeName, "Short");
354 assertEquals(1, getBarMethodCounter);
355 assertEquals(getBarMethodReturnTypeName, "String");
357 // TODO no setter methods, because 'config' is default true
358 // assertEquals(1, setBarMethodCounter);
359 // assertEquals(setBarMethodInputParamName, "bar");
360 // assertEquals(setBarMethodInputParamTypeName, "String");
364 public void testLeafListResolving() {
365 final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
366 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
367 assertNotNull(context);
369 final BindingGenerator bindingGen = new BindingGeneratorImpl();
370 final List<Type> genTypes = bindingGen.generateTypes(context);
372 assertNotNull(genTypes);
373 assertEquals(4, genTypes.size());
375 final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
376 final GeneratedType nestedContainer = (GeneratedType) genTypes.get(2);
378 assertEquals("SimpleContainer", simpleContainer.getName());
379 assertEquals("NestedContainer", nestedContainer.getName());
380 assertEquals(3, simpleContainer.getMethodDefinitions().size());
381 assertEquals(2, nestedContainer.getMethodDefinitions().size());
383 int setFooMethodCounter = 0;
384 int getFooMethodCounter = 0;
385 int getBarMethodCounter = 0;
386 int getNestedContainerCounter = 0;
388 String getFooMethodReturnTypeName = "";
389 String setFooMethodInputParamName = "";
390 String setFooMethodInputParamTypeName = "";
391 String getBarMethodReturnTypeName = "";
392 String getNestedContainerReturnTypeName = "";
393 for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
394 if (method.getName().equals("getFoo")) {
395 getFooMethodCounter++;
396 getFooMethodReturnTypeName = method.getReturnType().getName();
399 if (method.getName().equals("setFoo")) {
400 setFooMethodCounter++;
401 final MethodSignature.Parameter param = method.getParameters().get(0);
402 setFooMethodInputParamName = param.getName();
403 setFooMethodInputParamTypeName = param.getType().getName();
406 if (method.getName().equals("getBar")) {
407 getBarMethodCounter++;
408 getBarMethodReturnTypeName = method.getReturnType().getName();
411 if (method.getName().equals("getNestedContainer")) {
412 getNestedContainerCounter++;
413 getNestedContainerReturnTypeName = method.getReturnType().getName();
417 assertEquals(1, getFooMethodCounter);
418 assertEquals(getFooMethodReturnTypeName, "List");
420 // TODO no setter methods, because 'config' is default true
421 // assertEquals(1, setFooMethodCounter);
422 // assertEquals(setFooMethodInputParamName, "foo");
423 // assertEquals(setFooMethodInputParamTypeName, "List");
425 assertEquals(1, getBarMethodCounter);
426 assertEquals(getBarMethodReturnTypeName, "String");
428 assertEquals(1, getNestedContainerCounter);
429 assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
431 setFooMethodCounter = 0;
432 getFooMethodCounter = 0;
433 getBarMethodCounter = 0;
435 getFooMethodReturnTypeName = "";
436 setFooMethodInputParamName = "";
437 setFooMethodInputParamTypeName = "";
438 getBarMethodReturnTypeName = "";
440 for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
441 if (method.getName().equals("getFoo")) {
442 getFooMethodCounter++;
443 getFooMethodReturnTypeName = method.getReturnType().getName();
446 if (method.getName().equals("setFoo")) {
447 setFooMethodCounter++;
448 final MethodSignature.Parameter param = method.getParameters().get(0);
449 setFooMethodInputParamName = param.getName();
450 setFooMethodInputParamTypeName = param.getType().getName();
453 if (method.getName().equals("getBar")) {
454 getBarMethodCounter++;
455 getBarMethodReturnTypeName = method.getReturnType().getName();
459 assertEquals(1, getFooMethodCounter);
460 assertEquals(getFooMethodReturnTypeName, "Short");
462 // TODO no setter methods, because 'config' is default true
463 // assertEquals(1, setFooMethodCounter);
464 // assertEquals(setFooMethodInputParamName, "foo");
465 // assertEquals(setFooMethodInputParamTypeName, "Short");
467 assertEquals(1, getBarMethodCounter);
468 assertEquals(getBarMethodReturnTypeName, "List");
472 public void testListResolving() {
473 final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
474 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
475 assertNotNull(context);
477 final BindingGenerator bindingGen = new BindingGeneratorImpl();
478 final List<Type> genTypes = bindingGen.generateTypes(context);
480 assertNotNull(genTypes);
481 assertEquals(6, genTypes.size());
483 int genTypesCount = 0;
486 int listParentContainerMethodsCount = 0;
487 int simpleListMethodsCount = 0;
488 int listChildContainerMethodsCount = 0;
489 int listKeyClassCount = 0;
491 int getSimpleListKeyMethodCount = 0;
492 int getListChildContainerMethodCount = 0;
493 int getFooMethodCount = 0;
494 int setFooMethodCount = 0;
495 int getSimpleLeafListMethodCount = 0;
496 int setSimpleLeafListMethodCount = 0;
497 int getBarMethodCount = 0;
499 String getSimpleListKeyMethodReturnTypeName = "";
500 String getListChildContainerMethodReturnTypeName = "";
502 int listKeyClassPropertyCount = 0;
503 String listKeyClassPropertyName = "";
504 String listKeyClassPropertyTypeName = "";
505 boolean listKeyClassPropertyReadOnly = false;
507 int hashMethodParameterCount = 0;
508 String hashMethodParameterName = "";
509 String hashMethodParameterReturnTypeName = "";
511 int equalMethodParameterCount = 0;
512 String equalMethodParameterName = "";
513 String equalMethodParameterReturnTypeName = "";
515 for (final Type type : genTypes) {
516 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
517 final GeneratedType genType = (GeneratedType) type;
518 if (genType.getName().equals("ListParentContainer")) {
519 listParentContainerMethodsCount = genType.getMethodDefinitions().size();
521 } else if (genType.getName().equals("SimpleList")) {
522 simpleListMethodsCount = genType.getMethodDefinitions().size();
523 final List<MethodSignature> methods = genType.getMethodDefinitions();
524 for (final MethodSignature method : methods) {
525 if (method.getName().equals("getSimpleListKey")) {
526 getSimpleListKeyMethodCount++;
527 getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
528 } else if (method.getName().equals("getListChildContainer")) {
529 getListChildContainerMethodCount++;
530 getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
531 } else if (method.getName().equals("getFoo")) {
533 } else if (method.getName().equals("setFoo")) {
535 } else if (method.getName().equals("getSimpleLeafList")) {
536 getSimpleLeafListMethodCount++;
537 } else if (method.getName().equals("setSimpleLeafList")) {
538 setSimpleLeafListMethodCount++;
539 } else if (method.getName().equals("getBar")) {
544 } else if (genType.getName().equals("ListChildContainer")) {
545 listChildContainerMethodsCount = genType.getMethodDefinitions().size();
548 } else if (type instanceof GeneratedTransferObject) {
550 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
551 final List<GeneratedProperty> properties = genTO.getProperties();
552 final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
553 final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
556 listKeyClassPropertyCount = properties.size();
557 listKeyClassPropertyName = properties.get(0).getName();
558 listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
559 listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
561 hashMethodParameterCount = hashProps.size();
562 hashMethodParameterName = hashProps.get(0).getName();
563 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
565 equalMethodParameterCount = equalProps.size();
566 equalMethodParameterName = equalProps.get(0).getName();
567 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
572 assertEquals(1, listParentContainerMethodsCount);
573 assertEquals(1, listChildContainerMethodsCount);
574 assertEquals(1, getSimpleListKeyMethodCount);
575 assertEquals(1, listKeyClassCount);
577 assertEquals(1, listKeyClassPropertyCount);
578 assertEquals("ListKey", listKeyClassPropertyName);
579 assertEquals("Byte", listKeyClassPropertyTypeName);
580 assertEquals(true, listKeyClassPropertyReadOnly);
581 assertEquals(1, hashMethodParameterCount);
582 assertEquals("ListKey", hashMethodParameterName);
583 assertEquals("Byte", hashMethodParameterReturnTypeName);
584 assertEquals(1, equalMethodParameterCount);
585 assertEquals("ListKey", equalMethodParameterName);
586 assertEquals("Byte", equalMethodParameterReturnTypeName);
588 assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
590 assertEquals(1, getListChildContainerMethodCount);
591 assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
592 assertEquals(1, getFooMethodCount);
593 assertEquals(0, setFooMethodCount);
594 assertEquals(1, getSimpleLeafListMethodCount);
595 assertEquals(0, setSimpleLeafListMethodCount);
596 assertEquals(1, getBarMethodCount);
598 assertEquals(5, simpleListMethodsCount);
602 public void testListCompositeKeyResolving() {
603 final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
604 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
606 assertNotNull(context);
608 final BindingGenerator bindingGen = new BindingGeneratorImpl();
609 final List<Type> genTypes = bindingGen.generateTypes(context);
611 assertNotNull(genTypes);
612 assertEquals(8, genTypes.size());
614 int genTypesCount = 0;
617 int compositeKeyListKeyPropertyCount = 0;
618 int compositeKeyListKeyCount = 0;
619 int innerListKeyPropertyCount = 0;
621 for (final Type type : genTypes) {
622 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
624 } else if (type instanceof GeneratedTransferObject) {
625 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
627 if (genTO.getName().equals("CompositeKeyListKey")) {
628 compositeKeyListKeyCount++;
629 final List<GeneratedProperty> properties = genTO.getProperties();
630 for (final GeneratedProperty prop : properties) {
631 if (prop.getName().equals("Key1")) {
632 compositeKeyListKeyPropertyCount++;
633 } else if (prop.getName().equals("Key2")) {
634 compositeKeyListKeyPropertyCount++;
638 } else if (genTO.getName().equals("InnerListKey")) {
639 final List<GeneratedProperty> properties = genTO.getProperties();
640 innerListKeyPropertyCount = properties.size();
645 assertEquals(1, compositeKeyListKeyCount);
646 assertEquals(2, compositeKeyListKeyPropertyCount);
648 assertEquals(1, innerListKeyPropertyCount);
650 assertEquals(6, genTypesCount);
651 assertEquals(2, genTOsCount);
655 public void testGeneratedTypes() {
656 final String filePath = getClass().getResource("/demo-topology.yang").getPath();
657 final SchemaContext context = resolveSchemaContextFromFiles(filePath);
658 assertNotNull(context);
660 final BindingGenerator bindingGen = new BindingGeneratorImpl();
661 final List<Type> genTypes = bindingGen.generateTypes(context);
663 assertNotNull(genTypes);
664 assertEquals(15, genTypes.size());
666 int genTypesCount = 0;
668 for (final Type type : genTypes) {
669 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
671 } else if (type instanceof GeneratedTransferObject) {
676 assertEquals(12, genTypesCount);
677 assertEquals(3, genTOsCount);