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