2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\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
8 package org.opendaylight.yangtools.sal.binding.generator.impl;
\r
10 import static org.junit.Assert.*;
\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
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
29 public class GeneratedTypesTest {
\r
31 private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
\r
32 final YangModelParser parser = new YangParserImpl();
\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
39 final Set<Module> modules = parser.parseYangModels(inputFiles);
\r
40 return parser.resolveSchemaContext(modules);
\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
50 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
51 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
53 assertNotNull(genTypes);
\r
54 assertEquals(26, genTypes.size());
\r
58 public void testLeafrefResolving() {
\r
59 final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
\r
61 final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
\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
67 final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
\r
70 assertNotNull(topologyPath);
\r
71 assertNotNull(interfacesPath);
\r
72 // assertTrue(ifTypePath != null);
\r
73 assertNotNull(inetTypesPath);
\r
74 assertNotNull(yangTypesPath);
\r
76 // final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, ifTypePath,
\r
77 // inetTypesPath, yangTypesPath);
\r
78 final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
\r
80 assertNotNull(context);
\r
81 assertEquals(4, context.getModules().size());
\r
83 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
84 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
86 assertEquals(51, genTypes.size());
\r
87 assertNotNull(genTypes);
\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
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
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
136 assertNotNull(condLeafref);
\r
137 Type condLeafRT = condLeafref.getReturnType();
\r
138 assertNotNull(condLeafRT);
\r
139 assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName());
\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
150 assertNotNull(ifcIdProp);
\r
151 Type ifcIdPropType = ifcIdProp.getReturnType();
\r
152 assertNotNull(ifcIdPropType);
\r
153 assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName());
\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
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
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
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
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
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
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
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
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
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
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
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
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
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
261 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
262 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
264 assertNotNull(genTypes);
\r
265 assertEquals(3, genTypes.size());
\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
276 assertNotNull(simpleContainer);
\r
277 assertNotNull(nestedContainer);
\r
278 assertEquals(3, simpleContainer.getMethodDefinitions().size());
\r
279 assertEquals(2, nestedContainer.getMethodDefinitions().size());
\r
281 int getFooMethodCounter = 0;
\r
282 int getBarMethodCounter = 0;
\r
283 int getNestedContainerCounter = 0;
\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
294 if (method.getName().equals("getBar")) {
\r
295 getBarMethodCounter++;
\r
296 getBarMethodReturnTypeName = method.getReturnType().getName();
\r
299 if (method.getName().equals("getNestedContainer")) {
\r
300 getNestedContainerCounter++;
\r
301 getNestedContainerReturnTypeName = method.getReturnType().getName();
\r
305 assertEquals(1, getFooMethodCounter);
\r
306 assertEquals("Integer", getFooMethodReturnTypeName);
\r
308 assertEquals(1, getBarMethodCounter);
\r
309 assertEquals("String", getBarMethodReturnTypeName);
\r
311 assertEquals(1, getNestedContainerCounter);
\r
312 assertEquals("NestedContainer", getNestedContainerReturnTypeName);
\r
314 getFooMethodCounter = 0;
\r
315 getBarMethodCounter = 0;
\r
317 getFooMethodReturnTypeName = "";
\r
318 getBarMethodReturnTypeName = "";
\r
320 for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
\r
322 if (method.getName().equals("getFoo")) {
\r
323 getFooMethodCounter++;
\r
324 getFooMethodReturnTypeName = method.getReturnType().getName();
\r
327 if (method.getName().equals("getBar")) {
\r
328 getBarMethodCounter++;
\r
329 getBarMethodReturnTypeName = method.getReturnType().getName();
\r
333 assertEquals(1, getFooMethodCounter);
\r
334 assertEquals("Short", getFooMethodReturnTypeName);
\r
336 assertEquals(1, getBarMethodCounter);
\r
337 assertEquals("String", getBarMethodReturnTypeName);
\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
346 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
347 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
349 assertNotNull(genTypes);
\r
350 assertEquals(3, genTypes.size());
\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
361 assertNotNull(simpleContainer);
\r
362 assertNotNull(nestedContainer);
\r
363 assertEquals(3, simpleContainer.getMethodDefinitions().size());
\r
364 assertEquals(2, nestedContainer.getMethodDefinitions().size());
\r
366 int getFooMethodCounter = 0;
\r
367 int getBarMethodCounter = 0;
\r
368 int getNestedContainerCounter = 0;
\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
379 if (method.getName().equals("getBar")) {
\r
380 getBarMethodCounter++;
\r
381 getBarMethodReturnTypeName = method.getReturnType().getName();
\r
384 if (method.getName().equals("getNestedContainer")) {
\r
385 getNestedContainerCounter++;
\r
386 getNestedContainerReturnTypeName = method.getReturnType().getName();
\r
390 assertEquals(1, getFooMethodCounter);
\r
391 assertEquals("List", getFooMethodReturnTypeName);
\r
393 assertEquals(1, getBarMethodCounter);
\r
394 assertEquals("String", getBarMethodReturnTypeName);
\r
396 assertEquals(1, getNestedContainerCounter);
\r
397 assertEquals("NestedContainer", getNestedContainerReturnTypeName);
\r
399 getFooMethodCounter = 0;
\r
400 getBarMethodCounter = 0;
\r
402 getFooMethodReturnTypeName = "";
\r
403 getBarMethodReturnTypeName = "";
\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
411 if (method.getName().equals("getBar")) {
\r
412 getBarMethodCounter++;
\r
413 getBarMethodReturnTypeName = method.getReturnType().getName();
\r
417 assertEquals(1, getFooMethodCounter);
\r
418 assertEquals("Short", getFooMethodReturnTypeName);
\r
420 assertEquals(1, getBarMethodCounter);
\r
421 assertEquals("List", getBarMethodReturnTypeName);
\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
430 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
431 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
433 assertNotNull(genTypes);
\r
434 assertEquals(5, genTypes.size());
\r
436 int listParentContainerMethodsCount = 0;
\r
437 int simpleListMethodsCount = 0;
\r
438 int listChildContainerMethodsCount = 0;
\r
439 int listKeyClassCount = 0;
\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
449 String getSimpleListKeyMethodReturnTypeName = "";
\r
450 String getListChildContainerMethodReturnTypeName = "";
\r
452 int listKeyClassPropertyCount = 0;
\r
453 String listKeyClassPropertyName = "";
\r
454 String listKeyClassPropertyTypeName = "";
\r
455 boolean listKeyClassPropertyReadOnly = false;
\r
457 int hashMethodParameterCount = 0;
\r
458 String hashMethodParameterName = "";
\r
459 String hashMethodParameterReturnTypeName = "";
\r
461 int equalMethodParameterCount = 0;
\r
462 String equalMethodParameterName = "";
\r
463 String equalMethodParameterReturnTypeName = "";
\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
492 } else if (genType.getName().equals("ListChildContainer")) {
\r
493 listChildContainerMethodsCount = genType.getMethodDefinitions().size();
\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
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
507 hashMethodParameterCount = hashProps.size();
\r
508 hashMethodParameterName = hashProps.get(0).getName();
\r
509 hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
\r
511 equalMethodParameterCount = equalProps.size();
\r
512 equalMethodParameterName = equalProps.get(0).getName();
\r
513 equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
\r
518 assertEquals(1, listParentContainerMethodsCount);
\r
519 assertEquals(1, listChildContainerMethodsCount);
\r
520 assertEquals(1, getSimpleListKeyMethodCount);
\r
521 assertEquals(1, listKeyClassCount);
\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
534 assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
\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
544 assertEquals(5, simpleListMethodsCount);
\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
552 assertNotNull(context);
\r
554 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
555 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
557 assertNotNull(genTypes);
\r
558 assertEquals(7, genTypes.size());
\r
560 int genTypesCount = 0;
\r
561 int genTOsCount = 0;
\r
563 int compositeKeyListKeyPropertyCount = 0;
\r
564 int compositeKeyListKeyCount = 0;
\r
565 int innerListKeyPropertyCount = 0;
\r
567 for (final Type type : genTypes) {
\r
568 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
\r
570 } else if (type instanceof GeneratedTransferObject) {
\r
571 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
\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
584 } else if (genTO.getName().equals("InnerListKey")) {
\r
585 final List<GeneratedProperty> properties = genTO.getProperties();
\r
586 innerListKeyPropertyCount = properties.size();
\r
591 assertEquals(1, compositeKeyListKeyCount);
\r
592 assertEquals(2, compositeKeyListKeyPropertyCount);
\r
594 assertEquals(1, innerListKeyPropertyCount);
\r
596 assertEquals(5, genTypesCount);
\r
597 assertEquals(2, genTOsCount);
\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
606 final BindingGenerator bindingGen = new BindingGeneratorImpl();
\r
607 final List<Type> genTypes = bindingGen.generateTypes(context);
\r
609 assertNotNull(genTypes);
\r
610 assertEquals(14, genTypes.size());
\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
617 } else if (type instanceof GeneratedTransferObject) {
\r
622 assertEquals(11, genTypesCount);
\r
623 assertEquals(3, genTOsCount);
\r