Fixed bug in uses statement resolving.
[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.*;
11
12 import java.io.FileNotFoundException;
13 import java.net.URI;
14 import java.text.ParseException;
15 import java.util.ArrayList;
16 import java.util.Date;
17 import java.util.List;
18 import java.util.Set;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
24 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.Module;
29 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
30 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
31 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
32 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
33 import org.opendaylight.yangtools.yang.model.util.UnionType;
34
35 import com.google.common.collect.Lists;
36
37 public class UsesAugmentTest {
38     private final URI ns = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping");
39     private Date rev;
40     private final String prefix = "ug";
41
42     private Set<Module> modules;
43
44     @Before
45     public void init() throws FileNotFoundException, ParseException {
46         rev = TestUtils.simpleDateFormat.parse("2013-07-30");
47     }
48
49     /**
50      * Structure of testing model:
51      *
52      * notification pcreq
53      * |-- leaf version (U)
54      * |-- leaf type (U)
55      * |-- list requests
56      * |-- |-- container rp
57      * |-- |-- |-- leaf priority (U)
58      * |-- |-- |-- container box (U)
59      * |-- |-- |-- |-- container order (A)
60      * |-- |-- |-- |-- |-- leaf delete (U)
61      * |-- |-- |-- |-- |-- |-- leaf setup (U)
62      * |-- |-- |-- leaf processing-rule (U)
63      * |-- |-- |-- leaf ignore (U)
64      * |-- |-- path-key-expansion
65      * |-- |-- |-- container path-key
66      * |-- |-- |-- |-- list path-keys (U)
67      * |-- |-- |-- |-- |-- leaf version (U)
68      * |-- |-- |-- |-- |-- leaf type (U)
69      * |-- |-- |-- |-- |-- leaf processing-rule (U)
70      * |-- |-- |-- |-- |-- leaf ignore (U)
71      * |-- |-- container segment-computation
72      * |-- |-- |-- container p2p
73      * |-- |-- |-- |-- container endpoints
74      * |-- |-- |-- |-- |-- leaf processing-rule (U)
75      * |-- |-- |-- |-- |-- leaf ignore (U)
76      * |-- |-- |-- |-- |-- container box (U)
77      * |-- |-- |-- |-- |-- choice address-family (U)
78      * |-- |-- |-- |-- |-- |-- case ipv4
79      * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address
80      * |-- |-- |-- |-- |-- |-- case ipv6
81      * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address
82      * |-- |-- |-- |-- container reported-route
83      * |-- |-- |-- |-- |-- container bandwidth
84      * |-- |-- |-- |-- |-- list subobjects(U)
85      * |-- |-- |-- |-- |-- leaf processing-rule (U)
86      * |-- |-- |-- |-- |-- leaf ignore (U)
87      * |-- |-- |-- |-- container bandwidth (U)
88      * |-- |-- |-- |-- |-- container bandwidth (U)
89      * |-- |-- |-- |-- |-- leaf processing-rule (U)
90      * |-- |-- |-- |-- |-- leaf ignore (U)
91      * |-- list svec
92      * |-- |-- list metric
93      * |-- |-- |-- leaf metric-type (U)
94      * |-- |-- |-- container box (U)
95      * |-- |-- |-- leaf processing-rule (U)
96      * |-- |-- |-- leaf ignore (U)
97      * |-- |-- leaf link-diverse (U)
98      * |-- |-- leaf processing-rule (U)
99      * |-- |-- leaf ignore (U)
100      *
101      * U = added by uses A = added by augment
102      */
103     @Test
104     public void testAugmentInUses() throws Exception {
105         modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
106         Module testModule = TestUtils.findModule(modules, "uses-grouping");
107
108         // * notification pcreq
109         Set<NotificationDefinition> notifications = testModule.getNotifications();
110         assertEquals(1, notifications.size());
111         NotificationDefinition pcreq = notifications.iterator().next();
112         assertNotNull(pcreq);
113         assertEquals(createPath("pcreq"), pcreq.getPath());
114         Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
115         assertEquals(4, childNodes.size());
116         // * |-- leaf version (U)
117         LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
118         assertNotNull(version);
119         assertEquals(createPath("pcreq", "version"), version.getPath());
120         assertEquals(createPath("pcreq", "version", "protocol-version"), version.getType().getPath());
121         assertEquals(createPathForYangType("pcreq", "version", "protocol-version", "uint8"), version.getType()
122                 .getBaseType().getPath());
123         assertTrue(version.isAddedByUses());
124         // * |-- leaf type (U)
125         LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName("type");
126         assertNotNull(type);
127         assertTrue(type.isAddedByUses());
128         assertEquals(createPath("pcreq", "type"), type.getPath());
129         assertEquals(createPath("pcreq", "type", "int-ext"), type.getType().getPath());
130         UnionType union = (UnionType)type.getType().getBaseType();
131         assertEquals(createPathForYangType("pcreq", "type", "int-ext", "union"), union.getPath());
132         assertEquals(2, union.getTypes().size());
133         // * |-- list requests
134         ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName("requests");
135         assertNotNull(requests);
136         assertEquals(createPath("pcreq", "requests"), requests.getPath());
137         assertFalse(requests.isAddedByUses());
138         childNodes = requests.getChildNodes();
139         assertEquals(3, childNodes.size());
140         // * |-- |-- container rp
141         ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName("rp");
142         assertNotNull(rp);
143         assertEquals(createPath("pcreq", "requests", "rp"), rp.getPath());
144         assertFalse(rp.isAddedByUses());
145         childNodes = rp.getChildNodes();
146         assertEquals(4, childNodes.size());
147         // * |-- |-- |-- leaf priority (U)
148         LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName("priority");
149         assertNotNull(priority);
150         assertEquals(createPath("pcreq", "requests", "rp", "priority"), priority.getPath());
151         assertEquals(createPath("pcreq", "requests", "rp", "priority", "uint8"), priority.getType().getPath());
152         assertEquals(createPathForYangType("pcreq", "requests", "rp", "priority", "uint8", "uint8"), priority.getType()
153                 .getBaseType().getPath());
154         assertTrue(priority.isAddedByUses());
155         // * |-- |-- |-- container box (U)
156         ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName("box");
157         assertNotNull(box);
158         assertEquals(createPath("pcreq", "requests", "rp", "box"), box.getPath());
159         assertTrue(box.isAddedByUses());
160         // * |-- |-- |-- |-- container order (A)
161         ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName("order");
162         assertNotNull(order);
163         assertEquals(createPath("pcreq", "requests", "rp", "box", "order"), order.getPath());
164         assertFalse(order.isAddedByUses());
165         assertTrue(order.isAugmenting());
166         assertEquals(2, order.getChildNodes().size());
167         // * |-- |-- |-- |-- |-- leaf delete (U)
168         LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName("delete");
169         assertNotNull(delete);
170         assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "delete"), delete.getPath());
171         assertEquals(createPathForYangType("pcreq", "requests", "rp", "box", "order", "delete", "uint32"), delete
172                 .getType().getPath());
173         assertTrue(delete.isAddedByUses());
174         // * |-- |-- |-- |-- |-- leaf ignore (U)
175         LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName("setup");
176         assertNotNull(setup);
177         assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "setup"), setup.getPath());
178         assertEquals(createPathForYangType("pcreq", "requests", "rp", "box", "order", "setup", "uint32"), setup
179                 .getType().getPath());
180         assertTrue(setup.isAddedByUses());
181         // * |-- |-- |-- leaf processing-rule (U)
182         LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName("processing-rule");
183         assertNotNull(processingRule);
184         assertEquals(createPath("pcreq", "requests", "rp", "processing-rule"), processingRule.getPath());
185         assertEquals(createPathForYangType("pcreq", "requests", "rp", "processing-rule", "boolean"), processingRule
186                 .getType().getPath());
187         assertTrue(processingRule.isAddedByUses());
188         // * |-- |-- |-- leaf ignore (U)
189         LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName("ignore");
190         assertNotNull(ignore);
191         assertEquals(createPath("pcreq", "requests", "rp", "ignore"), ignore.getPath());
192         assertEquals(createPathForYangType("pcreq", "requests", "rp", "ignore", "boolean"), ignore.getType().getPath());
193         assertTrue(ignore.isAddedByUses());
194         // * |-- |-- path-key-expansion
195         ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName("path-key-expansion");
196         assertNotNull(pke);
197         assertEquals(createPath("pcreq", "requests", "path-key-expansion"), pke.getPath());
198         assertFalse(pke.isAddedByUses());
199         // * |-- |-- |-- path-key
200         ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName("path-key");
201         assertNotNull(pathKey);
202         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key"), pathKey.getPath());
203         assertFalse(pathKey.isAddedByUses());
204         assertEquals(3, pathKey.getChildNodes().size());
205         // * |-- |-- |-- |-- list path-keys (U)
206         ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName("path-keys");
207         assertNotNull(pathKeys);
208         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys"), pathKeys.getPath());
209         assertTrue(pathKeys.isAddedByUses());
210         childNodes = pathKeys.getChildNodes();
211         assertEquals(2, childNodes.size());
212         // * |-- |-- |-- |-- |-- leaf version (U)
213         version = (LeafSchemaNode) pathKeys.getDataChildByName("version");
214         assertNotNull(version);
215         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version"),
216                 version.getPath());
217         assertEquals(
218                 createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version",
219                         "protocol-version"), version.getType().getPath());
220         assertEquals(
221                 createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version",
222                         "protocol-version", "uint8"), version.getType().getBaseType().getPath());
223         assertTrue(version.isAddedByUses());
224         assertFalse(version.isAugmenting());
225         // * |-- |-- |-- |-- |-- leaf type (U)
226         type = (LeafSchemaNode) pathKeys.getDataChildByName("type");
227         assertNotNull(type);
228         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type"),
229                 type.getPath());
230         assertEquals(
231                 createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type",
232                         "int-ext"), type.getType().getPath());
233         assertEquals(
234                 createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type",
235                         "int-ext", "union"), type.getType().getBaseType().getPath());
236         assertTrue(type.isAddedByUses());
237         assertFalse(type.isAugmenting());
238         // * |-- |-- |-- |-- |-- leaf processing-rule (U)
239         processingRule = (LeafSchemaNode) pathKey.getDataChildByName("processing-rule");
240         assertNotNull(processingRule);
241         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule"),
242                 processingRule.getPath());
243         assertEquals(
244                 createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule",
245                         "boolean"), processingRule.getType().getPath());
246         assertTrue(processingRule.isAddedByUses());
247         // * |-- |-- |-- |-- |-- leaf ignore (U)
248         ignore = (LeafSchemaNode) pathKey.getDataChildByName("ignore");
249         assertNotNull(ignore);
250         assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "ignore"), ignore.getPath());
251         assertEquals(createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "ignore", "boolean"),
252                 ignore.getType().getPath());
253         assertTrue(ignore.isAddedByUses());
254         // * |-- |-- container segment-computation
255         ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName("segment-computation");
256         assertNotNull(sc);
257         assertEquals(createPath("pcreq", "requests", "segment-computation"), sc.getPath());
258         assertFalse(sc.isAddedByUses());
259         // * |-- |-- |-- container p2p
260         ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName("p2p");
261         assertNotNull(p2p);
262         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p"), p2p.getPath());
263         assertFalse(p2p.isAddedByUses());
264         // * |-- |-- |-- |-- container endpoints
265         ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName("endpoints");
266         assertNotNull(endpoints);
267         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints"), endpoints.getPath());
268         assertFalse(endpoints.isAddedByUses());
269         // * |-- |-- |-- |-- |-- leaf processing-rule (U)
270         processingRule = (LeafSchemaNode) endpoints.getDataChildByName("processing-rule");
271         assertNotNull(processingRule);
272         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "processing-rule"),
273                 processingRule.getPath());
274         assertEquals(
275                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "endpoints",
276                         "processing-rule", "boolean"), processingRule.getType().getPath());
277         assertTrue(processingRule.isAddedByUses());
278         // * |-- |-- |-- |-- |-- leaf ignore (U)
279         ignore = (LeafSchemaNode) endpoints.getDataChildByName("ignore");
280         assertNotNull(ignore);
281         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore"),
282                 ignore.getPath());
283         assertEquals(
284                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore",
285                         "boolean"), ignore.getType().getPath());
286         assertTrue(ignore.isAddedByUses());
287         // * |-- |-- |-- |-- |-- container box
288         box = (ContainerSchemaNode) endpoints.getDataChildByName("box");
289         assertNotNull(box);
290         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "box"), box.getPath());
291         assertTrue(box.isAddedByUses());
292         // * |-- |-- |-- |-- |-- choice address-family (U)
293         ChoiceNode af = (ChoiceNode) endpoints.getDataChildByName("address-family");
294         assertNotNull(af);
295         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "address-family"),
296                 af.getPath());
297         assertTrue(af.isAddedByUses());
298         // * |-- |-- |-- |-- container reported-route
299         ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName("reported-route");
300         assertNotNull(reportedRoute);
301         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route"),
302                 reportedRoute.getPath());
303         assertFalse(reportedRoute.isAddedByUses());
304         // * |-- |-- |-- |-- |-- container bandwidth
305         ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName("bandwidth");
306         assertNotNull(bandwidth);
307         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "bandwidth"),
308                 bandwidth.getPath());
309         assertFalse(bandwidth.isAddedByUses());
310         // * |-- |-- |-- |-- |-- list subobjects
311         ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName("subobjects");
312         assertNotNull(subobjects);
313         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "subobjects"),
314                 subobjects.getPath());
315         assertTrue(subobjects.isAddedByUses());
316         // * |-- |-- |-- |-- |-- leaf processing-rule (U)
317         processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName("processing-rule");
318         assertNotNull(processingRule);
319         assertEquals(
320                 createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "processing-rule"),
321                 processingRule.getPath());
322         assertEquals(
323                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "reported-route",
324                         "processing-rule", "boolean"), processingRule.getType().getPath());
325         assertTrue(processingRule.isAddedByUses());
326         // * |-- |-- |-- |-- |-- leaf ignore (U)
327         ignore = (LeafSchemaNode) reportedRoute.getDataChildByName("ignore");
328         assertNotNull(ignore);
329         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore"),
330                 ignore.getPath());
331         assertEquals(
332                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore",
333                         "boolean"), ignore.getType().getPath());
334         assertTrue(ignore.isAddedByUses());
335         // * |-- |-- |-- |-- container bandwidth (U)
336         bandwidth = (ContainerSchemaNode) p2p.getDataChildByName("bandwidth");
337         assertNotNull(bandwidth);
338         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth"), bandwidth.getPath());
339         assertTrue(bandwidth.isAddedByUses());
340         // * |-- |-- |-- |-- |-- container bandwidth (U)
341         ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName("bandwidth");
342         assertNotNull(bandwidthInner);
343         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "bandwidth"),
344                 bandwidthInner.getPath());
345         assertTrue(bandwidthInner.isAddedByUses());
346         // * |-- |-- |-- |-- |-- leaf processing-rule (U)
347         processingRule = (LeafSchemaNode) bandwidth.getDataChildByName("processing-rule");
348         assertNotNull(processingRule);
349         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "processing-rule"),
350                 processingRule.getPath());
351         assertEquals(
352                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "bandwidth",
353                         "processing-rule", "boolean"), processingRule.getType().getPath());
354         assertTrue(processingRule.isAddedByUses());
355         // * |-- |-- |-- |-- |-- leaf ignore (U)
356         ignore = (LeafSchemaNode) bandwidth.getDataChildByName("ignore");
357         assertNotNull(ignore);
358         assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore"),
359                 ignore.getPath());
360         assertEquals(
361                 createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore",
362                         "boolean"), ignore.getType().getPath());
363         assertTrue(ignore.isAddedByUses());
364         // * |-- list svec
365         ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName("svec");
366         assertNotNull(svec);
367         assertEquals(createPath("pcreq", "svec"), svec.getPath());
368         assertFalse(svec.isAddedByUses());
369         // * |-- |-- list metric
370         ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName("metric");
371         assertNotNull(metric);
372         assertEquals(createPath("pcreq", "svec", "metric"), metric.getPath());
373         assertFalse(metric.isAddedByUses());
374         // * |-- |-- |-- leaf metric-type (U)
375         LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName("metric-type");
376         assertNotNull(metricType);
377         assertEquals(createPath("pcreq", "svec", "metric", "metric-type"), metricType.getPath());
378         assertEquals(createPathForYangType("pcreq", "svec", "metric", "metric-type", "uint8"), metricType.getType()
379                 .getPath());
380         assertTrue(metricType.isAddedByUses());
381         // * |-- |-- |-- box (U)
382         box = (ContainerSchemaNode) metric.getDataChildByName("box");
383         assertNotNull(box);
384         assertEquals(createPath("pcreq", "svec", "metric", "box"), box.getPath());
385         assertTrue(box.isAddedByUses());
386         // * |-- |-- |-- leaf processing-rule (U)
387         processingRule = (LeafSchemaNode) metric.getDataChildByName("processing-rule");
388         assertNotNull(processingRule);
389         assertEquals(createPath("pcreq", "svec", "metric", "processing-rule"), processingRule.getPath());
390         assertEquals(createPathForYangType("pcreq", "svec", "metric", "processing-rule", "boolean"), processingRule
391                 .getType().getPath());
392         assertTrue(processingRule.isAddedByUses());
393         // * |-- |-- |-- leaf ignore (U)
394         ignore = (LeafSchemaNode) metric.getDataChildByName("ignore");
395         assertNotNull(ignore);
396         assertEquals(createPath("pcreq", "svec", "metric", "ignore"), ignore.getPath());
397         assertEquals(createPathForYangType("pcreq", "svec", "metric", "ignore", "boolean"), ignore.getType().getPath());
398         assertTrue(ignore.isAddedByUses());
399         // * |-- |-- leaf link-diverse (U)
400         LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName("link-diverse");
401         assertNotNull(linkDiverse);
402         assertEquals(createPath("pcreq", "svec", "link-diverse"), linkDiverse.getPath());
403         assertEquals(createPathForYangType("pcreq", "svec", "link-diverse", "boolean"), linkDiverse.getType().getPath());
404         assertTrue(linkDiverse.isAddedByUses());
405         // * |-- |-- leaf processing-rule (U)
406         processingRule = (LeafSchemaNode) svec.getDataChildByName("processing-rule");
407         assertNotNull(processingRule);
408         assertEquals(createPath("pcreq", "svec", "processing-rule"), processingRule.getPath());
409         assertEquals(createPathForYangType("pcreq", "svec", "processing-rule", "boolean"), processingRule.getType()
410                 .getPath());
411         assertTrue(processingRule.isAddedByUses());
412         // * |-- |-- leaf ignore (U)
413         ignore = (LeafSchemaNode) svec.getDataChildByName("ignore");
414         assertNotNull(ignore);
415         assertEquals(createPath("pcreq", "svec", "ignore"), ignore.getPath());
416         assertEquals(createPathForYangType("pcreq", "svec", "ignore", "boolean"), ignore.getType().getPath());
417         assertTrue(ignore.isAddedByUses());
418     }
419
420     private SchemaPath createPath(String... names) {
421         List<QName> path = new ArrayList<>();
422         for (String name : names) {
423             path.add(new QName(ns, rev, prefix, name));
424         }
425         return new SchemaPath(path, true);
426     }
427
428     private SchemaPath createPathForYangType(String... names) {
429         List<QName> path = new ArrayList<>();
430         for (int i = 0; i < names.length - 1; i++) {
431             path.add(new QName(ns, rev, prefix, names[i]));
432         }
433         path.add(new QName(URI.create("urn:ietf:params:xml:ns:yang:1"), names[names.length - 1]));
434         return new SchemaPath(path, true);
435     }
436
437     @Test
438     public void testTypedefs() throws FileNotFoundException {
439         modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
440         Module testModule = TestUtils.findModule(modules, "uses-grouping");
441         Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
442
443         TypeDefinition<?> intExt = null;
444         for(TypeDefinition<?> td : types) {
445             if("int-ext".equals(td.getQName().getLocalName())) {
446                 intExt = td;
447             }
448         }
449         assertNotNull(intExt);
450         assertEquals(createPath("int-ext"), intExt.getPath());
451
452         UnionType union = (UnionType)intExt.getBaseType();
453
454         TypeDefinition<?> uint8 = null;
455         TypeDefinition<?> pv = null;
456         for(TypeDefinition<?> td : union.getTypes()) {
457             if("uint8".equals(td.getQName().getLocalName())) {
458                 uint8 = td;
459             } else if("protocol-version".equals(td.getQName().getLocalName())) {
460                 pv = td;
461             }
462         }
463         assertNotNull(uint8);
464         assertNotNull(pv);
465
466         SchemaPath expectedPath = null;
467         QName q0 = new QName(ns, rev, prefix, "int-ext");
468         QName q1 = BaseTypes.constructQName("union");
469
470         expectedPath = new SchemaPath(Lists.newArrayList(q0, q1), true);
471         assertEquals(expectedPath, union.getPath());
472     }
473
474 }