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