Merge "Fixed resolving of schema path and qname for nodes added by augmentation."
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / UsesAugmentTest.java
1 /*
2  * Copyright (c) 2013 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.yangtools.yang.parser.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.io.FileNotFoundException;
13 import java.net.URI;
14 import java.text.ParseException;
15 import java.util.Date;
16 import java.util.LinkedList;
17 import java.util.List;
18 import java.util.Set;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
24 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.Module;
29 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
30 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
31 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
32 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
33 import org.opendaylight.yangtools.yang.model.util.BooleanType;
34 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
35 import org.opendaylight.yangtools.yang.model.util.Uint32;
36 import org.opendaylight.yangtools.yang.model.util.Uint8;
37 import org.opendaylight.yangtools.yang.model.util.UnionType;
38
39 import com.google.common.collect.Lists;
40
41 public class UsesAugmentTest {
42     private static final URI UG_NS = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping");
43     private static final URI GD_NS = URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions");
44     private Date UG_REV;
45     private Date GD_REV;
46     private static final String UG_PREF = "ug";
47     private static final String GD_PREF = "gd";
48
49     private Set<Module> modules;
50
51     @Before
52     public void init() throws FileNotFoundException, ParseException {
53         UG_REV = TestUtils.simpleDateFormat.parse("2013-07-30");
54         GD_REV = TestUtils.simpleDateFormat.parse("2013-09-04");
55     }
56
57     /**
58      * Structure of testing model:
59      *
60      * notification pcreq
61      * |-- leaf version (U)
62      * |-- leaf type (U)
63      * |-- list requests
64      * |-- |-- container rp
65      * |-- |-- |-- leaf priority (U)
66      * |-- |-- |-- container box (U)
67      * |-- |-- |-- |-- container order (A)
68      * |-- |-- |-- |-- |-- leaf delete (U)
69      * |-- |-- |-- |-- |-- |-- leaf setup (U)
70      * |-- |-- |-- leaf processing-rule (U)
71      * |-- |-- |-- leaf ignore (U)
72      * |-- |-- path-key-expansion
73      * |-- |-- |-- container path-key
74      * |-- |-- |-- |-- list path-keys (U)
75      * |-- |-- |-- |-- |-- leaf version (U)
76      * |-- |-- |-- |-- |-- leaf type (U)
77      * |-- |-- |-- |-- |-- leaf processing-rule (U)
78      * |-- |-- |-- |-- |-- leaf ignore (U)
79      * |-- |-- container segment-computation
80      * |-- |-- |-- container p2p
81      * |-- |-- |-- |-- container endpoints
82      * |-- |-- |-- |-- |-- leaf processing-rule (U)
83      * |-- |-- |-- |-- |-- leaf ignore (U)
84      * |-- |-- |-- |-- |-- container box (U)
85      * |-- |-- |-- |-- |-- choice address-family (U)
86      * |-- |-- |-- |-- |-- |-- case ipv4
87      * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address
88      * |-- |-- |-- |-- |-- |-- case ipv6
89      * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address
90      * |-- |-- |-- |-- container reported-route
91      * |-- |-- |-- |-- |-- container bandwidth
92      * |-- |-- |-- |-- |-- list subobjects(U)
93      * |-- |-- |-- |-- |-- leaf processing-rule (U)
94      * |-- |-- |-- |-- |-- leaf ignore (U)
95      * |-- |-- |-- |-- container bandwidth (U)
96      * |-- |-- |-- |-- |-- container bandwidth (U)
97      * |-- |-- |-- |-- |-- leaf processing-rule (U)
98      * |-- |-- |-- |-- |-- leaf ignore (U)
99      * |-- list svec
100      * |-- |-- list metric
101      * |-- |-- |-- leaf metric-type (U)
102      * |-- |-- |-- container box (U)
103      * |-- |-- |-- leaf processing-rule (U)
104      * |-- |-- |-- leaf ignore (U)
105      * |-- |-- leaf link-diverse (U)
106      * |-- |-- leaf processing-rule (U)
107      * |-- |-- leaf ignore (U)
108      *
109      * U = added by uses A = added by augment
110      */
111     @Test
112     public void testAugmentInUses() throws Exception {
113         modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
114         Module testModule = TestUtils.findModule(modules, "uses-grouping");
115
116         LinkedList<QName> path = new LinkedList<>();
117
118         // * notification pcreq
119         Set<NotificationDefinition> notifications = testModule.getNotifications();
120         assertEquals(1, notifications.size());
121         NotificationDefinition pcreq = notifications.iterator().next();
122         assertNotNull(pcreq);
123         QName expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "pcreq");
124         path.offer(expectedQName);
125         SchemaPath expectedPath = new SchemaPath(path, true);
126         assertEquals(expectedPath, pcreq.getPath());
127         Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
128         assertEquals(4, childNodes.size());
129         // * |-- leaf version
130         LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
131         assertNotNull(version);
132         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "version");
133         path.offer(expectedQName);
134         expectedPath = new SchemaPath(path, true);
135         assertEquals(expectedPath, version.getPath());
136         expectedQName = new QName(GD_NS, GD_REV, GD_PREF, "protocol-version");
137         path.offer(expectedQName);
138         expectedPath = new SchemaPath(Lists.newArrayList(expectedQName), true);
139         assertEquals(expectedPath, version.getType().getPath());
140         assertEquals(Uint8.getInstance(), version.getType().getBaseType());
141         assertTrue(version.isAddedByUses());
142         // * |-- leaf type
143         LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName("type");
144         assertNotNull(type);
145         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "type");
146         assertTrue(type.isAddedByUses());
147         path.pollLast();
148         path.pollLast();
149         path.offer(expectedQName);
150         expectedPath = new SchemaPath(path, true);
151         assertEquals(expectedPath, type.getPath());
152         expectedQName = new QName(GD_NS, GD_REV, GD_PREF, "int-ext");
153         path.offer(expectedQName);
154         expectedPath = new SchemaPath(Lists.newArrayList(expectedQName), true);
155         assertEquals(expectedPath, type.getType().getPath());
156         UnionType union = (UnionType)type.getType().getBaseType();
157         assertEquals(BaseTypes.schemaPath(BaseTypes.constructQName("union")), union.getPath());
158         assertEquals(2, union.getTypes().size());
159         // * |-- list requests
160         ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName("requests");
161         assertNotNull(requests);
162         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "requests");
163         assertEquals(expectedQName, requests.getQName());
164         path.pollLast();
165         path.pollLast();
166         path.offer(expectedQName);
167         expectedPath = new SchemaPath(path, true);
168         assertEquals(expectedPath, requests.getPath());
169         assertFalse(requests.isAddedByUses());
170         childNodes = requests.getChildNodes();
171         assertEquals(3, childNodes.size());
172         // * |-- |-- container rp
173         ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName("rp");
174         assertNotNull(rp);
175         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "rp");
176         path.offer(expectedQName);
177         expectedPath = new SchemaPath(path, true);
178         assertEquals(expectedPath, rp.getPath());
179         assertFalse(rp.isAddedByUses());
180         childNodes = rp.getChildNodes();
181         assertEquals(4, childNodes.size());
182         // * |-- |-- |-- leaf processing-rule
183         LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName("processing-rule");
184         assertNotNull(processingRule);
185         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
186         assertEquals(expectedQName, processingRule.getQName());
187         path.offer(expectedQName);
188         expectedPath = new SchemaPath(path, true);
189         assertEquals(expectedPath, processingRule.getPath());
190         assertEquals(BooleanType.getInstance(), processingRule.getType());
191         assertTrue(processingRule.isAddedByUses());
192         // * |-- |-- |-- leaf ignore
193         LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName("ignore");
194         assertNotNull(ignore);
195         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
196         assertEquals(expectedQName, ignore.getQName());
197         path.pollLast();
198         path.offer(expectedQName);
199         expectedPath = new SchemaPath(path, true);
200         assertEquals(expectedPath, ignore.getPath());
201         assertEquals(BooleanType.getInstance(), ignore.getType());
202         assertTrue(ignore.isAddedByUses());
203         // * |-- |-- |-- leaf priority
204         LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName("priority");
205         assertNotNull(priority);
206         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "priority");
207         assertEquals(expectedQName, priority.getQName());
208         path.pollLast();
209         path.offer(expectedQName);
210         expectedPath = new SchemaPath(path, true);
211         assertEquals(expectedPath, priority.getPath());
212         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "uint8");
213         path.offer(expectedQName);
214         expectedPath = new SchemaPath(path, true);
215         // TODO
216         //assertEquals(expectedPath, priority.getType().getPath());
217         assertEquals(Uint8.getInstance(), priority.getType().getBaseType());
218         assertTrue(priority.isAddedByUses());
219         // * |-- |-- |-- container box
220         ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName("box");
221         assertNotNull(box);
222         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "box");
223         assertEquals(expectedQName, box.getQName());
224         path.pollLast();
225         path.pollLast();
226         path.offer(expectedQName);
227         expectedPath = new SchemaPath(path, true);
228         assertEquals(expectedPath, box.getPath());
229         assertTrue(box.isAddedByUses());
230         // * |-- |-- |-- |-- container order
231         ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName("order");
232         assertNotNull(order);
233         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "order");
234         assertEquals(expectedQName, order.getQName());
235         path.offer(expectedQName);
236         expectedPath = new SchemaPath(path, true);
237         assertEquals(expectedPath, order.getPath());
238         assertFalse(order.isAddedByUses());
239         assertTrue(order.isAugmenting());
240         assertEquals(2, order.getChildNodes().size());
241         // * |-- |-- |-- |-- |-- leaf delete
242         LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName("delete");
243         assertNotNull(delete);
244         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "delete");
245         assertEquals(expectedQName, delete.getQName());
246         path.offer(expectedQName);
247         expectedPath = new SchemaPath(path, true);
248         assertEquals(expectedPath, delete.getPath());
249         assertEquals(Uint32.getInstance(), delete.getType());
250         assertTrue(delete.isAddedByUses());
251         // * |-- |-- |-- |-- |-- leaf setup
252         LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName("setup");
253         assertNotNull(setup);
254         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "setup");
255         assertEquals(expectedQName, setup.getQName());
256         path.pollLast();
257         path.offer(expectedQName);
258         expectedPath = new SchemaPath(path, true);
259         assertEquals(expectedPath, setup.getPath());
260         assertEquals(Uint32.getInstance(), setup.getType());
261         assertTrue(setup.isAddedByUses());
262         // * |-- |-- path-key-expansion
263         ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName("path-key-expansion");
264         assertNotNull(pke);
265         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "path-key-expansion");
266         assertEquals(expectedQName, pke.getQName());
267         path.pollLast();
268         path.pollLast();
269         path.pollLast();
270         path.pollLast();
271         path.offer(expectedQName);
272         expectedPath = new SchemaPath(path, true);
273         assertEquals(expectedPath, pke.getPath());
274         assertFalse(pke.isAddedByUses());
275         // * |-- |-- |-- path-key
276         ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName("path-key");
277         assertNotNull(pathKey);
278         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "path-key");
279         assertEquals(expectedQName, pathKey.getQName());
280         path.offer(expectedQName);
281         expectedPath= new SchemaPath(path, true);
282         assertEquals(expectedPath, pathKey.getPath());
283         assertFalse(pathKey.isAddedByUses());
284         assertEquals(3, pathKey.getChildNodes().size());
285         // * |-- |-- |-- |-- leaf processing-rule
286         processingRule = (LeafSchemaNode) pathKey.getDataChildByName("processing-rule");
287         assertNotNull(processingRule);
288         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
289         assertEquals(expectedQName, processingRule.getQName());
290         path.offer(expectedQName);
291         expectedPath= new SchemaPath(path, true);
292         assertEquals(expectedPath, processingRule.getPath());
293         assertEquals(BooleanType.getInstance(), processingRule.getType());
294         assertTrue(processingRule.isAddedByUses());
295         // * |-- |-- |-- |-- leaf ignore
296         ignore = (LeafSchemaNode) pathKey.getDataChildByName("ignore");
297         assertNotNull(ignore);
298         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
299         assertEquals(expectedQName, ignore.getQName());
300         path.pollLast();
301         path.offer(expectedQName);
302         expectedPath= new SchemaPath(path, true);
303         assertEquals(expectedPath, ignore.getPath());
304         assertEquals(BooleanType.getInstance(), ignore.getType());
305         assertTrue(ignore.isAddedByUses());
306         // * |-- |-- |-- |-- list path-keys
307         ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName("path-keys");
308         assertNotNull(pathKeys);
309         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "path-keys");
310         assertEquals(expectedQName, pathKeys.getQName());
311         path.pollLast();
312         path.offer(expectedQName);
313         expectedPath= new SchemaPath(path, true);
314         assertEquals(expectedPath, pathKeys.getPath());
315         assertTrue(pathKeys.isAddedByUses());
316         childNodes = pathKeys.getChildNodes();
317         assertEquals(2, childNodes.size());
318         // * |-- |-- |-- |-- |-- leaf version
319         version = (LeafSchemaNode) pathKeys.getDataChildByName("version");
320         assertNotNull(version);
321         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "version");
322         assertEquals(expectedQName, version.getQName());
323         path.offer(expectedQName);
324         expectedPath= new SchemaPath(path, true);
325         assertEquals(expectedPath, version.getPath());
326         assertTrue(version.getType() instanceof ExtendedType);
327         assertEquals(Uint8.getInstance(), version.getType().getBaseType());
328         assertTrue(version.isAddedByUses());
329         assertFalse(version.isAugmenting());
330         // * |-- |-- |-- |-- |-- leaf type
331         type = (LeafSchemaNode) pathKeys.getDataChildByName("type");
332         assertNotNull(type);
333         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "type");
334         assertEquals(expectedQName, type.getQName());
335         path.pollLast();
336         path.offer(expectedQName);
337         expectedPath= new SchemaPath(path, true);
338         assertEquals(expectedPath, type.getPath());
339         assertTrue(type.getType() instanceof ExtendedType);
340         assertTrue(type.isAddedByUses());
341         assertFalse(type.isAugmenting());
342         // * |-- |-- container segment-computation
343         ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName("segment-computation");
344         assertNotNull(sc);
345         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "segment-computation");
346         assertEquals(expectedQName, sc.getQName());
347         path.pollLast();
348         path.pollLast();
349         path.pollLast();
350         path.pollLast();
351         path.offer(expectedQName);
352         expectedPath= new SchemaPath(path, true);
353         assertEquals(expectedPath, sc.getPath());
354         assertFalse(sc.isAddedByUses());
355         // * |-- |-- |-- container p2p
356         ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName("p2p");
357         assertNotNull(p2p);
358         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "p2p");
359         assertEquals(expectedQName, p2p.getQName());
360         path.offer(expectedQName);
361         expectedPath= new SchemaPath(path, true);
362         assertEquals(expectedPath, p2p.getPath());
363         assertFalse(p2p.isAddedByUses());
364         // * |-- |-- |-- |-- container endpoints
365         ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName("endpoints");
366         assertNotNull(endpoints);
367         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "endpoints");
368         assertEquals(expectedQName, endpoints.getQName());
369         path.offer(expectedQName);
370         expectedPath= new SchemaPath(path, true);
371         assertEquals(expectedPath, endpoints.getPath());
372         assertFalse(endpoints.isAddedByUses());
373         // * |-- |-- |-- |-- |-- leaf processing-rule
374         processingRule = (LeafSchemaNode) endpoints.getDataChildByName("processing-rule");
375         assertNotNull(processingRule);
376         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
377         assertEquals(expectedQName, processingRule.getQName());
378         path.offer(expectedQName);
379         expectedPath= new SchemaPath(path, true);
380         assertEquals(expectedPath, processingRule.getPath());
381         assertEquals(BooleanType.getInstance(), processingRule.getType());
382         assertTrue(processingRule.isAddedByUses());
383         // * |-- |-- |-- |-- |-- leaf ignore
384         ignore = (LeafSchemaNode) endpoints.getDataChildByName("ignore");
385         assertNotNull(ignore);
386         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
387         assertEquals(expectedQName, ignore.getQName());
388         path.pollLast();
389         path.offer(expectedQName);
390         expectedPath= new SchemaPath(path, true);
391         assertEquals(expectedPath, ignore.getPath());
392         assertEquals(BooleanType.getInstance(), ignore.getType());
393         assertTrue(ignore.isAddedByUses());
394         // * |-- |-- |-- |-- |-- container box
395         box = (ContainerSchemaNode) endpoints.getDataChildByName("box");
396         assertNotNull(box);
397         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "box");
398         assertEquals(expectedQName, box.getQName());
399         path.pollLast();
400         path.offer(expectedQName);
401         expectedPath= new SchemaPath(path, true);
402         assertEquals(expectedPath, box.getPath());
403         assertTrue(box.isAddedByUses());
404         // * |-- |-- |-- |-- |-- choice address-family
405         ChoiceNode af = (ChoiceNode) endpoints.getDataChildByName("address-family");
406         assertNotNull(af);
407         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "address-family");
408         assertEquals(expectedQName, af.getQName());
409         path.pollLast();
410         path.offer(expectedQName);
411         expectedPath= new SchemaPath(path, true);
412         assertEquals(expectedPath, af.getPath());
413         assertTrue(af.isAddedByUses());
414         // * |-- |-- |-- |-- container reported-route
415         ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName("reported-route");
416         assertNotNull(reportedRoute);
417         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "reported-route");
418         assertEquals(expectedQName, reportedRoute.getQName());
419         path.pollLast();
420         path.pollLast();
421         path.offer(expectedQName);
422         expectedPath= new SchemaPath(path, true);
423         assertEquals(expectedPath, reportedRoute.getPath());
424         assertFalse(reportedRoute.isAddedByUses());
425         // * |-- |-- |-- |-- |-- leaf processing-rule
426         processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName("processing-rule");
427         assertNotNull(processingRule);
428         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
429         assertEquals(expectedQName, processingRule.getQName());
430         path.offer(expectedQName);
431         expectedPath= new SchemaPath(path, true);
432         assertEquals(expectedPath, processingRule.getPath());
433         assertEquals(BooleanType.getInstance(), processingRule.getType());
434         assertTrue(processingRule.isAddedByUses());
435         // * |-- |-- |-- |-- |-- leaf ignore
436         ignore = (LeafSchemaNode) reportedRoute.getDataChildByName("ignore");
437         assertNotNull(ignore);
438         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
439         assertEquals(expectedQName, ignore.getQName());
440         path.pollLast();
441         path.offer(expectedQName);
442         expectedPath= new SchemaPath(path, true);
443         assertEquals(expectedPath, ignore.getPath());
444         assertEquals(BooleanType.getInstance(), ignore.getType());
445         assertTrue(ignore.isAddedByUses());
446         // * |-- |-- |-- |-- |-- list subobjects
447         ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName("subobjects");
448         assertNotNull(subobjects);
449         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "subobjects");
450         assertEquals(expectedQName, subobjects.getQName());
451         path.pollLast();
452         path.offer(expectedQName);
453         expectedPath= new SchemaPath(path, true);
454         assertEquals(expectedPath, subobjects.getPath());
455         assertTrue(subobjects.isAddedByUses());
456         // * |-- |-- |-- |-- |-- container bandwidth
457         ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName("bandwidth");
458         assertNotNull(bandwidth);
459         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "bandwidth");
460         assertEquals(expectedQName, bandwidth.getQName());
461         path.pollLast();
462         path.offer(expectedQName);
463         expectedPath= new SchemaPath(path, true);
464         assertEquals(expectedPath, bandwidth.getPath());
465         assertFalse(bandwidth.isAddedByUses());
466         // * |-- |-- |-- |-- container bandwidth
467         bandwidth = (ContainerSchemaNode) p2p.getDataChildByName("bandwidth");
468         assertNotNull(bandwidth);
469         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "bandwidth");
470         assertEquals(expectedQName, bandwidth.getQName());
471         path.pollLast();
472         path.pollLast();
473         path.offer(expectedQName);
474         expectedPath= new SchemaPath(path, true);
475         assertEquals(expectedPath, bandwidth.getPath());
476         assertTrue(bandwidth.isAddedByUses());
477         // * |-- |-- |-- |-- |-- leaf processing-rule
478         processingRule = (LeafSchemaNode) bandwidth.getDataChildByName("processing-rule");
479         assertNotNull(processingRule);
480         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
481         assertEquals(expectedQName, processingRule.getQName());
482         path.offer(expectedQName);
483         expectedPath= new SchemaPath(path, true);
484         assertEquals(expectedPath, processingRule.getPath());
485         assertEquals(BooleanType.getInstance(), processingRule.getType());
486         assertTrue(processingRule.isAddedByUses());
487         // * |-- |-- |-- |-- |-- leaf ignore
488         ignore = (LeafSchemaNode) bandwidth.getDataChildByName("ignore");
489         assertNotNull(ignore);
490         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
491         assertEquals(expectedQName, ignore.getQName());
492         path.pollLast();
493         path.offer(expectedQName);
494         expectedPath= new SchemaPath(path, true);
495         assertEquals(expectedPath, ignore.getPath());
496         assertEquals(BooleanType.getInstance(), ignore.getType());
497         assertTrue(ignore.isAddedByUses());
498         // * |-- |-- |-- |-- |-- container bandwidth
499         ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName("bandwidth");
500         assertNotNull(bandwidthInner);
501         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "bandwidth");
502         assertEquals(expectedQName, bandwidth.getQName());
503         path.pollLast();
504         path.offer(expectedQName);
505         expectedPath= new SchemaPath(path, true);
506         assertEquals(expectedPath, bandwidthInner.getPath());
507         assertTrue(bandwidthInner.isAddedByUses());
508         // * |-- list svec
509         ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName("svec");
510         assertNotNull(svec);
511         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "svec");
512         assertEquals(expectedQName, svec.getQName());
513         path.pollLast();
514         path.pollLast();
515         path.pollLast();
516         path.pollLast();
517         path.pollLast();
518         path.offer(expectedQName);
519         expectedPath= new SchemaPath(path, true);
520         assertEquals(expectedPath, svec.getPath());
521         assertFalse(svec.isAddedByUses());
522         // * |-- |-- leaf link-diverse
523         LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName("link-diverse");
524         assertNotNull(linkDiverse);
525         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "link-diverse");
526         assertEquals(expectedQName, linkDiverse.getQName());
527         path.offer(expectedQName);
528         expectedPath= new SchemaPath(path, true);
529         assertEquals(expectedPath, linkDiverse.getPath());
530         assertEquals(BooleanType.getInstance(), linkDiverse.getType());
531         assertTrue(linkDiverse.isAddedByUses());
532         // * |-- |-- leaf processing-rule
533         processingRule = (LeafSchemaNode) svec.getDataChildByName("processing-rule");
534         assertNotNull(processingRule);
535         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
536         assertEquals(expectedQName, processingRule.getQName());
537         path.pollLast();
538         path.offer(expectedQName);
539         expectedPath= new SchemaPath(path, true);
540         assertEquals(expectedPath, processingRule.getPath());
541         assertEquals(BooleanType.getInstance(), processingRule.getType());
542         assertTrue(processingRule.isAddedByUses());
543         // * |-- |-- leaf ignore
544         ignore = (LeafSchemaNode) svec.getDataChildByName("ignore");
545         assertNotNull(ignore);
546         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
547         assertEquals(expectedQName, ignore.getQName());
548         path.pollLast();
549         path.offer(expectedQName);
550         expectedPath= new SchemaPath(path, true);
551         assertEquals(expectedPath, ignore.getPath());
552         assertEquals(BooleanType.getInstance(), ignore.getType());
553         assertTrue(ignore.isAddedByUses());
554         // * |-- |-- list metric
555         ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName("metric");
556         assertNotNull(metric);
557         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "metric");
558         assertEquals(expectedQName, metric.getQName());
559         path.pollLast();
560         path.offer(expectedQName);
561         expectedPath= new SchemaPath(path, true);
562         assertEquals(expectedPath, metric.getPath());
563         assertFalse(metric.isAddedByUses());
564         // * |-- |-- |-- leaf metric-type
565         LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName("metric-type");
566         assertNotNull(metricType);
567         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "metric-type");
568         assertEquals(expectedQName, metricType.getQName());
569         path.offer(expectedQName);
570         expectedPath= new SchemaPath(path, true);
571         assertEquals(expectedPath, metricType.getPath());
572         assertEquals(Uint8.getInstance(), metricType.getType());
573         assertTrue(metricType.isAddedByUses());
574         // * |-- |-- |-- box
575         box = (ContainerSchemaNode) metric.getDataChildByName("box");
576         assertNotNull(box);
577         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "box");
578         assertEquals(expectedQName, box.getQName());
579         path.pollLast();
580         path.offer(expectedQName);
581         expectedPath= new SchemaPath(path, true);
582         assertEquals(expectedPath, box.getPath());
583         assertTrue(box.isAddedByUses());
584         // * |-- |-- |-- leaf processing-rule
585         processingRule = (LeafSchemaNode) metric.getDataChildByName("processing-rule");
586         assertNotNull(processingRule);
587         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "processing-rule");
588         assertEquals(expectedQName, processingRule.getQName());
589         path.pollLast();
590         path.offer(expectedQName);
591         expectedPath= new SchemaPath(path, true);
592         assertEquals(expectedPath, processingRule.getPath());
593         assertEquals(BooleanType.getInstance(), processingRule.getType());
594         assertTrue(processingRule.isAddedByUses());
595         // * |-- |-- |-- leaf ignore
596         ignore = (LeafSchemaNode) metric.getDataChildByName("ignore");
597         assertNotNull(ignore);
598         expectedQName = new QName(UG_NS, UG_REV, UG_PREF, "ignore");
599         assertEquals(expectedQName, ignore.getQName());
600         path.pollLast();
601         path.offer(expectedQName);
602         expectedPath= new SchemaPath(path, true);
603         assertEquals(expectedPath, ignore.getPath());
604         assertEquals(BooleanType.getInstance(), ignore.getType());
605         assertTrue(ignore.isAddedByUses());
606     }
607
608     @Test
609     public void testTypedefs() throws FileNotFoundException {
610         modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
611         Module testModule = TestUtils.findModule(modules, "grouping-definitions");
612         Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
613
614         TypeDefinition<?> intExt = null;
615         for(TypeDefinition<?> td : types) {
616             if("int-ext".equals(td.getQName().getLocalName())) {
617                 intExt = td;
618             }
619         }
620         assertNotNull(intExt);
621
622         List<QName> path = Lists.newArrayList(new QName(GD_NS, GD_REV, GD_PREF, "int-ext"));
623         SchemaPath expectedPath = new SchemaPath(path, true);
624         assertEquals(expectedPath, intExt.getPath());
625
626         UnionType union = (UnionType)intExt.getBaseType();
627
628         TypeDefinition<?> uint8 = null;
629         TypeDefinition<?> pv = null;
630         for(TypeDefinition<?> td : union.getTypes()) {
631             if("uint8".equals(td.getQName().getLocalName())) {
632                 uint8 = td;
633             } else if("protocol-version".equals(td.getQName().getLocalName())) {
634                 pv = td;
635             }
636         }
637         assertNotNull(uint8);
638         assertNotNull(pv);
639
640         QName q1 = BaseTypes.constructQName("union");
641         expectedPath = new SchemaPath(Lists.newArrayList(q1), true);
642         assertEquals(expectedPath, union.getPath());
643     }
644
645 }