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