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