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