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