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