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