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