1c0557cc181d405a3d42e4e6f7b3950c42be6c88
[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(q1.getNamespace(), q1.getRevision())).thenReturn(m2);
289         when(schemaContext.findModuleByNamespaceAndRevision(q3.getNamespace(), q3.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         when(origSchNode.getQName()).thenReturn(QName.create("test", "2017-04-04", "aug-node"));
697         final Optional optionalSchemaNode = Optional.of(origSchNode);
698         when(targetSchNode.getOriginal()).thenReturn(optionalSchemaNode);
699         when(moduleAug.getDataChildByName(qnamePath)).thenReturn(targetSchNode);
700         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
701                 .thenReturn(moduleAug);
702
703         final TypeProvider typeProvider = null;
704
705         final Map<Module, ModuleContext> genCtx = new HashMap<>();
706
707         final Collection<ModuleContext> moduleContexts = new ArrayList<>();
708         final ModuleContext mc = new ModuleContext();
709         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(augmPackName, "augm");
710         mc.addChildNodeType(targetSchNode, gtb);
711         moduleContexts.add(mc);
712         genCtx.put(moduleAug, mc);
713
714         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
715
716         when(moduleAug.getName()).thenReturn("augm-module");
717         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
718         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
719
720         final Object[] args =
721                 { augmPackName, schemaPathAugmentListEntry, moduleAug, context, false, genCtx, genTypeBuilders, typeProvider };
722         final Map<Module, ModuleContext> result =
723                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
724         assertNotNull(result);
725         final ModuleContext moduleContext = result.get(moduleAug);
726         assertTrue(moduleContext.getAugmentations().get(0).getName().contains("Augm"));
727         assertEquals("pckg.name.data", moduleContext.getAugmentations().get(0).getPackageName());
728         assertTrue(moduleContext.getChildNode(path).getName().contains("Augm"));
729         assertEquals("pckg.name", moduleContext.getChildNode(path).getPackageName());
730     }
731
732     @Deprecated
733     @Test
734     public void usesAugmentationToGenTypesNullPckgNameTest() throws Exception {
735         try {
736             AugmentToGenType.usesAugmentationToGenTypes(null, null, null, null, null, null, null, null, false, null, null);
737         } catch (final Exception e) {
738             assertNotNull(e);
739             assertTrue(e instanceof IllegalArgumentException);
740             assertEquals(e.getMessage(), "Package Name cannot be NULL.");
741         }
742     }
743
744     @Deprecated
745     @Test
746     public void usesAugmentationToGenTypesNullAugSchemaListEntryTest() throws Exception {
747         try {
748             AugmentToGenType.usesAugmentationToGenTypes(null, "", null, null, null, null, null, null, false, null, null);
749         } catch (final Exception e) {
750             assertNotNull(e);
751             assertTrue(e instanceof IllegalArgumentException);
752             assertEquals(e.getMessage(), "Augmentation Schema List Entry cannot be NULL.");
753         }
754     }
755
756     @Deprecated
757     @Test
758     public void usesAugmentationToGenTypesEmptyAugSchemaListTest() throws Exception {
759         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
760         try {
761             AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
762                     false, null, null);
763         } catch (final Exception e) {
764             assertNotNull(e);
765             assertTrue(e instanceof IllegalStateException);
766             assertEquals(e.getMessage(), "Augmentation Schema List cannot be empty");
767         }
768     }
769
770     @Deprecated
771     @Test
772     public void usesAugmentationToGenTypesNullAugSchemaNodeTargetPathTest() throws Exception {
773         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
774         when(augmentationSchema.getTargetPath()).thenReturn(null);
775         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
776         augmentationSchemaList.add(augmentationSchema);
777         try {
778             AugmentToGenType.usesAugmentationToGenTypes(null, "", augmentationSchemaList, null, null, null, null, null,
779                     false, null, null);
780         } catch (final Exception e) {
781             assertNotNull(e);
782             assertTrue(e instanceof IllegalStateException);
783             assertEquals(e.getMessage(), "Augmentation Schema does not contain Target Path (Target Path is NULL).");
784         }
785     }
786
787     @Deprecated
788     @Test
789     public void usesAugmentationToGenTypesNullAugmentTargetTest() throws Exception {
790         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
791         final SchemaPath path = SchemaPath.create(true, qnamePath);
792         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
793         when(augmentationSchema.getTargetPath()).thenReturn(path);
794         final Set<UsesNode> uses = new HashSet<>();
795         when(augmentationSchema.getUses()).thenReturn(uses);
796
797         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
798         augmentationSchemaList.add(augmentationSchema);
799
800         final SchemaContext context = mock(SchemaContext.class);
801         final Module moduleAug = mock(Module.class);
802         when(moduleAug.getName()).thenReturn("augm-module");
803         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
804         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
805         final Set<GroupingDefinition> groupings = new HashSet<>();
806         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
807         when(groupingDefinition.getQName()).thenReturn(qnamePath);
808         groupings.add(groupingDefinition);
809         when(moduleAug.getGroupings()).thenReturn(groupings);
810
811         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
812                 .thenReturn(moduleAug);
813
814         final Map<Module, ModuleContext> genCtx = new HashMap<>();
815         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
816
817
818         final UsesNode usesNode = mock(UsesNode.class);
819         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
820
821         when(usesNode.getGroupingPath()).thenReturn(path);
822
823         try {
824             AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
825                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null, null);
826         } catch (final Exception e) {
827             assertNotNull(e);
828             assertTrue(e instanceof IllegalArgumentException);
829             assertEquals(e.getMessage(), "augment target not found: " + path);
830         }
831     }
832
833     @Deprecated
834     @Test
835     public void usesAugmentationToGenTypesNullTargetGTBTest() throws Exception {
836         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
837         final SchemaPath path = SchemaPath.create(true, qnamePath);
838         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
839         when(augmentationSchema.getTargetPath()).thenReturn(path);
840         final Set<UsesNode> uses = new HashSet<>();
841         when(augmentationSchema.getUses()).thenReturn(uses);
842
843         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
844         augmentationSchemaList.add(augmentationSchema);
845
846         final SchemaContext context = mock(SchemaContext.class);
847         final Module moduleAug = mock(Module.class);
848         when(moduleAug.getName()).thenReturn("augm-module");
849         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
850         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
851         final Set<GroupingDefinition> groupings = new HashSet<>();
852         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
853         when(groupingDefinition.getQName()).thenReturn(qnamePath);
854         final DataSchemaNode schNode = mock(DataSchemaNode.class);
855         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
856         groupings.add(groupingDefinition);
857         when(moduleAug.getGroupings()).thenReturn(groupings);
858
859         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
860                 .thenReturn(moduleAug);
861
862         final Map<Module, ModuleContext> genCtx = new HashMap<>();
863         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
864
865         final UsesNode usesNode = mock(UsesNode.class);
866         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
867
868         when(usesNode.getGroupingPath()).thenReturn(path);
869
870         try {
871             AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm", augmentationSchemaList, moduleAug,
872                     usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null, null);
873         } catch (final Exception e) {
874             assertNotNull(e);
875             assertTrue(e instanceof NullPointerException);
876             assertEquals(e.getMessage(), "Target type not yet generated: " + schNode);
877         }
878     }
879
880     @Deprecated
881     @Test
882     public void usesAugmentationToGenTypesTest() throws Exception {
883         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
884         final SchemaPath path = SchemaPath.create(true, qnamePath);
885         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
886         when(augmentationSchema.getTargetPath()).thenReturn(path);
887         final Set<UsesNode> uses = new HashSet<>();
888         when(augmentationSchema.getUses()).thenReturn(uses);
889
890         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
891         augmentationSchemaList.add(augmentationSchema);
892
893         final SchemaContext context = mock(SchemaContext.class);
894         final Module moduleAug = mock(Module.class);
895         when(moduleAug.getName()).thenReturn("augm-module");
896         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
897         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
898         final Set<GroupingDefinition> groupings = new HashSet<>();
899         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
900         when(groupingDefinition.getQName()).thenReturn(qnamePath);
901         final DataSchemaNode schNode = mock(DataSchemaNode.class);
902         when(schNode.getPath()).thenReturn(path);
903         when(schNode.getQName()).thenReturn(QName.create("test", "2017-04-04", "aug-node"));
904         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
905         groupings.add(groupingDefinition);
906         when(moduleAug.getGroupings()).thenReturn(groupings);
907
908         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
909                 .thenReturn(moduleAug);
910
911         final Map<Module, ModuleContext> genCtx = new HashMap<>();
912         final ModuleContext mc = new ModuleContext();
913         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl("pckg.test.augm", "GtbAugm");
914         mc.addChildNodeType(schNode, gtb);
915         genCtx.put(moduleAug, mc);
916
917         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
918
919         final UsesNode usesNode = mock(UsesNode.class);
920         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
921
922         when(usesNode.getGroupingPath()).thenReturn(path);
923
924         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
925                 augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null,
926                 BindingNamespaceType.Data);
927         assertNotNull(result);
928     }
929
930     @Deprecated
931     @Test
932     public void usesAugmentationToGenTypesChoiceTest() throws Exception {
933         final QName qnamePath = QName.create("test", "2017-04-04", "aug");
934         final SchemaPath path = SchemaPath.create(true, qnamePath);
935         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
936         when(augmentationSchema.getTargetPath()).thenReturn(path);
937         final Set<UsesNode> uses = new HashSet<>();
938         when(augmentationSchema.getUses()).thenReturn(uses);
939
940         final List<AugmentationSchema> augmentationSchemaList = new ArrayList<>();
941         augmentationSchemaList.add(augmentationSchema);
942
943         final SchemaContext context = mock(SchemaContext.class);
944         final Module moduleAug = mock(Module.class);
945         when(moduleAug.getName()).thenReturn("augm-module");
946         when(moduleAug.getNamespace()).thenReturn(qnamePath.getNamespace());
947         when(moduleAug.getRevision()).thenReturn(qnamePath.getRevision());
948         final Set<GroupingDefinition> groupings = new HashSet<>();
949         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
950         when(groupingDefinition.getQName()).thenReturn(qnamePath);
951         final ChoiceSchemaNode schNode = mock(ChoiceSchemaNode.class);
952         when(schNode.getPath()).thenReturn(path);
953         when(schNode.getQName()).thenReturn(QName.create("test", "2017-04-04", "aug-node"));
954         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
955         groupings.add(groupingDefinition);
956         when(moduleAug.getGroupings()).thenReturn(groupings);
957
958         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
959                 .thenReturn(moduleAug);
960
961         final Map<Module, ModuleContext> genCtx = new HashMap<>();
962         final ModuleContext mc = new ModuleContext();
963         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl("pckg.test.augm", "GtbAugm");
964         mc.addChildNodeType(schNode, gtb);
965         genCtx.put(moduleAug, mc);
966
967         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
968
969         final UsesNode usesNode = mock(UsesNode.class);
970         final DataNodeContainer usesNodeParent = mock(DataNodeContainer.class);
971
972         when(usesNode.getGroupingPath()).thenReturn(path);
973
974         final Map<Module, ModuleContext> result = AugmentToGenType.usesAugmentationToGenTypes(context, "pckg.test.augm",
975                 augmentationSchemaList, moduleAug, usesNode, usesNodeParent, genCtx, genTypeBuilders, false, null,
976                 BindingNamespaceType.Data);
977         assertNotNull(result);
978     }
979
980     @SuppressWarnings({ "rawtypes" })
981     @Test
982     public void findOriginalTargetFromGroupingNonGroupingTest() throws Exception {
983         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
984         final Method generate =
985                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
986         assertNotNull(generate);
987         generate.setAccessible(true);
988
989         final Module module = mock(Module.class);
990         final QName qnamePath = QName.create("test", "2017-04-04", "test");
991         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
992         final DataSchemaNode schNode = mock(DataSchemaNode.class);
993         when(schNode.getPath()).thenReturn(schemaPath);
994         when(module.getDataChildByName(qnamePath)).thenReturn(schNode);
995
996         final SchemaContext context = mock(SchemaContext.class);
997         when(context.findModuleByNamespaceAndRevision(qnamePath .getNamespace(), qnamePath.getRevision()))
998                 .thenReturn(module);
999         final UsesNode usesNode = mock(UsesNode.class);
1000         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1001
1002         final Object[] args = { context, schemaPath, usesNode };
1003         try {
1004             generate.invoke(AugmentToGenType.class, args);
1005             fail();
1006         } catch (final Exception e) {
1007             assertNotNull(e);
1008             assertTrue(e instanceof InvocationTargetException);
1009             final Throwable cause = e.getCause();
1010             assertNotNull(cause);
1011             assertTrue(cause instanceof IllegalArgumentException);
1012             assertEquals("Failed to generate code for augment in " + usesNode, cause.getMessage());
1013         }
1014     }
1015
1016     @SuppressWarnings({ "rawtypes" })
1017     @Test
1018     public void findOriginalTargetFromGroupingAsUsesFailedTest() throws Exception {
1019         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1020         final Method generate =
1021                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1022         assertNotNull(generate);
1023         generate.setAccessible(true);
1024
1025         final Module module = mock(Module.class);
1026         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1027         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1028         final DataSchemaNode schNode = mock(DataSchemaNode.class);
1029         when(schNode.getPath()).thenReturn(schemaPath);
1030         when(schNode.isAddedByUses()).thenReturn(true);
1031         final Set<GroupingDefinition> groupings = new HashSet<>();
1032         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1033         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1034         groupings.add(groupingDefinition);
1035         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1036         when(module.getGroupings()).thenReturn(groupings);
1037
1038         final SchemaContext context = mock(SchemaContext.class);
1039         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1040                 .thenReturn(module);
1041         final UsesNode usesNode = mock(UsesNode.class);
1042         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1043
1044         final Object[] args = { context, schemaPath, usesNode };
1045         try {
1046             generate.invoke(AugmentToGenType.class, args);
1047             fail();
1048         } catch (final Exception e) {
1049             assertNotNull(e);
1050             assertTrue(e instanceof InvocationTargetException);
1051             final Throwable cause = e.getCause();
1052             assertNotNull(cause);
1053             assertTrue(cause instanceof IllegalStateException);
1054             assertEquals("Failed to generate code for augment in " + usesNode, cause.getMessage());
1055         }
1056     }
1057
1058     @SuppressWarnings({ "rawtypes" })
1059     @Test
1060     public void findOriginalTargetFromGroupingReturnNullTest() throws Exception {
1061         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1062         final Method generate =
1063                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1064         assertNotNull(generate);
1065         generate.setAccessible(true);
1066
1067         final Module module = mock(Module.class);
1068         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1069         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1070         final DataSchemaNode schNode = null;
1071         final Set<GroupingDefinition> groupings = new HashSet<>();
1072         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1073         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1074         groupings.add(groupingDefinition);
1075         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1076         when(module.getGroupings()).thenReturn(groupings);
1077
1078         final SchemaContext context = mock(SchemaContext.class);
1079         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1080                 .thenReturn(module);
1081         final UsesNode usesNode = mock(UsesNode.class);
1082         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1083
1084         final Object[] args = { context, schemaPath, usesNode };
1085         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1086         assertEquals(null, result);
1087     }
1088
1089     @SuppressWarnings({ "rawtypes", "unchecked" })
1090     @Test
1091     public void findOriginalTargetFromGroupingTest() throws Exception {
1092         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1093         final Method generate =
1094                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1095         assertNotNull(generate);
1096         generate.setAccessible(true);
1097
1098         final Module module = mock(Module.class);
1099         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1100         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1101         final DataSchemaNode schNode = mock(DataSchemaNode.class);
1102         when(schNode.getPath()).thenReturn(schemaPath);
1103         final Set<GroupingDefinition> groupings = new HashSet<>();
1104         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1105         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1106         groupings.add(groupingDefinition);
1107         final DerivableSchemaNode derivSchNode = mock(DerivableSchemaNode.class);
1108         when(derivSchNode.isAddedByUses()).thenReturn(true);
1109         final Optional optional = Optional.of(schNode);
1110         when(derivSchNode.getOriginal()).thenReturn(optional);
1111         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(derivSchNode);
1112         when(module.getGroupings()).thenReturn(groupings);
1113
1114         final SchemaContext context = mock(SchemaContext.class);
1115         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1116                 .thenReturn(module);
1117         final UsesNode usesNode = mock(UsesNode.class);
1118         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1119
1120         final Object[] args = { context, schemaPath, usesNode };
1121         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1122         assertEquals(schNode, result);
1123     }
1124
1125     @SuppressWarnings({ "rawtypes" })
1126     @Test
1127     public void findOriginalTargetFromGroupingChoiceTest() throws Exception {
1128         final Class[] parameterTypes = { SchemaContext.class, SchemaPath.class, UsesNode.class };
1129         final Method generate =
1130                 AugmentToGenType.class.getDeclaredMethod("findOriginalTargetFromGrouping", parameterTypes);
1131         assertNotNull(generate);
1132         generate.setAccessible(true);
1133
1134         final Module module = mock(Module.class);
1135         final QName qnamePath = QName.create("test", "2017-04-04", "test");
1136         final SchemaPath schemaPath = SchemaPath.create(true, qnamePath);
1137         final ChoiceSchemaNode schNode = mock(ChoiceSchemaNode.class);
1138         when(schNode.getPath()).thenReturn(schemaPath);
1139         final Set<GroupingDefinition> groupings = new HashSet<>();
1140         final GroupingDefinition groupingDefinition = mock(GroupingDefinition.class);
1141         when(groupingDefinition.getQName()).thenReturn(qnamePath);
1142         groupings.add(groupingDefinition);
1143         when(groupingDefinition.getDataChildByName(qnamePath)).thenReturn(schNode);
1144         when(module.getGroupings()).thenReturn(groupings);
1145
1146         final SchemaContext context = mock(SchemaContext.class);
1147         when(context.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1148                 .thenReturn(module);
1149         final UsesNode usesNode = mock(UsesNode.class);
1150         when(usesNode.getGroupingPath()).thenReturn(schemaPath);
1151
1152         final Object[] args = { context, schemaPath, usesNode };
1153         final DataSchemaNode result = (DataSchemaNode) generate.invoke(AugmentToGenType.class, args);
1154         assertEquals(schNode, result);
1155     }
1156
1157     @SuppressWarnings({ "rawtypes" })
1158     @Test
1159     public void generateTypesFromAugmentedChoiceCasesNullPckgNameTest() throws Exception {
1160         final Class[] parameterTypes =
1161                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1162                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1163                         BindingNamespaceType.class};
1164         final Method generate =
1165                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1166         assertNotNull(generate);
1167         generate.setAccessible(true);
1168
1169         final SchemaContext schemaContext = null;
1170         final Module module = null;
1171         final String pckgName = null;
1172         final Type targetType = null;
1173         final ChoiceSchemaNode targetNode = null;
1174         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1175         final DataNodeContainer usesNodeParent = null;
1176         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1177         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1178
1179         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
1180                 usesNodeParent, genCtx, false, genTypeBuilder, null, BindingNamespaceType.Data };
1181         try {
1182             generate.invoke(AugmentToGenType.class, args);
1183             fail();
1184         } catch (final Exception e) {
1185             assertNotNull(e);
1186             assertTrue(e instanceof InvocationTargetException);
1187             final Throwable cause = e.getCause();
1188             assertNotNull(cause);
1189             assertTrue(cause instanceof IllegalArgumentException);
1190             assertEquals("Base Package Name cannot be NULL.", cause.getMessage());
1191         }
1192     }
1193
1194     @SuppressWarnings({ "rawtypes" })
1195     @Test
1196     public void generateTypesFromAugmentedChoiceCasesNullTargetType() throws Exception {
1197         final Class[] parameterTypes =
1198                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1199                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1200                         BindingNamespaceType.class };
1201         final Method generate =
1202                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1203         assertNotNull(generate);
1204         generate.setAccessible(true);
1205
1206         final SchemaContext schemaContext = null;
1207         final Module module = null;
1208         final String pckgName = "";
1209         final Type targetType = null;
1210         final ChoiceSchemaNode targetNode = null;
1211         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1212         final DataNodeContainer usesNodeParent = null;
1213         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1214         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1215
1216         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry,
1217                 usesNodeParent, genCtx, false, genTypeBuilder, null, BindingNamespaceType.Data };
1218         try {
1219             generate.invoke(AugmentToGenType.class, args);
1220             fail();
1221         } catch (final Exception e) {
1222             assertNotNull(e);
1223             assertTrue(e instanceof InvocationTargetException);
1224             final Throwable cause = e.getCause();
1225             assertNotNull(cause);
1226             assertTrue(cause instanceof IllegalArgumentException);
1227             assertEquals("Referenced Choice Type cannot be NULL.", cause.getMessage());
1228         }
1229     }
1230
1231     @SuppressWarnings({ "rawtypes" })
1232     @Test
1233     public void generateTypesFromAugmentedChoiceCasesNullAugmentNodes() throws Exception {
1234         final Class[] parameterTypes =
1235                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1236                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1237                         BindingNamespaceType.class };
1238         final Method generate =
1239                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1240         assertNotNull(generate);
1241         generate.setAccessible(true);
1242
1243         final SchemaContext schemaContext = null;
1244         final Module module = null;
1245         final String pckgName = "";
1246         final Type targetType = mock(Type.class);
1247         final ChoiceSchemaNode targetNode = null;
1248         final List<AugmentationSchema> schemaPathAugmentListEntry = null;
1249         final DataNodeContainer usesNodeParent = null;
1250         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1251         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1252
1253         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1254                 genCtx, false, genTypeBuilder, null, BindingNamespaceType.Data };
1255         try {
1256             generate.invoke(AugmentToGenType.class, args);
1257             fail();
1258         } catch (final Exception e) {
1259             assertNotNull(e);
1260             assertTrue(e instanceof InvocationTargetException);
1261             final Throwable cause = e.getCause();
1262             assertNotNull(cause);
1263             assertTrue(cause instanceof IllegalArgumentException);
1264             assertEquals("Set of Choice Case Nodes cannot be NULL.", cause.getMessage());
1265         }
1266     }
1267
1268     @SuppressWarnings({ "rawtypes", "unchecked" })
1269     @Test
1270     public void generateTypesFromAugmentedChoiceCasesNullCaseNodeTest() throws Exception {
1271         final Class[] parameterTypes =
1272                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1273                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1274                         BindingNamespaceType.class };
1275         final Method generate =
1276                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1277         assertNotNull(generate);
1278         generate.setAccessible(true);
1279
1280         final SchemaContext schemaContext = null;
1281         final Module module = null;
1282         final String pckgName = "";
1283         final Type targetType = mock(Type.class);
1284         final ChoiceSchemaNode targetNode = null;
1285         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1286         final DataSchemaNode caseNode = null;
1287         augmentNodes.add(caseNode);
1288
1289         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1290         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1291         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1292         schemaPathAugmentListEntry.add(augmentationSchema);
1293
1294         final DataNodeContainer usesNodeParent = null;
1295         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1296         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1297
1298         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1299                 genCtx, false, genTypeBuilder, null, BindingNamespaceType.Data };
1300         final Map<Module, ModuleContext> result =
1301                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
1302         assertEquals(genCtx, result);
1303     }
1304
1305     @SuppressWarnings({ "rawtypes" })
1306     @Test
1307     public void generateTypesFromAugmentedChoiceCasesNullChildTest() throws Exception {
1308         final Class[] parameterTypes =
1309                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1310                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1311                         BindingNamespaceType.class };
1312         final Method generate =
1313                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1314         assertNotNull(generate);
1315         generate.setAccessible(true);
1316
1317         final QName qnamePath = QName.create("test", "2017-04-04", "chcase");
1318         final QName qnamePath2 = QName.create("test", "2017-04-04", "chcase2");
1319         final SchemaPath path = SchemaPath.create(true, qnamePath, qnamePath2);
1320
1321         final SchemaContext schemaContext = mock(SchemaContext.class);
1322         final Module module = mock(Module.class);
1323         when(module.getName()).thenReturn("test-module-case");
1324         final DataSchemaNode schemaNode = mock(DataSchemaNode.class);
1325         when(module.getDataChildByName(qnamePath)).thenReturn(schemaNode);
1326         when(module.getRevision()).thenReturn(qnamePath.getRevision());
1327         when(module.getNamespace()).thenReturn(qnamePath.getNamespace());
1328         final String pckgName = "test.augment.choice.cases";
1329         final Type targetType = mock(Type.class);
1330         when(targetType.getFullyQualifiedName()).thenReturn(Augmentable.class.getName());
1331         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1332         final ChoiceCaseNode caseNode = mock(ChoiceCaseNode.class);
1333         when(caseNode.getPath()).thenReturn(path);
1334         when(caseNode.getQName()).thenReturn(qnamePath);
1335         augmentNodes.add(caseNode);
1336
1337         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1338         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1339         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1340         schemaPathAugmentListEntry.add(augmentationSchema);
1341
1342         final DataNodeContainer usesNodeParent = null;
1343         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
1344         when(targetNode.getPath()).thenReturn(path);
1345         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1346         final ModuleContext moduleContext = new ModuleContext();
1347         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(pckgName, "test-case-node-augment");
1348         moduleContext.addCaseType(path, gtb);
1349         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1350
1351         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1352                 .thenReturn(module);
1353
1354         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1355                 genCtx, false, genTypeBuilder, null, BindingNamespaceType.Data };
1356         try {
1357             generate.invoke(AugmentToGenType.class, args);
1358             fail();
1359         } catch (final Exception e) {
1360             assertNotNull(e);
1361             assertTrue(e instanceof InvocationTargetException);
1362             final Throwable cause = e.getCause();
1363             assertNotNull(cause);
1364             assertTrue(cause instanceof IllegalArgumentException);
1365             assertEquals("Failed to find parent type of choice " + targetNode, cause.getMessage());
1366         }
1367     }
1368
1369     @SuppressWarnings({ "rawtypes", "unchecked" })
1370     @Test
1371     public void generateTypesFromAugmentedChoiceCasesTest() throws Exception {
1372         final Class[] parameterTypes =
1373                 { SchemaContext.class, Module.class, String.class, Type.class, ChoiceSchemaNode.class, List.class,
1374                         DataNodeContainer.class, Map.class, boolean.class, Map.class, TypeProvider.class,
1375                         BindingNamespaceType.class };
1376         final Method generate =
1377                 AugmentToGenType.class.getDeclaredMethod("generateTypesFromAugmentedChoiceCases", parameterTypes);
1378         assertNotNull(generate);
1379         generate.setAccessible(true);
1380
1381         final QName qnamePath = QName.create("test", "2017-04-04", "chcase");
1382         final QName qnamePath2 = QName.create("test", "2017-04-04", "chcase2");
1383         final SchemaPath path = SchemaPath.create(true, qnamePath, qnamePath2);
1384
1385         final SchemaContext schemaContext = mock(SchemaContext.class);
1386         final Module module = mock(Module.class);
1387         when(module.getName()).thenReturn("test-module-case");
1388         final ChoiceCaseNode schemaNode = mock(ChoiceCaseNode.class);
1389         when(schemaNode.getPath()).thenReturn(path);
1390         when(module.getDataChildByName(qnamePath)).thenReturn(schemaNode);
1391         when(module.getRevision()).thenReturn(qnamePath.getRevision());
1392         when(module.getNamespace()).thenReturn(qnamePath.getNamespace());
1393         final String pckgName = "test.augment.choice.cases";
1394         final Type targetType = mock(Type.class);
1395         when(targetType.getFullyQualifiedName()).thenReturn(Augmentable.class.getName());
1396         final Set<DataSchemaNode> augmentNodes = new HashSet<>();
1397         final ChoiceCaseNode caseNode = mock(ChoiceCaseNode.class);
1398         when(caseNode.getPath()).thenReturn(path);
1399         when(caseNode.getQName()).thenReturn(qnamePath);
1400         augmentNodes.add(caseNode);
1401
1402         final AugmentationSchema augmentationSchema = mock(AugmentationSchema.class);
1403         when(augmentationSchema.getChildNodes()).thenReturn(augmentNodes);
1404         final List<AugmentationSchema> schemaPathAugmentListEntry = new ArrayList<>();
1405         schemaPathAugmentListEntry.add(augmentationSchema);
1406
1407         final DataNodeContainer usesNodeParent = null;
1408         final ChoiceSchemaNode targetNode = mock(ChoiceSchemaNode.class);
1409         when(targetNode.getPath()).thenReturn(path);
1410         final Map<Module, ModuleContext> genCtx = new HashMap<>();
1411         final ModuleContext moduleContext = new ModuleContext();
1412         final GeneratedTypeBuilder gtb = new GeneratedTypeBuilderImpl(pckgName, "test-case-node-augment");
1413         moduleContext.addCaseType(path, gtb);
1414         genCtx.put(module, moduleContext);
1415         final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilder = new HashMap<>();
1416
1417         when(schemaContext.findModuleByNamespaceAndRevision(qnamePath.getNamespace(), qnamePath.getRevision()))
1418                 .thenReturn(module);
1419
1420         final Object[] args = { schemaContext, module, pckgName, targetType, targetNode, schemaPathAugmentListEntry, usesNodeParent,
1421                 genCtx, false, genTypeBuilder, null ,BindingNamespaceType.Data };
1422         final Map<Module, ModuleContext> result =
1423                 (Map<Module, ModuleContext>) generate.invoke(AugmentToGenType.class, args);
1424         assertNotNull(result);
1425         assertEquals(result.get(module), moduleContext);
1426     }
1427 }