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