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.yangtools.sal.java.api.generator.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.*;
15 import java.lang.annotation.Annotation;
16 import java.lang.reflect.Field;
17 import java.lang.reflect.Method;
18 import java.lang.reflect.ParameterizedType;
19 import java.lang.reflect.WildcardType;
20 import java.math.BigDecimal;
21 import java.math.BigInteger;
23 import java.net.URLClassLoader;
24 import java.util.ArrayList;
25 import java.util.HashSet;
26 import java.util.List;
29 import org.junit.Test;
30 import org.opendaylight.yangtools.sal.binding.model.api.Type;
31 import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile;
32 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
33 import org.opendaylight.yangtools.yang.model.api.Module;
34 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
36 import com.google.common.collect.Range;
39 * Test correct code generation.
42 public class CompilationTest extends BaseCompilationTest {
45 public void testListGeneration() throws Exception {
46 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "list-gen");
47 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
48 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "list-gen");
49 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
51 generateTestSources("/compilation/list-gen", sourcesOutputDir);
53 // Test if all sources are generated
54 File parent = new File(sourcesOutputDir, NS_TEST);
55 File keyArgs = new File(parent, "KeyArgs.java");
56 File links = new File(parent, "Links.java");
57 File linksBuilder = new File(parent, "LinksBuilder.java");
58 File linksKey = new File(parent, "LinksKey.java");
59 File testData = new File(parent, "TestData.java");
60 assertTrue(keyArgs.exists());
61 assertTrue(links.exists());
62 assertTrue(linksBuilder.exists());
63 assertTrue(linksKey.exists());
64 assertTrue(testData.exists());
65 assertFilesCount(parent, 6);
67 parent = new File(sourcesOutputDir, NS_TEST + FS + "links");
68 File level = new File(parent, "Level.java");
69 File linkGroup = new File(parent, "LinkGroup.java");
70 File node = new File(parent, "Node.java");
71 File nodeBuilder = new File(parent, "NodeBuilder.java");
72 File nodeList = new File(parent, "NodeList.java");
73 File nodeListBuilder = new File(parent, "NodeListBuilder.java");
74 File nodesType = new File(parent, "NodesType.java");
75 assertTrue(level.exists());
76 assertTrue(linkGroup.exists());
77 assertTrue(node.exists());
78 assertTrue(nodeBuilder.exists());
79 assertTrue(nodeList.exists());
80 assertTrue(nodeListBuilder.exists());
81 assertTrue(nodesType.exists());
82 assertFilesCount(parent, 7);
84 // Test if sources are compilable
85 testCompilation(sourcesOutputDir, compiledOutputDir);
87 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
88 Class<?> keyArgsClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader);
89 Class<?> linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader);
90 Class<?> linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader);
92 // Test generated 'grouping key-args'
93 assertTrue(keyArgsClass.isInterface());
94 assertEquals(2, keyArgsClass.getDeclaredMethods().length);
95 assertContainsMethod(keyArgsClass, String.class, "getName");
96 assertContainsMethod(keyArgsClass, Integer.class, "getSize");
98 // Test generated 'list links'
99 assertTrue(linksClass.isInterface());
101 assertEquals(6, linksClass.getDeclaredMethods().length);
102 assertImplementsIfc(linksClass, keyArgsClass);
104 // Test list key constructor arguments ordering
105 assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);
106 // Test serialVersionUID generation
107 Field suid = assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE);
108 suid.setAccessible(true);
109 assertEquals(-8829501012356283881L, suid.getLong(null));
111 cleanUp(sourcesOutputDir, compiledOutputDir);
115 public void testAugmentUnderUsesGeneration() throws Exception {
116 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-under-uses");
117 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
118 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-under-uses");
119 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
121 generateTestSources("/compilation/augment-under-uses", sourcesOutputDir);
123 // Test if all sources were generated from 'module foo'
124 File parent = new File(sourcesOutputDir, NS_FOO);
125 assertTrue(new File(parent, "Object.java").exists());
126 assertTrue(new File(parent, "ClosedObject.java").exists());
127 assertTrue(new File(parent, "OpenObject.java").exists());
128 assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
129 assertTrue(new File(parent, "PathKeySubobject.java").exists());
130 assertFilesCount(parent, 9);
132 parent = new File(parent, "object");
133 assertTrue(new File(parent, "Nodes.java").exists());
134 assertTrue(new File(parent, "NodesBuilder.java").exists());
135 assertFilesCount(parent, 2);
137 parent = new File(sourcesOutputDir, NS_FOO + FS + "closed");
138 assertFilesCount(parent, 1);
140 parent = new File(parent, "object");
141 assertTrue(new File(parent, "Link1.java").exists());
142 assertTrue(new File(parent, "Link1Builder.java").exists());
143 assertFilesCount(parent, 2);
145 parent = new File(sourcesOutputDir, NS_FOO + FS + "open");
146 assertFilesCount(parent, 1);
148 parent = new File(parent, "object");
149 assertTrue(new File(parent, "Nodes1.java").exists());
150 assertTrue(new File(parent, "Nodes1Builder.java").exists());
151 assertFilesCount(parent, 3);
153 parent = new File(parent, "nodes");
154 assertTrue(new File(parent, "Links.java").exists());
155 assertTrue(new File(parent, "LinksBuilder.java").exists());
156 assertFilesCount(parent, 2);
158 parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit");
159 assertFilesCount(parent, 1);
160 parent = new File(parent, "route");
161 assertFilesCount(parent, 1);
162 parent = new File(parent, "object");
163 assertTrue(new File(parent, "Subobjects.java").exists());
164 assertTrue(new File(parent, "SubobjectsBuilder.java").exists());
165 assertFilesCount(parent, 3);
167 parent = new File(parent, "subobjects");
168 assertFilesCount(parent, 1);
169 parent = new File(parent, "subobject");
170 assertFilesCount(parent, 1);
171 parent = new File(parent, "type");
172 assertTrue(new File(parent, "PathKey.java").exists());
173 assertTrue(new File(parent, "PathKeyBuilder.java").exists());
174 assertFilesCount(parent, 3);
176 parent = new File(parent, "path");
177 assertFilesCount(parent, 1);
178 parent = new File(parent, "key");
179 assertTrue(new File(parent, "PathKey.java").exists());
180 assertTrue(new File(parent, "PathKeyBuilder.java").exists());
181 assertFilesCount(parent, 2);
183 // Test if all sources were generated from 'module bar'
184 parent = new File(sourcesOutputDir, NS_BAR);
185 assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
186 assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
187 assertTrue(new File(parent, "RouteSubobjects.java").exists());
188 assertFilesCount(parent, 5);
190 parent = new File(parent, "route");
191 assertFilesCount(parent, 1);
192 parent = new File(new File(sourcesOutputDir, NS_BAR), "basic");
193 assertFilesCount(parent, 1);
194 parent = new File(parent, "explicit");
195 assertFilesCount(parent, 1);
196 parent = new File(parent, "route");
197 assertFilesCount(parent, 1);
199 parent = new File(parent, "subobjects");
200 assertFilesCount(parent, 2);
201 assertTrue(new File(parent, "SubobjectType.java").exists());
203 parent = new File(parent, "subobject");
204 assertFilesCount(parent, 1);
206 parent = new File(parent, "type");
207 assertTrue(new File(parent, "IpPrefix.java").exists());
208 assertTrue(new File(parent, "IpPrefixBuilder.java").exists());
209 assertTrue(new File(parent, "Label.java").exists());
210 assertTrue(new File(parent, "LabelBuilder.java").exists());
211 assertFilesCount(parent, 4);
213 // Test if sources are compilable
214 testCompilation(sourcesOutputDir, compiledOutputDir);
216 cleanUp(sourcesOutputDir, compiledOutputDir);
220 public void testAugmentOfAugmentGeneration() throws Exception {
221 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "aug-of-aug");
222 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
223 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "aug-of-aug");
224 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
226 generateTestSources("/compilation/augment-of-augment", sourcesOutputDir);
228 // Test if all sources were generated from 'module foo'
229 File parent = new File(sourcesOutputDir, NS_FOO);
230 File fooListener = new File(parent, "FooListener.java");
231 File pathAttributes = new File(parent, "PathAttributes.java");
232 File update = new File(parent, "Update.java");
233 File updateBuilder = new File(parent, "UpdateBuilder.java");
234 assertTrue(fooListener.exists());
235 assertTrue(pathAttributes.exists());
236 assertTrue(update.exists());
237 assertTrue(updateBuilder.exists());
238 assertFilesCount(parent, 6);
240 parent = new File(sourcesOutputDir, NS_FOO + FS + "path");
241 assertFilesCount(parent, 1);
242 parent = new File(parent, "attributes");
243 assertFilesCount(parent, 2);
244 File origin = new File(parent, "Origin.java");
245 File originBuilder = new File(parent, "OriginBuilder.java");
246 assertTrue(origin.exists());
247 assertTrue(originBuilder.exists());
249 parent = new File(sourcesOutputDir, NS_FOO + FS + "update");
250 assertFilesCount(parent, 2);
251 pathAttributes = new File(parent, "PathAttributes.java");
252 File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java");
253 assertTrue(pathAttributes.exists());
254 assertTrue(pathAttributesBuilder.exists());
256 // Test if all sources were generated from 'module bar'
257 parent = new File(sourcesOutputDir, NS_BAR);
258 File destination = new File(parent, "Destination.java");
259 File pathAttributes1 = new File(parent, "PathAttributes1.java");
260 File pathAttributes1Builder = new File(parent, "PathAttributes1Builder.java");
261 assertTrue(destination.exists());
262 assertTrue(pathAttributes1.exists());
263 assertTrue(pathAttributes1Builder.exists());
264 assertFilesCount(parent, 5);
266 parent = new File(sourcesOutputDir, NS_BAR + FS + "destination");
267 assertFilesCount(parent, 2);
268 File destinationType = new File(parent, "DestinationType.java");
269 assertTrue(destinationType.exists());
271 parent = new File(parent, "destination");
272 assertFilesCount(parent, 1);
273 parent = new File(parent, "type");
274 assertFilesCount(parent, 2);
275 File destinationIpv4 = new File(parent, "DestinationIp.java");
276 File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java");
277 assertTrue(destinationIpv4.exists());
278 assertTrue(destinationIpv4Builder.exists());
280 parent = new File(sourcesOutputDir, NS_BAR + FS + "update");
281 assertFilesCount(parent, 1);
282 parent = new File(parent, "path");
283 assertFilesCount(parent, 1);
284 parent = new File(parent, "attributes");
285 File mpUnreachNlri = new File(parent, "MpUnreachNlri.java");
286 File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java");
287 assertTrue(mpUnreachNlri.exists());
288 assertTrue(mpUnreachNlriBuilder.exists());
289 assertFilesCount(parent, 3);
291 parent = new File(parent, "mp");
292 assertFilesCount(parent, 1);
293 parent = new File(parent, "unreach");
294 assertFilesCount(parent, 1);
295 parent = new File(parent, "nlri");
296 File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java");
297 File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java");
298 assertTrue(withdrawnRoutes.exists());
299 assertTrue(withdrawnRoutesBuilder.exists());
300 assertFilesCount(parent, 2);
302 // Test if all sources were generated from 'module baz'
303 parent = new File(sourcesOutputDir, NS_BAZ);
304 assertFilesCount(parent, 2);
305 File linkstateDestination = new File(parent, "LinkstateDestination.java");
306 assertTrue(linkstateDestination.exists());
308 parent = new File(sourcesOutputDir, NS_BAZ + FS + "update");
309 assertFilesCount(parent, 1);
310 parent = new File(parent, "path");
311 assertFilesCount(parent, 1);
312 parent = new File(parent, "attributes");
313 assertFilesCount(parent, 1);
314 parent = new File(parent, "mp");
315 assertFilesCount(parent, 1);
316 parent = new File(parent, "unreach");
317 assertFilesCount(parent, 1);
318 parent = new File(parent, "nlri");
319 assertFilesCount(parent, 1);
320 parent = new File(parent, "withdrawn");
321 assertFilesCount(parent, 1);
322 parent = new File(parent, "routes");
323 assertFilesCount(parent, 1);
324 parent = new File(parent, "destination");
325 assertFilesCount(parent, 1);
326 parent = new File(parent, "type");
327 File destinationLinkstate = new File(parent, "DestinationLinkstate.java");
328 File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java");
329 assertTrue(destinationLinkstate.exists());
330 assertTrue(destinationLinkstateBuilder.exists());
331 assertFilesCount(parent, 3);
332 parent = new File(parent, "destination");
333 assertFilesCount(parent, 1);
334 parent = new File(parent, "linkstate");
335 File links = new File(parent, "Links.java");
336 File linksBuilder = new File(parent, "LinksBuilder.java");
337 assertTrue(links.exists());
338 assertTrue(linksBuilder.exists());
339 assertFilesCount(parent, 3);
340 parent = new File(parent, "links");
341 File source = new File(parent, "Source.java");
342 File sourceBuilder = new File(parent, "SourceBuilder.java");
343 assertTrue(source.exists());
344 assertTrue(sourceBuilder.exists());
345 assertFilesCount(parent, 3);
346 parent = new File(parent, "source");
347 File address = new File(parent, "Address.java");
348 File addressBuilder = new File(parent, "AddressBuilder.java");
349 assertTrue(address.exists());
350 assertTrue(addressBuilder.exists());
351 assertFilesCount(parent, 2);
353 // Test if sources are compilable
354 testCompilation(sourcesOutputDir, compiledOutputDir);
356 cleanUp(sourcesOutputDir, compiledOutputDir);
360 public void testLeafReturnTypes() throws Exception {
361 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "leaf-return-types");
362 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
363 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "leaf-return-types");
364 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
366 generateTestSources("/compilation/leaf-return-types", sourcesOutputDir);
368 File parent = new File(sourcesOutputDir, NS_TEST);
369 assertTrue(new File(parent, "TestData.java").exists());
370 assertTrue(new File(parent, "Nodes.java").exists());
371 assertTrue(new File(parent, "NodesBuilder.java").exists());
372 assertTrue(new File(parent, "Alg.java").exists());
373 assertTrue(new File(parent, "IdUnionBuilder.java").exists());
374 assertFilesCount(parent, 5);
376 // Test if sources are compilable
377 testCompilation(sourcesOutputDir, compiledOutputDir);
379 String pkg = BASE_PKG + ".urn.opendaylight.test.rev131008";
380 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
381 Class<?> nodesClass = Class.forName(pkg + ".Nodes", true, loader);
382 Class<?> builderClass = Class.forName(pkg + ".NodesBuilder", true, loader);
384 // Test methods return type
385 byte[] b = new byte[] {};
386 assertContainsMethod(nodesClass, b.getClass(), "getIdBinary");
387 assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader);
388 assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean");
389 assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64");
390 assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty");
391 assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader);
392 testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg");
393 testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier");
394 assertContainsMethod(nodesClass, Byte.class, "getId8");
395 assertContainsMethod(nodesClass, Short.class, "getId16");
396 assertContainsMethod(nodesClass, Integer.class, "getId32");
397 assertContainsMethod(nodesClass, Long.class, "getId64");
398 assertContainsMethod(nodesClass, Long.class, "getIdLeafref");
399 assertContainsMethod(nodesClass, String.class, "getIdString");
400 assertContainsMethod(nodesClass, Short.class, "getIdU8");
401 assertContainsMethod(nodesClass, Integer.class, "getIdU16");
402 assertContainsMethod(nodesClass, Long.class, "getIdU32");
403 assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
404 assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
406 Object builderObj = builderClass.newInstance();
408 Method m = assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass());
409 List<Range<Integer>> lengthConstraints = new ArrayList<>();
410 lengthConstraints.add(Range.closed(1, 10));
411 Object arg = new byte[] {};
412 String expectedMsg = String.format("Invalid length: {}, expected: {}.", arg, lengthConstraints);
413 assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
415 m = assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class);
416 List<Range<BigDecimal>> rangeConstraints = new ArrayList<>();
417 rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5")));
418 arg = new BigDecimal("1.4");
419 expectedMsg = String.format("Invalid range: %s, expected: %s.", arg, rangeConstraints);
420 assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
422 cleanUp(sourcesOutputDir, compiledOutputDir);
426 public void testGenerationContextReferenceExtension() throws Exception {
427 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "context-reference");
428 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
429 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "context-reference");
430 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
432 generateTestSources("/compilation/context-reference", sourcesOutputDir);
434 // Test if all sources are generated
435 File fooParent = new File(sourcesOutputDir, NS_FOO);
436 assertFilesCount(fooParent, 3);
437 assertTrue(new File(fooParent, "FooData.java").exists());
438 assertTrue(new File(fooParent, "Nodes.java").exists());
439 assertTrue(new File(fooParent, "NodesBuilder.java").exists());
441 File barParent = new File(sourcesOutputDir, NS_BAR);
442 assertFilesCount(barParent, 1);
443 assertTrue(new File(barParent, "IdentityClass.java").exists());
445 // Test if sources are compilable
446 testCompilation(sourcesOutputDir, compiledOutputDir);
448 ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
449 Class<?> nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader);
450 Class<?> identityClass = Class
451 .forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader);
455 identityClass.getConstructor();
456 Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true, loader);
457 assertEquals(baseIdentity, identityClass.getSuperclass());
458 } catch (NoSuchMethodException e) {
459 throw new AssertionError("IdentityClass must have no-arg constructor");
464 Method getId = nodesClass.getMethod("getId");
465 Annotation[] annotations = getId.getAnnotations();
466 assertEquals(1, annotations.length);
467 Annotation routingContext = annotations[0];
468 assertEquals(RoutingContext.class, routingContext.annotationType());
469 } catch (NoSuchMethodException e) {
470 throw new AssertionError("Method getId() not found");
473 cleanUp(sourcesOutputDir, compiledOutputDir);
477 public void compilationTest() throws Exception {
478 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang");
479 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
480 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang");
481 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
483 generateTestSources("/yang", sourcesOutputDir);
485 // Test if sources are compilable
486 testCompilation(sourcesOutputDir, compiledOutputDir);
488 cleanUp(sourcesOutputDir, compiledOutputDir);
492 public void bug586Test() throws Exception {
493 final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug586");
494 assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
495 final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug586");
496 assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
498 generateTestSources("/compilation/bug586", sourcesOutputDir);
500 // Test if sources are compilable
501 testCompilation(sourcesOutputDir, compiledOutputDir);
503 cleanUp(sourcesOutputDir, compiledOutputDir);
506 private void generateTestSources(String resourceDirPath, File sourcesOutputDir) throws Exception {
507 final List<File> sourceFiles = getSourceFiles(resourceDirPath);
508 final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
509 final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
510 final List<Type> types = bindingGenerator.generateTypes(context);
511 final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
512 generator.generateToFile(sourcesOutputDir);
515 private void testReturnTypeIdentityref(Class<?> clazz, String methodName, String returnTypeStr) throws Exception {
517 java.lang.reflect.Type returnType;
519 method = clazz.getMethod(methodName);
520 assertEquals(java.lang.Class.class, method.getReturnType());
521 returnType = method.getGenericReturnType();
522 assertTrue(returnType instanceof ParameterizedType);
523 ParameterizedType pt = (ParameterizedType) returnType;
524 java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
525 assertEquals(1, parameters.length);
526 java.lang.reflect.Type parameter = parameters[0];
527 assertTrue(parameter instanceof WildcardType);
528 WildcardType wildcardType = (WildcardType) parameter;
529 assertEquals("? extends " + returnTypeStr, wildcardType.toString());
530 } catch (NoSuchMethodException e) {
531 throw new AssertionError("Method '" + methodName + "' not found");
535 private void testReturnTypeInstanceIdentitifer(ClassLoader loader, Class<?> clazz, String methodName)
538 Class<?> rawReturnType;
539 java.lang.reflect.Type returnType;
541 method = clazz.getMethod(methodName);
542 rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true, loader);
543 assertEquals(rawReturnType, method.getReturnType());
544 returnType = method.getGenericReturnType();
545 assertTrue(returnType instanceof ParameterizedType);
546 ParameterizedType pt = (ParameterizedType) returnType;
547 java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
548 assertEquals(1, parameters.length);
549 java.lang.reflect.Type parameter = parameters[0];
550 assertTrue(parameter instanceof WildcardType);
551 WildcardType wildcardType = (WildcardType) parameter;
552 assertEquals("?", wildcardType.toString());
553 } catch (NoSuchMethodException e) {
554 throw new AssertionError("Method '" + methodName + "' not found");