2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.impl;
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;
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;
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;
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");
52 private Set<Module> modules;
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");
62 * Structure of testing model:
65 * |-- leaf version (U)
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)
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)
113 * U = added by uses A = added by augment
115 * @throws Exception if exception occurs
118 public void testAugmentInUses() throws Exception {
119 modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
120 Module testModule = TestUtils.findModule(modules, "uses-grouping");
122 LinkedList<QName> path = new LinkedList<>();
124 // * notification pcreq
125 Set<NotificationDefinition> notifications = testModule.getNotifications();
126 assertEquals(1, notifications.size());
127 NotificationDefinition pcreq = notifications.iterator().next();
128 assertNotNull(pcreq);
129 QName expectedQName = QName.create(UG_NS, UG_REV, "pcreq");
130 path.offer(expectedQName);
131 SchemaPath expectedPath = SchemaPath.create(path, true);
132 assertEquals(expectedPath, pcreq.getPath());
133 Collection<DataSchemaNode> childNodes = pcreq.getChildNodes();
134 assertEquals(4, childNodes.size());
135 // * |-- leaf version
136 LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
137 assertNotNull(version);
138 expectedQName = QName.create(UG_NS, UG_REV, "version");
139 path.offer(expectedQName);
140 expectedPath = SchemaPath.create(path, true);
141 assertEquals(expectedPath, version.getPath());
142 expectedQName = QName.create(GD_NS, GD_REV, "protocol-version");
143 path.offer(expectedQName);
144 expectedPath = SchemaPath.create(Lists.newArrayList(expectedQName), true);
145 assertEquals(expectedPath, version.getType().getPath());
146 assertEquals(Uint8.getInstance(), version.getType().getBaseType());
147 assertTrue(version.isAddedByUses());
149 LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName("type");
151 expectedQName = QName.create(UG_NS, UG_REV, "type");
152 assertTrue(type.isAddedByUses());
155 path.offer(expectedQName);
156 expectedPath = SchemaPath.create(path, true);
157 assertEquals(expectedPath, type.getPath());
158 expectedQName = QName.create(GD_NS, GD_REV, "int-ext");
159 path.offer(expectedQName);
160 expectedPath = SchemaPath.create(Lists.newArrayList(expectedQName), true);
161 assertEquals(expectedPath, type.getType().getPath());
162 UnionType union = (UnionType)type.getType().getBaseType();
163 assertEquals(SchemaPath.create(true, BaseTypes.constructQName("union")), union.getPath());
164 assertEquals(2, union.getTypes().size());
165 // * |-- list requests
166 ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName("requests");
167 assertNotNull(requests);
168 expectedQName = QName.create(UG_NS, UG_REV, "requests");
169 assertEquals(expectedQName, requests.getQName());
172 path.offer(expectedQName);
173 expectedPath = SchemaPath.create(path, true);
174 assertEquals(expectedPath, requests.getPath());
175 assertFalse(requests.isAddedByUses());
176 childNodes = requests.getChildNodes();
177 assertEquals(3, childNodes.size());
178 // * |-- |-- container rp
179 ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName("rp");
181 expectedQName = QName.create(UG_NS, UG_REV, "rp");
182 path.offer(expectedQName);
183 expectedPath = SchemaPath.create(path, true);
184 assertEquals(expectedPath, rp.getPath());
185 assertFalse(rp.isAddedByUses());
186 childNodes = rp.getChildNodes();
187 assertEquals(4, childNodes.size());
188 // * |-- |-- |-- leaf processing-rule
189 LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName("processing-rule");
190 assertNotNull(processingRule);
191 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
192 assertEquals(expectedQName, processingRule.getQName());
193 path.offer(expectedQName);
194 expectedPath = SchemaPath.create(path, true);
195 assertEquals(expectedPath, processingRule.getPath());
196 assertEquals(BooleanType.getInstance(), processingRule.getType());
197 assertTrue(processingRule.isAddedByUses());
198 // * |-- |-- |-- leaf ignore
199 LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName("ignore");
200 assertNotNull(ignore);
201 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
202 assertEquals(expectedQName, ignore.getQName());
204 path.offer(expectedQName);
205 expectedPath = SchemaPath.create(path, true);
206 assertEquals(expectedPath, ignore.getPath());
207 assertEquals(BooleanType.getInstance(), ignore.getType());
208 assertTrue(ignore.isAddedByUses());
209 // * |-- |-- |-- leaf priority
210 LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName("priority");
211 assertNotNull(priority);
212 expectedQName = QName.create(UG_NS, UG_REV, "priority");
213 assertEquals(expectedQName, priority.getQName());
215 path.offer(expectedQName);
216 expectedPath = SchemaPath.create(path, true);
217 assertEquals(expectedPath, priority.getPath());
218 expectedQName = QName.create(UG_NS, UG_REV, "uint8");
219 path.offer(expectedQName);
220 expectedPath = SchemaPath.create(path, true);
222 //assertEquals(expectedPath, priority.getType().getPath());
223 assertEquals(Uint8.getInstance(), priority.getType().getBaseType());
224 assertTrue(priority.isAddedByUses());
225 // * |-- |-- |-- container box
226 ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName("box");
228 expectedQName = QName.create(UG_NS, UG_REV, "box");
229 assertEquals(expectedQName, box.getQName());
232 path.offer(expectedQName);
233 expectedPath = SchemaPath.create(path, true);
234 assertEquals(expectedPath, box.getPath());
235 assertTrue(box.isAddedByUses());
236 // * |-- |-- |-- |-- container order
237 ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName("order");
238 assertNotNull(order);
239 expectedQName = QName.create(UG_NS, UG_REV, "order");
240 assertEquals(expectedQName, order.getQName());
241 path.offer(expectedQName);
242 expectedPath = SchemaPath.create(path, true);
243 assertEquals(expectedPath, order.getPath());
244 assertTrue(order.isAddedByUses());
245 assertTrue(order.isAugmenting());
246 assertEquals(2, order.getChildNodes().size());
247 // * |-- |-- |-- |-- |-- leaf delete
248 LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName("delete");
249 assertNotNull(delete);
250 expectedQName = QName.create(UG_NS, UG_REV, "delete");
251 assertEquals(expectedQName, delete.getQName());
252 path.offer(expectedQName);
253 expectedPath = SchemaPath.create(path, true);
254 assertEquals(expectedPath, delete.getPath());
255 assertEquals(Uint32.getInstance(), delete.getType());
256 assertTrue(delete.isAddedByUses());
257 // * |-- |-- |-- |-- |-- leaf setup
258 LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName("setup");
259 assertNotNull(setup);
260 expectedQName = QName.create(UG_NS, UG_REV, "setup");
261 assertEquals(expectedQName, setup.getQName());
263 path.offer(expectedQName);
264 expectedPath = SchemaPath.create(path, true);
265 assertEquals(expectedPath, setup.getPath());
266 assertEquals(Uint32.getInstance(), setup.getType());
267 assertTrue(setup.isAddedByUses());
268 // * |-- |-- path-key-expansion
269 ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName("path-key-expansion");
271 expectedQName = QName.create(UG_NS, UG_REV, "path-key-expansion");
272 assertEquals(expectedQName, pke.getQName());
277 path.offer(expectedQName);
278 expectedPath = SchemaPath.create(path, true);
279 assertEquals(expectedPath, pke.getPath());
280 assertFalse(pke.isAddedByUses());
281 // * |-- |-- |-- path-key
282 ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName("path-key");
283 assertNotNull(pathKey);
284 expectedQName = QName.create(UG_NS, UG_REV, "path-key");
285 assertEquals(expectedQName, pathKey.getQName());
286 path.offer(expectedQName);
287 expectedPath= SchemaPath.create(path, true);
288 assertEquals(expectedPath, pathKey.getPath());
289 assertFalse(pathKey.isAddedByUses());
290 assertEquals(3, pathKey.getChildNodes().size());
291 // * |-- |-- |-- |-- leaf processing-rule
292 processingRule = (LeafSchemaNode) pathKey.getDataChildByName("processing-rule");
293 assertNotNull(processingRule);
294 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
295 assertEquals(expectedQName, processingRule.getQName());
296 path.offer(expectedQName);
297 expectedPath= SchemaPath.create(path, true);
298 assertEquals(expectedPath, processingRule.getPath());
299 assertEquals(BooleanType.getInstance(), processingRule.getType());
300 assertTrue(processingRule.isAddedByUses());
301 // * |-- |-- |-- |-- leaf ignore
302 ignore = (LeafSchemaNode) pathKey.getDataChildByName("ignore");
303 assertNotNull(ignore);
304 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
305 assertEquals(expectedQName, ignore.getQName());
307 path.offer(expectedQName);
308 expectedPath= SchemaPath.create(path, true);
309 assertEquals(expectedPath, ignore.getPath());
310 assertEquals(BooleanType.getInstance(), ignore.getType());
311 assertTrue(ignore.isAddedByUses());
312 // * |-- |-- |-- |-- list path-keys
313 ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName("path-keys");
314 assertNotNull(pathKeys);
315 expectedQName = QName.create(UG_NS, UG_REV, "path-keys");
316 assertEquals(expectedQName, pathKeys.getQName());
318 path.offer(expectedQName);
319 expectedPath= SchemaPath.create(path, true);
320 assertEquals(expectedPath, pathKeys.getPath());
321 assertTrue(pathKeys.isAddedByUses());
322 childNodes = pathKeys.getChildNodes();
323 assertEquals(2, childNodes.size());
324 // * |-- |-- |-- |-- |-- leaf version
325 version = (LeafSchemaNode) pathKeys.getDataChildByName("version");
326 assertNotNull(version);
327 expectedQName = QName.create(UG_NS, UG_REV, "version");
328 assertEquals(expectedQName, version.getQName());
329 path.offer(expectedQName);
330 expectedPath= SchemaPath.create(path, true);
331 assertEquals(expectedPath, version.getPath());
332 assertTrue(version.getType() instanceof ExtendedType);
333 assertEquals(Uint8.getInstance(), version.getType().getBaseType());
334 assertTrue(version.isAddedByUses());
335 assertTrue(version.isAugmenting());
336 // * |-- |-- |-- |-- |-- leaf type
337 type = (LeafSchemaNode) pathKeys.getDataChildByName("type");
339 expectedQName = QName.create(UG_NS, UG_REV, "type");
340 assertEquals(expectedQName, type.getQName());
342 path.offer(expectedQName);
343 expectedPath= SchemaPath.create(path, true);
344 assertEquals(expectedPath, type.getPath());
345 assertTrue(type.getType() instanceof ExtendedType);
346 assertTrue(type.isAddedByUses());
347 assertTrue(type.isAugmenting());
348 // * |-- |-- container segment-computation
349 ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName("segment-computation");
351 expectedQName = QName.create(UG_NS, UG_REV, "segment-computation");
352 assertEquals(expectedQName, sc.getQName());
357 path.offer(expectedQName);
358 expectedPath= SchemaPath.create(path, true);
359 assertEquals(expectedPath, sc.getPath());
360 assertFalse(sc.isAddedByUses());
361 // * |-- |-- |-- container p2p
362 ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName("p2p");
364 expectedQName = QName.create(UG_NS, UG_REV, "p2p");
365 assertEquals(expectedQName, p2p.getQName());
366 path.offer(expectedQName);
367 expectedPath= SchemaPath.create(path, true);
368 assertEquals(expectedPath, p2p.getPath());
369 assertFalse(p2p.isAddedByUses());
370 // * |-- |-- |-- |-- container endpoints
371 ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName("endpoints");
372 assertNotNull(endpoints);
373 expectedQName = QName.create(UG_NS, UG_REV, "endpoints");
374 assertEquals(expectedQName, endpoints.getQName());
375 path.offer(expectedQName);
376 expectedPath= SchemaPath.create(path, true);
377 assertEquals(expectedPath, endpoints.getPath());
378 assertFalse(endpoints.isAddedByUses());
379 // * |-- |-- |-- |-- |-- leaf processing-rule
380 processingRule = (LeafSchemaNode) endpoints.getDataChildByName("processing-rule");
381 assertNotNull(processingRule);
382 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
383 assertEquals(expectedQName, processingRule.getQName());
384 path.offer(expectedQName);
385 expectedPath= SchemaPath.create(path, true);
386 assertEquals(expectedPath, processingRule.getPath());
387 assertEquals(BooleanType.getInstance(), processingRule.getType());
388 assertTrue(processingRule.isAddedByUses());
389 // * |-- |-- |-- |-- |-- leaf ignore
390 ignore = (LeafSchemaNode) endpoints.getDataChildByName("ignore");
391 assertNotNull(ignore);
392 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
393 assertEquals(expectedQName, ignore.getQName());
395 path.offer(expectedQName);
396 expectedPath= SchemaPath.create(path, true);
397 assertEquals(expectedPath, ignore.getPath());
398 assertEquals(BooleanType.getInstance(), ignore.getType());
399 assertTrue(ignore.isAddedByUses());
400 // * |-- |-- |-- |-- |-- container box
401 box = (ContainerSchemaNode) endpoints.getDataChildByName("box");
403 expectedQName = QName.create(UG_NS, UG_REV, "box");
404 assertEquals(expectedQName, box.getQName());
406 path.offer(expectedQName);
407 expectedPath= SchemaPath.create(path, true);
408 assertEquals(expectedPath, box.getPath());
409 assertTrue(box.isAddedByUses());
410 // * |-- |-- |-- |-- |-- choice address-family
411 ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName("address-family");
413 expectedQName = QName.create(UG_NS, UG_REV, "address-family");
414 assertEquals(expectedQName, af.getQName());
416 path.offer(expectedQName);
417 expectedPath= SchemaPath.create(path, true);
418 assertEquals(expectedPath, af.getPath());
419 assertTrue(af.isAddedByUses());
420 // * |-- |-- |-- |-- container reported-route
421 ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName("reported-route");
422 assertNotNull(reportedRoute);
423 expectedQName = QName.create(UG_NS, UG_REV, "reported-route");
424 assertEquals(expectedQName, reportedRoute.getQName());
427 path.offer(expectedQName);
428 expectedPath= SchemaPath.create(path, true);
429 assertEquals(expectedPath, reportedRoute.getPath());
430 assertFalse(reportedRoute.isAddedByUses());
431 // * |-- |-- |-- |-- |-- leaf processing-rule
432 processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName("processing-rule");
433 assertNotNull(processingRule);
434 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
435 assertEquals(expectedQName, processingRule.getQName());
436 path.offer(expectedQName);
437 expectedPath= SchemaPath.create(path, true);
438 assertEquals(expectedPath, processingRule.getPath());
439 assertEquals(BooleanType.getInstance(), processingRule.getType());
440 assertTrue(processingRule.isAddedByUses());
441 // * |-- |-- |-- |-- |-- leaf ignore
442 ignore = (LeafSchemaNode) reportedRoute.getDataChildByName("ignore");
443 assertNotNull(ignore);
444 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
445 assertEquals(expectedQName, ignore.getQName());
447 path.offer(expectedQName);
448 expectedPath= SchemaPath.create(path, true);
449 assertEquals(expectedPath, ignore.getPath());
450 assertEquals(BooleanType.getInstance(), ignore.getType());
451 assertTrue(ignore.isAddedByUses());
452 // * |-- |-- |-- |-- |-- list subobjects
453 ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName("subobjects");
454 assertNotNull(subobjects);
455 expectedQName = QName.create(UG_NS, UG_REV, "subobjects");
456 assertEquals(expectedQName, subobjects.getQName());
458 path.offer(expectedQName);
459 expectedPath= SchemaPath.create(path, true);
460 assertEquals(expectedPath, subobjects.getPath());
461 assertTrue(subobjects.isAddedByUses());
462 // * |-- |-- |-- |-- |-- container bandwidth
463 ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName("bandwidth");
464 assertNotNull(bandwidth);
465 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
466 assertEquals(expectedQName, bandwidth.getQName());
468 path.offer(expectedQName);
469 expectedPath= SchemaPath.create(path, true);
470 assertEquals(expectedPath, bandwidth.getPath());
471 assertFalse(bandwidth.isAddedByUses());
472 // * |-- |-- |-- |-- container bandwidth
473 bandwidth = (ContainerSchemaNode) p2p.getDataChildByName("bandwidth");
474 assertNotNull(bandwidth);
475 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
476 assertEquals(expectedQName, bandwidth.getQName());
479 path.offer(expectedQName);
480 expectedPath= SchemaPath.create(path, true);
481 assertEquals(expectedPath, bandwidth.getPath());
482 assertTrue(bandwidth.isAddedByUses());
483 // * |-- |-- |-- |-- |-- leaf processing-rule
484 processingRule = (LeafSchemaNode) bandwidth.getDataChildByName("processing-rule");
485 assertNotNull(processingRule);
486 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
487 assertEquals(expectedQName, processingRule.getQName());
488 path.offer(expectedQName);
489 expectedPath= SchemaPath.create(path, true);
490 assertEquals(expectedPath, processingRule.getPath());
491 assertEquals(BooleanType.getInstance(), processingRule.getType());
492 assertTrue(processingRule.isAddedByUses());
493 // * |-- |-- |-- |-- |-- leaf ignore
494 ignore = (LeafSchemaNode) bandwidth.getDataChildByName("ignore");
495 assertNotNull(ignore);
496 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
497 assertEquals(expectedQName, ignore.getQName());
499 path.offer(expectedQName);
500 expectedPath= SchemaPath.create(path, true);
501 assertEquals(expectedPath, ignore.getPath());
502 assertEquals(BooleanType.getInstance(), ignore.getType());
503 assertTrue(ignore.isAddedByUses());
504 // * |-- |-- |-- |-- |-- container bandwidth
505 ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName("bandwidth");
506 assertNotNull(bandwidthInner);
507 expectedQName = QName.create(UG_NS, UG_REV, "bandwidth");
508 assertEquals(expectedQName, bandwidth.getQName());
510 path.offer(expectedQName);
511 expectedPath= SchemaPath.create(path, true);
512 assertEquals(expectedPath, bandwidthInner.getPath());
513 assertTrue(bandwidthInner.isAddedByUses());
515 ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName("svec");
517 expectedQName = QName.create(UG_NS, UG_REV, "svec");
518 assertEquals(expectedQName, svec.getQName());
524 path.offer(expectedQName);
525 expectedPath= SchemaPath.create(path, true);
526 assertEquals(expectedPath, svec.getPath());
527 assertFalse(svec.isAddedByUses());
528 // * |-- |-- leaf link-diverse
529 LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName("link-diverse");
530 assertNotNull(linkDiverse);
531 expectedQName = QName.create(UG_NS, UG_REV, "link-diverse");
532 assertEquals(expectedQName, linkDiverse.getQName());
533 path.offer(expectedQName);
534 expectedPath= SchemaPath.create(path, true);
535 assertEquals(expectedPath, linkDiverse.getPath());
536 assertEquals(BooleanType.getInstance(), linkDiverse.getType());
537 assertTrue(linkDiverse.isAddedByUses());
538 // * |-- |-- leaf processing-rule
539 processingRule = (LeafSchemaNode) svec.getDataChildByName("processing-rule");
540 assertNotNull(processingRule);
541 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
542 assertEquals(expectedQName, processingRule.getQName());
544 path.offer(expectedQName);
545 expectedPath= SchemaPath.create(path, true);
546 assertEquals(expectedPath, processingRule.getPath());
547 assertEquals(BooleanType.getInstance(), processingRule.getType());
548 assertTrue(processingRule.isAddedByUses());
549 // * |-- |-- leaf ignore
550 ignore = (LeafSchemaNode) svec.getDataChildByName("ignore");
551 assertNotNull(ignore);
552 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
553 assertEquals(expectedQName, ignore.getQName());
555 path.offer(expectedQName);
556 expectedPath= SchemaPath.create(path, true);
557 assertEquals(expectedPath, ignore.getPath());
558 assertEquals(BooleanType.getInstance(), ignore.getType());
559 assertTrue(ignore.isAddedByUses());
560 // * |-- |-- list metric
561 ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName("metric");
562 assertNotNull(metric);
563 expectedQName = QName.create(UG_NS, UG_REV, "metric");
564 assertEquals(expectedQName, metric.getQName());
566 path.offer(expectedQName);
567 expectedPath= SchemaPath.create(path, true);
568 assertEquals(expectedPath, metric.getPath());
569 assertFalse(metric.isAddedByUses());
570 // * |-- |-- |-- leaf metric-type
571 LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName("metric-type");
572 assertNotNull(metricType);
573 expectedQName = QName.create(UG_NS, UG_REV, "metric-type");
574 assertEquals(expectedQName, metricType.getQName());
575 path.offer(expectedQName);
576 expectedPath= SchemaPath.create(path, true);
577 assertEquals(expectedPath, metricType.getPath());
578 assertEquals(Uint8.getInstance(), metricType.getType());
579 assertTrue(metricType.isAddedByUses());
581 box = (ContainerSchemaNode) metric.getDataChildByName("box");
583 expectedQName = QName.create(UG_NS, UG_REV, "box");
584 assertEquals(expectedQName, box.getQName());
586 path.offer(expectedQName);
587 expectedPath= SchemaPath.create(path, true);
588 assertEquals(expectedPath, box.getPath());
589 assertTrue(box.isAddedByUses());
590 // * |-- |-- |-- leaf processing-rule
591 processingRule = (LeafSchemaNode) metric.getDataChildByName("processing-rule");
592 assertNotNull(processingRule);
593 expectedQName = QName.create(UG_NS, UG_REV, "processing-rule");
594 assertEquals(expectedQName, processingRule.getQName());
596 path.offer(expectedQName);
597 expectedPath= SchemaPath.create(path, true);
598 assertEquals(expectedPath, processingRule.getPath());
599 assertEquals(BooleanType.getInstance(), processingRule.getType());
600 assertTrue(processingRule.isAddedByUses());
601 // * |-- |-- |-- leaf ignore
602 ignore = (LeafSchemaNode) metric.getDataChildByName("ignore");
603 assertNotNull(ignore);
604 expectedQName = QName.create(UG_NS, UG_REV, "ignore");
605 assertEquals(expectedQName, ignore.getQName());
607 path.offer(expectedQName);
608 expectedPath= SchemaPath.create(path, true);
609 assertEquals(expectedPath, ignore.getPath());
610 assertEquals(BooleanType.getInstance(), ignore.getType());
611 assertTrue(ignore.isAddedByUses());
615 public void testTypedefs() throws IOException, URISyntaxException {
616 modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI());
617 Module testModule = TestUtils.findModule(modules, "grouping-definitions");
618 Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
620 TypeDefinition<?> intExt = null;
621 for(TypeDefinition<?> td : types) {
622 if("int-ext".equals(td.getQName().getLocalName())) {
626 assertNotNull(intExt);
628 List<QName> path = Lists.newArrayList(QName.create(GD_NS, GD_REV, "int-ext"));
629 SchemaPath expectedPath = SchemaPath.create(path, true);
630 assertEquals(expectedPath, intExt.getPath());
632 UnionType union = (UnionType)intExt.getBaseType();
634 TypeDefinition<?> uint8 = null;
635 TypeDefinition<?> pv = null;
636 for(TypeDefinition<?> td : union.getTypes()) {
637 if("uint8".equals(td.getQName().getLocalName())) {
639 } else if("protocol-version".equals(td.getQName().getLocalName())) {
643 assertNotNull(uint8);
646 QName q1 = BaseTypes.constructQName("union");
647 expectedPath = SchemaPath.create(Lists.newArrayList(q1), true);
648 assertEquals(expectedPath, union.getPath());