Binding generator v2 - namespace fix #1
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / test / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / AugmentToGenTypeTest.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.javav2.generator.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17 import com.google.common.base.Optional;
18 import java.lang.reflect.Constructor;
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
31 import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
32 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
33 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
34 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
35 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentable;
36 import org.opendaylight.mdsal.binding.javav2.spec.structural.Augmentation;
37 import org.opendaylight.yangtools.yang.common.QName;
38 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
39 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
40 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
41 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
42 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
43 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
44 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
45 import org.opendaylight.yangtools.yang.model.api.Module;
46 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
47 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
48 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
49 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
50 import org.opendaylight.yangtools.yang.model.api.UsesNode;
51 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
52
53 public class AugmentToGenTypeTest {
54
55     @SuppressWarnings("unchecked")
56     @Test(expected = UnsupportedOperationException.class)
57     public void constructorTest() throws Throwable {
58         final Constructor<AugmentToGenType> constructor =
59                 (Constructor<AugmentToGenType>) AugmentToGenType.class.getDeclaredConstructors()[0];
60         constructor.setAccessible(true);
61         final Object[] objs = {};
62         try {
63             constructor.newInstance(objs);
64         } catch (final Exception e) {
65             throw e.getCause();
66         }
67     }
68
69     @SuppressWarnings("rawtypes")
70     @Test
71     public void generateNullModuleTest() throws Exception {
72         final Class[] parameterTypes =
73                 { Module.class, SchemaContext.class, TypeProvider.class, Map.class, Map.class, boolean.class };
74         final Method generate = AugmentToGenType.class.getDeclaredMethod("generate", parameterTypes);
75         assertNotNull(generate);
76         generate.setAccessible(true);
77
78         final SchemaContext context = null;
79         final TypeProvider typeProvider = null;
80         final Map<Module, ModuleContext> genCtx = new HashMap<>();
81         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
82         final Module m = null;
83
84         final Object[] args = { m, context, typeProvider, genCtx, genTypeBuilders, false };
85         try {
86             generate.invoke(AugmentToGenType.class, args);
87             fail();
88         } catch (final Exception e) {
89             assertNotNull(e);
90             assertTrue(e instanceof InvocationTargetException);
91             final Throwable cause = e.getCause();
92             assertNotNull(cause);
93             assertTrue(cause instanceof IllegalArgumentException);
94             assertEquals("Module reference cannot be NULL.", cause.getMessage());
95         }
96     }
97
98     @SuppressWarnings("rawtypes")
99     @Test
100     public void generateNullModuleNameTest() throws Exception {
101         final Class[] parameterTypes =
102                 { Module.class, SchemaContext.class, TypeProvider.class, Map.class, Map.class, boolean.class };
103         final Method generate = AugmentToGenType.class.getDeclaredMethod("generate", parameterTypes);
104         assertNotNull(generate);
105         generate.setAccessible(true);
106
107         final SchemaContext context = null;
108         final TypeProvider typeProvider = null;
109         final Map<Module, ModuleContext> genCtx = new HashMap<>();
110         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
111         final Module m = mock(Module.class);
112         when(m.getName()).thenReturn(null);
113
114         final Object[] args = { m, context, typeProvider, genCtx, genTypeBuilders, false };
115         try {
116             generate.invoke(AugmentToGenType.class, args);
117             fail();
118         } catch (final Exception e) {
119             assertNotNull(e);
120             assertTrue(e instanceof InvocationTargetException);
121             final Throwable cause = e.getCause();
122             assertNotNull(cause);
123             assertTrue(cause instanceof IllegalArgumentException);
124             assertEquals("Module name cannot be NULL.", cause.getMessage());
125         }
126     }
127
128     @SuppressWarnings("rawtypes")
129     @Test
130     public void generateNullModuleAugmentationsTest() throws Exception {
131         final Class[] parameterTypes =
132                 { Module.class, SchemaContext.class, TypeProvider.class, Map.class, Map.class, boolean.class };
133         final Method generate = AugmentToGenType.class.getDeclaredMethod("generate", parameterTypes);
134         assertNotNull(generate);
135         generate.setAccessible(true);
136
137         final SchemaContext context = null;
138         final TypeProvider typeProvider = null;
139         final Map<Module, ModuleContext> genCtx = new HashMap<>();
140         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
141         final Module m = mock(Module.class);
142         when(m.getName()).thenReturn("name");
143         when(m.getAugmentations()).thenReturn(null);
144
145         final Object[] args = { m, context, typeProvider, genCtx, genTypeBuilders, false };
146         try {
147             generate.invoke(AugmentToGenType.class, args);
148             fail();
149         } catch (final Exception e) {
150             assertNotNull(e);
151             assertTrue(e instanceof InvocationTargetException);
152             final Throwable cause = e.getCause();
153             assertNotNull(cause);
154             assertTrue(cause instanceof IllegalStateException);
155             assertEquals("Augmentations Set cannot be NULL.", cause.getMessage());
156         }
157     }
158
159     @SuppressWarnings("rawtypes")
160     @Test
161     public void generateWithoutAugmentationsTest() throws Exception {
162         final Class[] parameterTypes =
163                 { Module.class, SchemaContext.class, TypeProvider.class, Map.class, Map.class, boolean.class };
164         final Method generate = AugmentToGenType.class.getDeclaredMethod("generate", parameterTypes);
165         assertNotNull(generate);
166         generate.setAccessible(true);
167
168         final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test.yang");
169         final TypeProvider typeProvider = new TypeProviderImpl(context);
170         final Map<Module, ModuleContext> genCtx = new HashMap<>();
171         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
172
173         final Object[] args =
174                 { context.getModules().iterator().next(), context, typeProvider, genCtx, genTypeBuilders, false };
175         final Map invoke = (Map) generate.invoke(AugmentToGenType.class, args);
176         assertNotNull(invoke);
177     }
178
179     @SuppressWarnings({ "rawtypes", "unchecked" })
180     @Test
181     public void generateWithAugmentationsTest() throws Exception {
182         final Class[] parameterTypes =
183                 { Module.class, SchemaContext.class, TypeProvider.class, Map.class, Map.class, boolean.class };
184         final Method generate = AugmentToGenType.class.getDeclaredMethod("generate", parameterTypes);
185         assertNotNull(generate);
186         generate.setAccessible(true);
187
188         final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test-augment.yang");
189         final TypeProvider typeProvider = new TypeProviderImpl(context);
190         final Map<Module, ModuleContext> genCtx = mock(Map.class);
191         final Collection<ModuleContext> moduleContexts = new ArrayList<>();
192         final ModuleContext moduleContext = new ModuleContext();
193         moduleContexts.add(moduleContext);
194         final QName create = QName.create("urn:test:simple:test", "2017-02-06", "my-cont");
195         final SchemaNode schemaNode = mock(SchemaNode.class);
196         when(schemaNode.getPath()).thenReturn(SchemaPath.create(true, create));
197         moduleContext.addChildNodeType(schemaNode, new GeneratedTypeBuilderImpl("test", "Test"));
198         when(genCtx.values()).thenReturn(moduleContexts);
199         when(genCtx.get(context.getModules().iterator().next())).thenReturn(moduleContext);
200         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
201
202         final Object[] args =
203                 { context.getModules().iterator().next(), context, typeProvider, genCtx, genTypeBuilders, false };
204         final Map invoke = (Map) generate.invoke(AugmentToGenType.class, args);
205         assertNotNull(invoke);
206     }
207
208     @SuppressWarnings("rawtypes")
209     @Test
210     public void resolveAugmentationsNullModuleTest() throws Exception {
211         final Class[] parameterTypes = { Module.class };
212         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
213         assertNotNull(generate);
214         generate.setAccessible(true);
215
216         final Module m = null;
217
218         final Object[] args = { m };
219         try {
220             generate.invoke(AugmentToGenType.class, args);
221             fail();
222         } catch (final Exception e) {
223             assertNotNull(e);
224             assertTrue(e instanceof InvocationTargetException);
225             final Throwable cause = e.getCause();
226             assertNotNull(cause);
227             assertTrue(cause instanceof IllegalArgumentException);
228             assertEquals("Module reference cannot be NULL.", cause.getMessage());
229         }
230     }
231
232     @SuppressWarnings("rawtypes")
233     @Test
234     public void resolveAugmentationsNullAugmentationsTest() throws Exception {
235         final Class[] parameterTypes = { Module.class };
236         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
237         assertNotNull(generate);
238         generate.setAccessible(true);
239
240         final Module m = mock(Module.class);
241         when(m.getAugmentations()).thenReturn(null);
242
243         final Object[] args = { m };
244         try {
245             generate.invoke(AugmentToGenType.class, args);
246             fail();
247         } catch (final Exception e) {
248             assertNotNull(e);
249             assertTrue(e instanceof InvocationTargetException);
250             final Throwable cause = e.getCause();
251             assertNotNull(cause);
252             assertTrue(cause instanceof IllegalStateException);
253             assertEquals("Augmentations Set cannot be NULL.", cause.getMessage());
254         }
255     }
256
257     @SuppressWarnings({ "rawtypes", "unchecked" })
258     @Test
259     public void resolveAugmentationsTest() throws Exception {
260         final Class[] parameterTypes = { Module.class };
261         final Method generate = AugmentToGenType.class.getDeclaredMethod("resolveAugmentations", parameterTypes);
262         assertNotNull(generate);
263         generate.setAccessible(true);
264
265         final Module m = mock(Module.class);
266
267         final Set<AugmentationSchema> augmentations = new HashSet<>();
268
269         final QName q1 = QName.create("q1", "2017-04-04", "q1");
270         final QName q2 = QName.create("q2", "2017-04-04", "q2");
271         final QName q3 = QName.create("q3", "2017-04-04", "q3");
272         final QName q4 = QName.create("q4", "2017-04-04", "q4");
273         final QName q5 = QName.create("q5", "2017-04-04", "q5");
274
275         final AugmentationSchema augmentationSchema1 = mock(AugmentationSchema.class);
276         when(augmentationSchema1.getTargetPath()).thenReturn(SchemaPath.create(true, q1, q2));
277         final AugmentationSchema augmentationSchema2 = mock(AugmentationSchema.class);
278         when(augmentationSchema2.getTargetPath()).thenReturn(SchemaPath.create(true, q3, q4, q5));
279         augmentations.add(augmentationSchema1);
280         augmentations.add(augmentationSchema2);
281
282         when(m.getAugmentations()).thenReturn(augmentations);
283
284         final Object[] args = { m };
285
286         final List<AugmentationSchema> result =
287                 (List<AugmentationSchema>) generate.invoke(AugmentToGenType.class, args);
288         assertNotNull(result);
289         assertTrue(!result.isEmpty());
290         assertEquals(result.get(0), augmentationSchema1);
291         assertEquals(result.get(1), augmentationSchema2);
292     }
293
294     @SuppressWarnings({ "rawtypes" })
295     @Test
296     public void augmentationToGenTypesNullPckgNameTest() throws Exception {
297         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
298                 boolean.class, Map.class, Map.class, TypeProvider.class };
299         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
300         assertNotNull(generate);
301         generate.setAccessible(true);
302
303         final String augmPackName = null;
304         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = null;
305         final SchemaContext context = null;
306         final TypeProvider typeProvider = null;
307         final Map<Module, ModuleContext> genCtx = new HashMap<>();
308         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
309         final Module m = null;
310
311         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
312         try {
313             generate.invoke(AugmentToGenType.class, args);
314             fail();
315         } catch (final Exception e) {
316             assertNotNull(e);
317             assertTrue(e instanceof InvocationTargetException);
318             final Throwable cause = e.getCause();
319             assertNotNull(cause);
320             assertTrue(cause instanceof IllegalArgumentException);
321             assertEquals("Package Name cannot be NULL.", cause.getMessage());
322         }
323     }
324
325     @SuppressWarnings({ "rawtypes" })
326     @Test
327     public void augmentationToGenTypesNullAugSchemaTest() throws Exception {
328         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
329                 boolean.class, Map.class, Map.class, TypeProvider.class };
330         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
331         assertNotNull(generate);
332         generate.setAccessible(true);
333
334         final String augmPackName = "pckg.name";
335         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = null;
336         final SchemaContext context = null;
337         final TypeProvider typeProvider = null;
338         final Map<Module, ModuleContext> genCtx = new HashMap<>();
339         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
340         final Module m = null;
341
342         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
343         try {
344             generate.invoke(AugmentToGenType.class, args);
345             fail();
346         } catch (final Exception e) {
347             assertNotNull(e);
348             assertTrue(e instanceof InvocationTargetException);
349             final Throwable cause = e.getCause();
350             assertNotNull(cause);
351             assertTrue(cause instanceof IllegalArgumentException);
352             assertEquals("Augmentation List Entry cannot be NULL.", cause.getMessage());
353         }
354     }
355
356     @SuppressWarnings({ "rawtypes" })
357     @Test
358     public void augmentationToGenTypesNullAugSchemaTargetPathTest() throws Exception {
359         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
360                 boolean.class, Map.class, Map.class, TypeProvider.class };
361         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
362         assertNotNull(generate);
363         generate.setAccessible(true);
364
365         final String augmPackName = "pckg.name";
366         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
367         when(augmSchema.getTargetPath()).thenReturn(null);
368
369         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
370         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
371         when(schemaPathAugmentListEntry.getKey()).thenReturn(null);
372         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
373
374         final SchemaContext context = null;
375         final TypeProvider typeProvider = null;
376         final Map<Module, ModuleContext> genCtx = new HashMap<>();
377         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
378         final Module m = null;
379
380         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
381         try {
382             generate.invoke(AugmentToGenType.class, args);
383             fail();
384         } catch (final Exception e) {
385             assertNotNull(e);
386             assertTrue(e instanceof InvocationTargetException);
387             final Throwable cause = e.getCause();
388             assertNotNull(cause);
389             assertTrue(cause instanceof IllegalStateException);
390             assertEquals("Augmentation List Entry does not contain Target Path (Target Path is NULL).", cause.getMessage());
391         }
392     }
393
394     @SuppressWarnings({ "rawtypes" })
395     @Test
396     public void augmentationToGenTypesNullAugSchemaListTest() throws Exception {
397         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
398                 boolean.class, Map.class, Map.class, TypeProvider.class };
399         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
400         assertNotNull(generate);
401         generate.setAccessible(true);
402
403         final String augmPackName = "pckg.name";
404         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
405         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
406         final SchemaPath path = SchemaPath.create(true, qnamePath);
407         when(augmSchema.getTargetPath()).thenReturn(path);
408
409         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
410         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
411         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
412         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
413
414         final SchemaContext context = null;
415         final TypeProvider typeProvider = null;
416         final Map<Module, ModuleContext> genCtx = new HashMap<>();
417         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
418         final Module m = null;
419
420         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
421         try {
422             generate.invoke(AugmentToGenType.class, args);
423             fail();
424         } catch (final Exception e) {
425             assertNotNull(e);
426             assertTrue(e instanceof InvocationTargetException);
427             final Throwable cause = e.getCause();
428             assertNotNull(cause);
429             assertTrue(cause instanceof IllegalStateException);
430             assertEquals("Augmentation List cannot be empty.", cause.getMessage());
431         }
432     }
433
434     @SuppressWarnings({ "rawtypes" })
435     @Test
436     public void augmentationToGenTypesNullAugSchemaTargetNodeTest() throws Exception {
437         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
438                 boolean.class, Map.class, Map.class, TypeProvider.class };
439         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
440         assertNotNull(generate);
441         generate.setAccessible(true);
442
443         final String augmPackName = "pckg.name";
444
445         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
446         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
447         final SchemaPath path = SchemaPath.create(true, qnamePath);
448         when(augmSchema.getTargetPath()).thenReturn(path);
449         final Set<UsesNode> uses = new HashSet<>();
450         when(augmSchema.getUses()).thenReturn(uses);
451
452         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
453         augmentationSchemaList.add(augmSchema);
454         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
455         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
456         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
457
458         final SchemaContext context = mock(SchemaContext.class);
459         final Module moduleAug = mock(Module.class);
460         final DataSchemaNode schNode = null;
461         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(schNode);
462         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
463                 .thenReturn(moduleAug);
464
465         final TypeProvider typeProvider = null;
466         final Map<Module, ModuleContext> genCtx = new HashMap<>();
467         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
468
469         final Module m = mock(Module.class);
470         when(m.getName()).thenReturn("augm-module");
471         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
472         when(m.getRevision()).thenReturn(qnamePath.getRevision());
473
474         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
475         try {
476             generate.invoke(AugmentToGenType.class, args);
477             fail();
478         } catch (final Exception e) {
479             assertNotNull(e);
480             assertTrue(e instanceof InvocationTargetException);
481             final Throwable cause = e.getCause();
482             assertNotNull(cause);
483             assertTrue(cause instanceof IllegalArgumentException);
484             assertEquals("augment target not found: " + path, cause.getMessage());
485         }
486     }
487
488     @SuppressWarnings({ "rawtypes" })
489     @Test
490     public void augmentationToGenTypesNullAugTargetGTBTest() throws Exception {
491         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
492                 boolean.class, Map.class, Map.class, TypeProvider.class };
493         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
494         assertNotNull(generate);
495         generate.setAccessible(true);
496
497         final String augmPackName = "pckg.name";
498
499         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
500         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
501         final SchemaPath path = SchemaPath.create(true, qnamePath);
502         when(augmSchema.getTargetPath()).thenReturn(path);
503         final Set<UsesNode> uses = new HashSet<>();
504         when(augmSchema.getUses()).thenReturn(uses);
505
506         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
507         augmentationSchemaList.add(augmSchema);
508         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
509         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
510         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
511
512         final SchemaContext context = mock(SchemaContext.class);
513         final Module moduleAug = mock(Module.class);
514         final DataSchemaNode schNode = mock(DataSchemaNode.class);
515         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(schNode);
516         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
517                 .thenReturn(moduleAug);
518
519         final TypeProvider typeProvider = null;
520         final Map<Module, ModuleContext> genCtx = new HashMap<>();
521         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
522
523         final Module m = mock(Module.class);
524         when(m.getName()).thenReturn("augm-module");
525         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
526         when(m.getRevision()).thenReturn(qnamePath.getRevision());
527
528         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
529         try {
530             generate.invoke(AugmentToGenType.class, args);
531             fail();
532         } catch (final Exception e) {
533             assertNotNull(e);
534             assertTrue(e instanceof InvocationTargetException);
535             final Throwable cause = e.getCause();
536             assertNotNull(cause);
537             assertTrue(cause instanceof NullPointerException);
538             assertEquals("Target type not yet generated: " + schNode, cause.getMessage());
539         }
540     }
541
542     @SuppressWarnings({ "rawtypes", "unchecked" })
543     @Test
544     public void augmentationToGenTypesAugUsesNullOrigTargetTest() throws Exception {
545         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
546                 boolean.class, Map.class, Map.class, TypeProvider.class };
547         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
548         assertNotNull(generate);
549         generate.setAccessible(true);
550
551         final String augmPackName = "pckg.name";
552
553         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
554         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
555         final SchemaPath path = SchemaPath.create(true, qnamePath);
556         when(augmSchema.getTargetPath()).thenReturn(path);
557         final Set<UsesNode> uses = new HashSet<>();
558         when(augmSchema.getUses()).thenReturn(uses);
559
560         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
561         augmentationSchemaList.add(augmSchema);
562         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
563         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
564         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
565
566         final SchemaContext context = mock(SchemaContext.class);
567         final Module moduleAug = mock(Module.class);
568         final DerivableSchemaNode targetSchNode = mock(DerivableSchemaNode.class);
569         when(targetSchNode.getPath()).thenReturn(path);
570         when(targetSchNode.isAddedByUses()).thenReturn(true);
571         final Optional optionalSchemaNode = Optional.absent();
572         when(targetSchNode.getOriginal()).thenReturn(optionalSchemaNode);
573         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(targetSchNode);
574         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
575                 .thenReturn(moduleAug);
576
577         final TypeProvider typeProvider = null;
578         final Map<Module, ModuleContext> genCtx = new HashMap<>();
579         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
580
581         final Module m = mock(Module.class);
582         when(m.getName()).thenReturn("augm-module");
583         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
584         when(m.getRevision()).thenReturn(qnamePath.getRevision());
585
586         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
587         try {
588             generate.invoke(AugmentToGenType.class, args);
589             fail();
590         } catch (final Exception e) {
591             assertNotNull(e);
592             assertTrue(e instanceof InvocationTargetException);
593             final Throwable cause = e.getCause();
594             assertNotNull(cause);
595             assertTrue(cause instanceof IllegalStateException);
596             assertEquals("Failed to find target node from grouping in augmentation " + augmSchema + " in module "
597                     + m.getName(), cause.getMessage());
598         }
599     }
600
601     @SuppressWarnings({ "rawtypes" })
602     @Test
603     public void augmentationToGenTypesTargetChoicSchemaNodeTest() throws Exception {
604         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
605                 boolean.class, Map.class, Map.class, TypeProvider.class };
606         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
607         assertNotNull(generate);
608         generate.setAccessible(true);
609
610         final String augmPackName = "pckg.name";
611
612         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
613         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
614         final SchemaPath path = SchemaPath.create(true, qnamePath);
615         when(augmSchema.getTargetPath()).thenReturn(path);
616         final Set<UsesNode> uses = new HashSet<>();
617         when(augmSchema.getUses()).thenReturn(uses);
618
619         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
620         augmentationSchemaList.add(augmSchema);
621         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
622         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
623         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
624
625         final SchemaContext context = mock(SchemaContext.class);
626         final Module moduleAug = mock(Module.class);
627         final ChoiceSchemaNode targetSchNode = mock(ChoiceSchemaNode.class);
628         when(targetSchNode.getPath()).thenReturn(path);
629         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(targetSchNode);
630         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
631                 .thenReturn(moduleAug);
632
633         final TypeProvider typeProvider = null;
634
635         final Map genCtx = mock(Map.class);
636         final Collection<ModuleContext> moduleContexts = new ArrayList<>();
637         final ModuleContext mc = new ModuleContext();
638         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(augmPackName, "augm");
639         mc.addChildNodeType(targetSchNode, gtb);
640         moduleContexts.add(mc);
641         when(genCtx.values()).thenReturn(moduleContexts);
642
643         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
644
645         final Module m = mock(Module.class);
646         when(m.getName()).thenReturn("augm-module");
647         when(m.getNamespace()).thenReturn(qnamePath.getNamespace());
648         when(m.getRevision()).thenReturn(qnamePath.getRevision());
649
650         final Object[] args = { augmPackName, schemaPathAugmentListEntry, m, context, false, genCtx, genTypeBuilders, typeProvider };
651         final Map result = (Map) generate.invoke(AugmentToGenType.class, args);
652         assertNotNull(result);
653     }
654
655     @SuppressWarnings({ "rawtypes", "unchecked" })
656     @Test
657     public void augmentationToGenTypesTest() throws Exception {
658         final Class[] parameterTypes = { String.class, Map.Entry.class, Module.class, SchemaContext.class,
659                 boolean.class, Map.class, Map.class, TypeProvider.class };
660         final Method generate = AugmentToGenType.class.getDeclaredMethod("augmentationToGenTypes", parameterTypes);
661         assertNotNull(generate);
662         generate.setAccessible(true);
663
664         final String augmPackName = "pckg.name";
665
666         final AugmentationSchema augmSchema = mock(AugmentationSchema.class);
667         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
668         final SchemaPath path = SchemaPath.create(true, qnamePath);
669         when(augmSchema.getTargetPath()).thenReturn(path);
670         final Set<UsesNode> uses = new HashSet<>();
671         when(augmSchema.getUses()).thenReturn(uses);
672         final List<UnknownSchemaNode> unknownSchemaNodes = new ArrayList<>();
673         when(augmSchema.getUnknownSchemaNodes()).thenReturn(unknownSchemaNodes);
674
675         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
676         augmentationSchemaList.add(augmSchema);
677         final Map.Entry<SchemaPath, List<AugmentationSchema>> schemaPathAugmentListEntry = mock(Map.Entry.class);
678         when(schemaPathAugmentListEntry.getKey()).thenReturn(path);
679         when(schemaPathAugmentListEntry.getValue()).thenReturn(augmentationSchemaList);
680
681         final SchemaContext context = mock(SchemaContext.class);
682         final Module moduleAug = mock(Module.class);
683         final DerivableSchemaNode targetSchNode = mock(DerivableSchemaNode.class);
684         when(targetSchNode.getPath()).thenReturn(path);
685         when(targetSchNode.isAddedByUses()).thenReturn(true);
686         final DataSchemaNode origSchNode = mock(DataSchemaNode.class);
687         when(origSchNode.getPath()).thenReturn(path);
688         when(origSchNode.isAddedByUses()).thenReturn(true);
689         final Optional optionalSchemaNode = Optional.of(origSchNode);
690         when(targetSchNode.getOriginal()).thenReturn(optionalSchemaNode);
691         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(targetSchNode);
692         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
693                 .thenReturn(moduleAug);
694
695         final TypeProvider typeProvider = null;
696
697         final Map<Module, ModuleContext> genCtx = new HashMap<>();
698
699         final Collection<ModuleContext> moduleContexts = new ArrayList<>();
700         final ModuleContext mc = new ModuleContext();
701         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(augmPackName, "augm");
702         mc.addChildNodeType(targetSchNode, gtb);
703         moduleContexts.add(mc);
704         genCtx.put(moduleAug, mc);
705
706         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
707
708         when(moduleAug.getName()).thenReturn("augm-module");
709         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
710         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
711
712         final Object[] args =
713                 { augmPackName, schemaPathAugmentListEntry, moduleAug, context, false, genCtx, genTypeBuilders, typeProvider };
714         final Map<Module, ModuleContext> result =
715                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
716         assertNotNull(result);
717         final ModuleContext moduleContext = result.get(moduleAug);
718         assertTrue(moduleContext.getAugmentations().get(0).getName().contains("Augm"));
719         assertEquals("pckg.name.data.aug", moduleContext.getAugmentations().get(0).getPackageName());
720         assertTrue(moduleContext.getChildNode(path).getName().contains("Augm"));
721         assertEquals("pckg.name", moduleContext.getChildNode(path).getPackageName());
722     }
723
724     @Test
725     public void usesAugmentationToGenTypesNullPckgNameTest() throws Exception {
726         try {
727             AugmentToGenType.usesAugmentationToGenTypes(null, null, null, null, null, null, null, null, false, null);
728         } catch (final Exception e) {
729             assertNotNull(e);
730             assertTrue(e instanceof IllegalArgumentException);
731             assertEquals(e.getMessage(), "Package Name cannot be NULL.");
732         }
733     }
734
735     @Test
736     public void usesAugmentationToGenTypesNullAugSchemaListEntryTest() throws Exception {
737         try {
738             AugmentToGenType.usesAugmentationToGenTypes(null, "", null, null, null, null, null, null, false, null);
739         } catch (final Exception e) {
740             assertNotNull(e);
741             assertTrue(e instanceof IllegalArgumentException);
742             assertEquals(e.getMessage(), "Augmentation Schema List Entry cannot be NULL.");
743         }
744     }
745
746     @Test
747     public void usesAugmentationToGenTypesEmptyAugSchemaListTest() throws Exception {
748         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
749         try {
750             AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
751                     false, null);
752         } catch (final Exception e) {
753             assertNotNull(e);
754             assertTrue(e instanceof IllegalStateException);
755             assertEquals(e.getMessage(), "Augmentation Schema List cannot be empty");
756         }
757     }
758
759     @Test
760     public void usesAugmentationToGenTypesNullAugSchemaNodeTargetPathTest() throws Exception {
761         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
762         when(augmentationSchema.getTargetPath()).thenReturn(null);
763         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
764         augmentationSchemaList.add(augmentationSchema);
765         try {
766             AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
767                     false, null);
768         } catch (final Exception e) {
769             assertNotNull(e);
770             assertTrue(e instanceof IllegalStateException);
771             assertEquals(e.getMessage(), "Augmentation Schema does not contain Target Path (Target Path is NULL).");
772         }
773     }
774
775     @Test
776     public void usesAugmentationToGenTypesNullAugmentTargetTest() throws Exception {
777         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
778         final SchemaPath path = SchemaPath.create(true, qnamePath);
779         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
780         when(augmentationSchema.getTargetPath()).thenReturn(path);
781         final Set<UsesNode> uses = new HashSet<>();
782         when(augmentationSchema.getUses()).thenReturn(uses);
783
784         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
785         augmentationSchemaList.add(augmentationSchema);
786
787         final SchemaContext context = mock(SchemaContext.class);
788         final Module moduleAug = mock(Module.class);
789         when(moduleAug.getName()).thenReturn("augm-module");
790         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
791         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
792         final Set<GroupingDefinition> groupings = new HashSet<>();
793         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
794         when(groupingDefinition.getQName()).thenReturn(qnamePath);
795         groupings.add(groupingDefinition);
796         when(moduleAug.getGroupings()).thenReturn(groupings);
797
798         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
799                 .thenReturn(moduleAug);
800
801         final Map<Module, ModuleContext> genCtx = new HashMap<>();
802         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
803
804
805         final UsesNode usesNode = mock(UsesNode.class);
806         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
807
808         when(usesNode.getGroupingPath()).thenReturn(path);
809
810         try {
811             AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
812                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
813         } catch (final Exception e) {
814             assertNotNull(e);
815             assertTrue(e instanceof IllegalArgumentException);
816             assertEquals(e.getMessage(), "augment target not found: " + path);
817         }
818     }
819
820     @Test
821     public void usesAugmentationToGenTypesNullTargetGTBTest() throws Exception {
822         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
823         final SchemaPath path = SchemaPath.create(true, qnamePath);
824         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
825         when(augmentationSchema.getTargetPath()).thenReturn(path);
826         final Set<UsesNode> uses = new HashSet<>();
827         when(augmentationSchema.getUses()).thenReturn(uses);
828
829         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
830         augmentationSchemaList.add(augmentationSchema);
831
832         final SchemaContext context = mock(SchemaContext.class);
833         final Module moduleAug = mock(Module.class);
834         when(moduleAug.getName()).thenReturn("augm-module");
835         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
836         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
837         final Set<GroupingDefinition> groupings = new HashSet<>();
838         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
839         when(groupingDefinition.getQName()).thenReturn(qnamePath);
840         final DataSchemaNode schNode = mock(DataSchemaNode.class);
841         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
842         groupings.add(groupingDefinition);
843         when(moduleAug.getGroupings()).thenReturn(groupings);
844
845         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
846                 .thenReturn(moduleAug);
847
848         final Map<Module, ModuleContext> genCtx = new HashMap<>();
849         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
850
851         final UsesNode usesNode = mock(UsesNode.class);
852         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
853
854         when(usesNode.getGroupingPath()).thenReturn(path);
855
856         try {
857             AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
858                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
859         } catch (final Exception e) {
860             assertNotNull(e);
861             assertTrue(e instanceof NullPointerException);
862             assertEquals(e.getMessage(), "Target type not yet generated: " + schNode);
863         }
864     }
865
866     @Test
867     public void usesAugmentationToGenTypesTest() throws Exception {
868         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
869         final SchemaPath path = SchemaPath.create(true, qnamePath);
870         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
871         when(augmentationSchema.getTargetPath()).thenReturn(path);
872         final Set<UsesNode> uses = new HashSet<>();
873         when(augmentationSchema.getUses()).thenReturn(uses);
874
875         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
876         augmentationSchemaList.add(augmentationSchema);
877
878         final SchemaContext context = mock(SchemaContext.class);
879         final Module moduleAug = mock(Module.class);
880         when(moduleAug.getName()).thenReturn("augm-module");
881         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
882         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
883         final Set<GroupingDefinition> groupings = new HashSet<>();
884         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
885         when(groupingDefinition.getQName()).thenReturn(qnamePath);
886         final DataSchemaNode schNode = mock(DataSchemaNode.class);
887         when(schNode.getPath()).thenReturn(path);
888         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
889         groupings.add(groupingDefinition);
890         when(moduleAug.getGroupings()).thenReturn(groupings);
891
892         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
893                 .thenReturn(moduleAug);
894
895         final Map<Module, ModuleContext> genCtx = new HashMap<>();
896         final ModuleContext mc = new ModuleContext();
897         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl("pckg.test.augm", "GtbAugm");
898         mc.addChildNodeType(schNode, gtb);
899         genCtx.put(moduleAug, mc);
900
901         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
902
903         final UsesNode usesNode = mock(UsesNode.class);
904         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
905
906         when(usesNode.getGroupingPath()).thenReturn(path);
907
908         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
909                 augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
910         assertNotNull(result);
911     }
912
913     @Test
914     public void usesAugmentationToGenTypesChoiceTest() throws Exception {
915         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
916         final SchemaPath path = SchemaPath.create(true, qnamePath);
917         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
918         when(augmentationSchema.getTargetPath()).thenReturn(path);
919         final Set<UsesNode> uses = new HashSet<>();
920         when(augmentationSchema.getUses()).thenReturn(uses);
921
922         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
923         augmentationSchemaList.add(augmentationSchema);
924
925         final SchemaContext context = mock(SchemaContext.class);
926         final Module moduleAug = mock(Module.class);
927         when(moduleAug.getName()).thenReturn("augm-module");
928         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
929         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
930         final Set<GroupingDefinition> groupings = new HashSet<>();
931         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
932         when(groupingDefinition.getQName()).thenReturn(qnamePath);
933         final ChoiceSchemaNode schNode = mock(ChoiceSchemaNode.class);
934         when(schNode.getPath()).thenReturn(path);
935         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
936         groupings.add(groupingDefinition);
937         when(moduleAug.getGroupings()).thenReturn(groupings);
938
939         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
940                 .thenReturn(moduleAug);
941
942         final Map<Module, ModuleContext> genCtx = new HashMap<>();
943         final ModuleContext mc = new ModuleContext();
944         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl("pckg.test.augm", "GtbAugm");
945         mc.addChildNodeType(schNode, gtb);
946         genCtx.put(moduleAug, mc);
947
948         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
949
950         final UsesNode usesNode = mock(UsesNode.class);
951         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
952
953         when(usesNode.getGroupingPath()).thenReturn(path);
954
955         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
956                 augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null);
957         assertNotNull(result);
958     }
959
960     @SuppressWarnings({ "rawtypes" })
961     @Test
962     public void findOriginalTargetFromGroupingNonGroupingTest() throws Exception {
963         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
964         final Method generate =
965                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
966         assertNotNull(generate);
967         generate.setAccessible(true);
968
969         final Module module = mock(Module.class);
970         final QName qnamePath = QName.create("test", "2017-04-04", "test");
971         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
972         final DataSchemaNode schNode = mock(DataSchemaNode.class);
973         when(schNode.getPath()).thenReturn(schemaPath);
974         when(module.getDataChildByName(qnamePath)).thenReturn(schNode);
975
976         final SchemaContext context = mock(SchemaContext.class);
977         when(context.findModuleByNamespaceAndRevision(qnamePath .getNamespace(), qnamePath.getRevision()))
978                 .thenReturn(module);
979         final UsesNode usesNode = mock(UsesNode.class);
980         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
981
982         final Object[] args = { context, schemaPath, usesNode };
983         try {
984             generate.invoke(AugmentToGenType.class, args);
985             fail();
986         } catch (final Exception e) {
987             assertNotNull(e);
988             assertTrue(e instanceof InvocationTargetException);
989             final Throwable cause = e.getCause();
990             assertNotNull(cause);
991             assertTrue(cause instanceof IllegalArgumentException);
992             assertEquals("Failed to generate code for augment in " + usesNode, cause.getMessage());
993         }
994     }
995
996     @SuppressWarnings({ "rawtypes" })
997     @Test
998     public void findOriginalTargetFromGroupingAsUsesFailedTest() throws Exception {
999         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1000         final Method generate =
1001                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1002         assertNotNull(generate);
1003         generate.setAccessible(true);
1004
1005         final Module module = mock(Module.class);
1006         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1007         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1008         final DataSchemaNode schNode = mock(DataSchemaNode.class);
1009         when(schNode.getPath()).thenReturn(schemaPath);
1010         when(schNode.isAddedByUses()).thenReturn(true);
1011         final Set<GroupingDefinition> groupings = new HashSet<>();
1012         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1013         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1014         groupings.add(groupingDefinition);
1015         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1016         when(module.getGroupings()).thenReturn(groupings);
1017
1018         final SchemaContext context = mock(SchemaContext.class);
1019         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1020                 .thenReturn(module);
1021         final UsesNode usesNode = mock(UsesNode.class);
1022         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1023
1024         final Object[] args = { context, schemaPath, usesNode };
1025         try {
1026             generate.invoke(AugmentToGenType.class, args);
1027             fail();
1028         } catch (final Exception e) {
1029             assertNotNull(e);
1030             assertTrue(e instanceof InvocationTargetException);
1031             final Throwable cause = e.getCause();
1032             assertNotNull(cause);
1033             assertTrue(cause instanceof IllegalStateException);
1034             assertEquals("Failed to generate code for augment in " + usesNode, cause.getMessage());
1035         }
1036     }
1037
1038     @SuppressWarnings({ "rawtypes" })
1039     @Test
1040     public void findOriginalTargetFromGroupingReturnNullTest() throws Exception {
1041         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1042         final Method generate =
1043                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1044         assertNotNull(generate);
1045         generate.setAccessible(true);
1046
1047         final Module module = mock(Module.class);
1048         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1049         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1050         final DataSchemaNode schNode = null;
1051         final Set<GroupingDefinition> groupings = new HashSet<>();
1052         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1053         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1054         groupings.add(groupingDefinition);
1055         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1056         when(module.getGroupings()).thenReturn(groupings);
1057
1058         final SchemaContext context = mock(SchemaContext.class);
1059         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1060                 .thenReturn(module);
1061         final UsesNode usesNode = mock(UsesNode.class);
1062         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1063
1064         final Object[] args = { context, schemaPath, usesNode };
1065         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1066         assertEquals(null, result);
1067     }
1068
1069     @SuppressWarnings({ "rawtypes", "unchecked" })
1070     @Test
1071     public void findOriginalTargetFromGroupingTest() throws Exception {
1072         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1073         final Method generate =
1074                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1075         assertNotNull(generate);
1076         generate.setAccessible(true);
1077
1078         final Module module = mock(Module.class);
1079         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1080         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1081         final DataSchemaNode schNode = mock(DataSchemaNode.class);
1082         when(schNode.getPath()).thenReturn(schemaPath);
1083         final Set<GroupingDefinition> groupings = new HashSet<>();
1084         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1085         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1086         groupings.add(groupingDefinition);
1087         final DerivableSchemaNode derivSchNode = mock(DerivableSchemaNode.class);
1088         when(derivSchNode.isAddedByUses()).thenReturn(true);
1089         final Optional optional = Optional.of(schNode);
1090         when(derivSchNode.getOriginal()).thenReturn(optional);
1091         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(derivSchNode);
1092         when(module.getGroupings()).thenReturn(groupings);
1093
1094         final SchemaContext context = mock(SchemaContext.class);
1095         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1096                 .thenReturn(module);
1097         final UsesNode usesNode = mock(UsesNode.class);
1098         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1099
1100         final Object[] args = { context, schemaPath, usesNode };
1101         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1102         assertEquals(schNode, result);
1103     }
1104
1105     @SuppressWarnings({ "rawtypes" })
1106     @Test
1107     public void findOriginalTargetFromGroupingChoiceTest() throws Exception {
1108         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1109         final Method generate =
1110                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1111         assertNotNull(generate);
1112         generate.setAccessible(true);
1113
1114         final Module module = mock(Module.class);
1115         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1116         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1117         final ChoiceSchemaNode schNode = mock(ChoiceSchemaNode.class);
1118         when(schNode.getPath()).thenReturn(schemaPath);
1119         final Set<GroupingDefinition> groupings = new HashSet<>();
1120         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1121         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1122         groupings.add(groupingDefinition);
1123         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1124         when(module.getGroupings()).thenReturn(groupings);
1125
1126         final SchemaContext context = mock(SchemaContext.class);
1127         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1128                 .thenReturn(module);
1129         final UsesNode usesNode = mock(UsesNode.class);
1130         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1131
1132         final Object[] args = { context, schemaPath, usesNode };
1133         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1134         assertEquals(schNode, result);
1135     }
1136
1137     @SuppressWarnings({ "rawtypes" })
1138     @Test
1139     public void generateTypesFromAugmentedChoiceCasesNullPckgNameTest() throws Exception {
1140         final Class[] parameterTypes =
1141                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1142                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1143         final Method generate =
1144                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1145         assertNotNull(generate);
1146         generate.setAccessible(true);
1147
1148         final SchemaContext schemaContext = null;
1149         final Module module = null;
1150         final String pckgName = null;
1151         final Type targetType = null;
1152         final ChoiceSchemaNode targetNode = null;
1153         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1154         final DataNodeContainer usesNodeParent = null;
1155         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1156         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1157
1158         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
1159                 usesNodeParent, genCtx, false, genTypeBuilder, null };
1160         try {
1161             generate.invoke(AugmentToGenType.class, args);
1162             fail();
1163         } catch (final Exception e) {
1164             assertNotNull(e);
1165             assertTrue(e instanceof InvocationTargetException);
1166             final Throwable cause = e.getCause();
1167             assertNotNull(cause);
1168             assertTrue(cause instanceof IllegalArgumentException);
1169             assertEquals("Base Package Name cannot be NULL.", cause.getMessage());
1170         }
1171     }
1172
1173     @SuppressWarnings({ "rawtypes" })
1174     @Test
1175     public void generateTypesFromAugmentedChoiceCasesNullTargetType() throws Exception {
1176         final Class[] parameterTypes =
1177                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1178                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1179         final Method generate =
1180                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1181         assertNotNull(generate);
1182         generate.setAccessible(true);
1183
1184         final SchemaContext schemaContext = null;
1185         final Module module = null;
1186         final String pckgName = "";
1187         final Type targetType = null;
1188         final ChoiceSchemaNode targetNode = null;
1189         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1190         final DataNodeContainer usesNodeParent = null;
1191         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1192         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1193
1194         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
1195                 usesNodeParent, genCtx, false, genTypeBuilder, null };
1196         try {
1197             generate.invoke(AugmentToGenType.class, args);
1198             fail();
1199         } catch (final Exception e) {
1200             assertNotNull(e);
1201             assertTrue(e instanceof InvocationTargetException);
1202             final Throwable cause = e.getCause();
1203             assertNotNull(cause);
1204             assertTrue(cause instanceof IllegalArgumentException);
1205             assertEquals("Referenced Choice Type cannot be NULL.", cause.getMessage());
1206         }
1207     }
1208
1209     @SuppressWarnings({ "rawtypes" })
1210     @Test
1211     public void generateTypesFromAugmentedChoiceCasesNullAugmentNodes() throws Exception {
1212         final Class[] parameterTypes =
1213                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1214                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1215         final Method generate =
1216                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1217         assertNotNull(generate);
1218         generate.setAccessible(true);
1219
1220         final SchemaContext schemaContext = null;
1221         final Module module = null;
1222         final String pckgName = "";
1223         final Type targetType = mock(Type.class);
1224         final ChoiceSchemaNode targetNode = null;
1225         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1226         final DataNodeContainer usesNodeParent = null;
1227         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1228         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1229
1230         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1231                 genCtx, false, genTypeBuilder, null };
1232         try {
1233             generate.invoke(AugmentToGenType.class, args);
1234             fail();
1235         } catch (final Exception e) {
1236             assertNotNull(e);
1237             assertTrue(e instanceof InvocationTargetException);
1238             final Throwable cause = e.getCause();
1239             assertNotNull(cause);
1240             assertTrue(cause instanceof IllegalArgumentException);
1241             assertEquals("Set of Choice Case Nodes cannot be NULL.", cause.getMessage());
1242         }
1243     }
1244
1245     @SuppressWarnings({ "rawtypes", "unchecked" })
1246     @Test
1247     public void generateTypesFromAugmentedChoiceCasesNullCaseNodeTest() throws Exception {
1248         final Class[] parameterTypes =
1249                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1250                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1251         final Method generate =
1252                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1253         assertNotNull(generate);
1254         generate.setAccessible(true);
1255
1256         final SchemaContext schemaContext = null;
1257         final Module module = null;
1258         final String pckgName = "";
1259         final Type targetType = mock(Type.class);
1260         final ChoiceSchemaNode targetNode = null;
1261         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1262         final DataSchemaNode caseNode = null;
1263         augmentNodes.add(caseNode);
1264
1265         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1266         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1267         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1268         schemaPathAugmentListEntry.add(augmentationSchema);
1269
1270         final DataNodeContainer usesNodeParent = null;
1271         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1272         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1273
1274         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1275                 genCtx, false, genTypeBuilder, null };
1276         final Map<Module, ModuleContext> result =
1277                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
1278         assertEquals(genCtx, result);
1279     }
1280
1281     @SuppressWarnings({ "rawtypes" })
1282     @Test
1283     public void generateTypesFromAugmentedChoiceCasesNullChildTest() throws Exception {
1284         final Class[] parameterTypes =
1285                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1286                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1287         final Method generate =
1288                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1289         assertNotNull(generate);
1290         generate.setAccessible(true);
1291
1292         final QName qnamePath = QName.create("test", "2017-04-04", "chcase");
1293         final QName qnamePath2 = QName.create("test", "2017-04-04", "chcase2");
1294         final SchemaPath path = SchemaPath.create(true, qnamePath, qnamePath2);
1295
1296         final SchemaContext schemaContext = mock(SchemaContext.class);
1297         final Module module = mock(Module.class);
1298         when(module.getName()).thenReturn("test-module-case");
1299         final DataSchemaNode schemaNode = mock(DataSchemaNode.class);
1300         when(module.getDataChildByName(qnamePath)).thenReturn(schemaNode);
1301         when(module.getRevision()).thenReturn(qnamePath.getRevision());
1302         when(module.getNamespace()).thenReturn(qnamePath.getNamespace());
1303         final String pckgName = "test.augment.choice.cases";
1304         final Type targetType = mock(Type.class);
1305         when(targetType.getFullyQualifiedName()).thenReturn(Augmentable.class.getName());
1306         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1307         final ChoiceCaseNode caseNode = mock(ChoiceCaseNode.class);
1308         when(caseNode.getPath()).thenReturn(path);
1309         when(caseNode.getQName()).thenReturn(qnamePath);
1310         augmentNodes.add(caseNode);
1311
1312         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1313         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1314         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1315         schemaPathAugmentListEntry.add(augmentationSchema);
1316
1317         final DataNodeContainer usesNodeParent = null;
1318         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
1319         when(targetNode.getPath()).thenReturn(path);
1320         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1321         final ModuleContext moduleContext = new ModuleContext();
1322         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(pckgName, "test-case-node-augment");
1323         moduleContext.addCaseType(path, gtb);
1324         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1325
1326         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1327                 .thenReturn(module);
1328
1329         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1330                 genCtx, false, genTypeBuilder, null };
1331         try {
1332             generate.invoke(AugmentToGenType.class, args);
1333             fail();
1334         } catch (final Exception e) {
1335             assertNotNull(e);
1336             assertTrue(e instanceof InvocationTargetException);
1337             final Throwable cause = e.getCause();
1338             assertNotNull(cause);
1339             assertTrue(cause instanceof IllegalArgumentException);
1340             assertEquals("Failed to find parent type of choice " + targetNode, cause.getMessage());
1341         }
1342     }
1343
1344     @SuppressWarnings({ "rawtypes", "unchecked" })
1345     @Test
1346     public void generateTypesFromAugmentedChoiceCasesTest() throws Exception {
1347         final Class[] parameterTypes =
1348                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1349                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class };
1350         final Method generate =
1351                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1352         assertNotNull(generate);
1353         generate.setAccessible(true);
1354
1355         final QName qnamePath = QName.create("test", "2017-04-04", "chcase");
1356         final QName qnamePath2 = QName.create("test", "2017-04-04", "chcase2");
1357         final SchemaPath path = SchemaPath.create(true, qnamePath, qnamePath2);
1358
1359         final SchemaContext schemaContext = mock(SchemaContext.class);
1360         final Module module = mock(Module.class);
1361         when(module.getName()).thenReturn("test-module-case");
1362         final ChoiceCaseNode schemaNode = mock(ChoiceCaseNode.class);
1363         when(schemaNode.getPath()).thenReturn(path);
1364         when(module.getDataChildByName(qnamePath)).thenReturn(schemaNode);
1365         when(module.getRevision()).thenReturn(qnamePath.getRevision());
1366         when(module.getNamespace()).thenReturn(qnamePath.getNamespace());
1367         final String pckgName = "test.augment.choice.cases";
1368         final Type targetType = mock(Type.class);
1369         when(targetType.getFullyQualifiedName()).thenReturn(Augmentable.class.getName());
1370         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1371         final ChoiceCaseNode caseNode = mock(ChoiceCaseNode.class);
1372         when(caseNode.getPath()).thenReturn(path);
1373         when(caseNode.getQName()).thenReturn(qnamePath);
1374         augmentNodes.add(caseNode);
1375
1376         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1377         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1378         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1379         schemaPathAugmentListEntry.add(augmentationSchema);
1380
1381         final DataNodeContainer usesNodeParent = null;
1382         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
1383         when(targetNode.getPath()).thenReturn(path);
1384         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1385         final ModuleContext moduleContext = new ModuleContext();
1386         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(pckgName, "test-case-node-augment");
1387         moduleContext.addCaseType(path, gtb);
1388         genCtx.put(module, moduleContext);
1389         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1390
1391         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1392                 .thenReturn(module);
1393
1394         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1395                 genCtx, false, genTypeBuilder, null };
1396         final Map<Module, ModuleContext> result =
1397                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
1398         assertNotNull(result);
1399         assertEquals(result.get(module), moduleContext);
1400     }
1401 }