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