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.ParseException;
15 import java.util.ArrayList;
16 import java.util.Date;
17 import java.util.List;
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;
32 public class UsesAugmentTest {
33 private final URI ns = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping");
35 private final String prefix = "ug";
37 private Set<Module> modules;
40 public void init() throws FileNotFoundException, ParseException {
41 rev = TestUtils.simpleDateFormat.parse("2013-07-30");
46 * Structure of testing model:
49 * |-- leaf version (U)
51 * |-- |-- container rp
52 * |-- |-- |-- leaf priority (U)
53 * |-- |-- |-- container box (U)
54 * |-- |-- |-- |-- container order (A)
55 * |-- |-- |-- |-- |-- leaf delete (U)
56 * |-- |-- |-- |-- |-- |-- leaf setup (U)
57 * |-- |-- |-- leaf processing-rule (U)
58 * |-- |-- |-- leaf ignore (U)
59 * |-- |-- path-key-expansion
60 * |-- |-- |-- container path-key
61 * |-- |-- |-- |-- list path-keys (U)
62 * |-- |-- |-- |-- |-- leaf version (U, A)
63 * |-- |-- |-- |-- |-- leaf processing-rule (U)
64 * |-- |-- |-- |-- |-- leaf ignore (U)
65 * |-- |-- container segment-computation
66 * |-- |-- |-- container p2p
67 * |-- |-- |-- |-- container endpoints
68 * |-- |-- |-- |-- |-- leaf processing-rule (U)
69 * |-- |-- |-- |-- |-- leaf ignore (U)
70 * |-- |-- |-- |-- |-- container box (U)
71 * |-- |-- |-- |-- |-- choice address-family (U)
72 * |-- |-- |-- |-- |-- |-- case ipv4
73 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv4-address
74 * |-- |-- |-- |-- |-- |-- case ipv6
75 * |-- |-- |-- |-- |-- |-- |-- leaf source-ipv6-address
76 * |-- |-- |-- |-- container reported-route
77 * |-- |-- |-- |-- |-- container bandwidth
78 * |-- |-- |-- |-- |-- list subobjects(U)
79 * |-- |-- |-- |-- |-- leaf processing-rule (U)
80 * |-- |-- |-- |-- |-- leaf ignore (U)
81 * |-- |-- |-- |-- container bandwidth (U)
82 * |-- |-- |-- |-- |-- container bandwidth (U)
83 * |-- |-- |-- |-- |-- leaf processing-rule (U)
84 * |-- |-- |-- |-- |-- leaf ignore (U)
87 * |-- |-- |-- leaf metric-type (U)
88 * |-- |-- |-- container box (U)
89 * |-- |-- |-- leaf processing-rule (U)
90 * |-- |-- |-- leaf ignore (U)
91 * |-- |-- leaf link-diverse (U)
92 * |-- |-- leaf processing-rule (U)
93 * |-- |-- leaf ignore (U)
96 * A = added by augment
99 public void testAugmentInUses() throws Exception {
100 modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
101 Module testModule = TestUtils.findModule(modules, "uses-grouping");
103 // * notification pcreq
104 Set<NotificationDefinition> notifications = testModule.getNotifications();
105 assertEquals(1, notifications.size());
106 NotificationDefinition pcreq = notifications.iterator().next();
107 assertNotNull(pcreq);
108 assertEquals(createPath("pcreq"), pcreq.getPath());
109 Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
110 assertEquals(3, childNodes.size());
111 // * |-- leaf version (U)
112 LeafSchemaNode version = (LeafSchemaNode)pcreq.getDataChildByName("version");
113 assertNotNull(version);
114 assertEquals(createPath("pcreq", "version"), version.getPath());
115 assertTrue(version.isAddedByUses());
116 // * |-- list requests
117 ListSchemaNode requests = (ListSchemaNode)pcreq.getDataChildByName("requests");
118 assertNotNull(requests);
119 assertEquals(createPath("pcreq", "requests"), requests.getPath());
120 assertFalse(requests.isAddedByUses());
121 childNodes = requests.getChildNodes();
122 assertEquals(3, childNodes.size());
123 // * |-- |-- container rp
124 ContainerSchemaNode rp = (ContainerSchemaNode)requests.getDataChildByName("rp");
126 assertEquals(createPath("pcreq", "requests", "rp"), rp.getPath());
127 assertFalse(rp.isAddedByUses());
128 childNodes = rp.getChildNodes();
129 assertEquals(4, childNodes.size());
130 // * |-- |-- |-- leaf priority (U)
131 LeafSchemaNode priority = (LeafSchemaNode)rp.getDataChildByName("priority");
132 assertNotNull(priority);
133 assertEquals(createPath("pcreq", "requests", "rp", "priority"), priority.getPath());
134 assertTrue(priority.isAddedByUses());
135 // * |-- |-- |-- container box (U)
136 ContainerSchemaNode box = (ContainerSchemaNode)rp.getDataChildByName("box");
138 assertEquals(createPath("pcreq", "requests", "rp", "box"), box.getPath());
139 assertTrue(box.isAddedByUses());
140 // * |-- |-- |-- |-- container order (A)
141 ContainerSchemaNode order = (ContainerSchemaNode)box.getDataChildByName("order");
142 assertNotNull(order);
143 assertEquals(createPath("pcreq", "requests", "rp", "box", "order"), order.getPath());
144 assertFalse(order.isAddedByUses());
145 assertTrue(order.isAugmenting());
146 assertEquals(2, order.getChildNodes().size());
147 // * |-- |-- |-- |-- |-- leaf processing-rule (U)
148 LeafSchemaNode delete = (LeafSchemaNode)order.getDataChildByName("delete");
149 assertNotNull(delete);
150 assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "delete"), delete.getPath());
151 assertTrue(delete.isAddedByUses());
152 // * |-- |-- |-- |-- |-- leaf ignore (U)
153 LeafSchemaNode setup = (LeafSchemaNode)order.getDataChildByName("setup");
154 assertNotNull(setup);
155 assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "setup"), setup.getPath());
156 assertTrue(setup.isAddedByUses());
157 // * |-- |-- |-- leaf processing-rule (U)
158 LeafSchemaNode processingRule = (LeafSchemaNode)rp.getDataChildByName("processing-rule");
159 assertNotNull(processingRule);
160 assertEquals(createPath("pcreq", "requests", "rp", "processing-rule"), processingRule.getPath());
161 assertTrue(processingRule.isAddedByUses());
162 // * |-- |-- |-- leaf ignore (U)
163 LeafSchemaNode ignore = (LeafSchemaNode)rp.getDataChildByName("ignore");
164 assertNotNull(ignore);
165 assertEquals(createPath("pcreq", "requests", "rp", "ignore"), ignore.getPath());
166 assertTrue(ignore.isAddedByUses());
167 // * |-- |-- path-key-expansion
168 ContainerSchemaNode pke = (ContainerSchemaNode)requests.getDataChildByName("path-key-expansion");
170 assertEquals(createPath("pcreq", "requests", "path-key-expansion"), pke.getPath());
171 assertFalse(pke.isAddedByUses());
172 // * |-- |-- |-- path-key
173 ContainerSchemaNode pathKey = (ContainerSchemaNode)pke.getDataChildByName("path-key");
174 assertNotNull(pathKey);
175 assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key"), pathKey.getPath());
176 assertFalse(pathKey.isAddedByUses());
177 assertEquals(3, pathKey.getChildNodes().size());
178 // * |-- |-- |-- |-- list path-keys (U)
179 ListSchemaNode pathKeys = (ListSchemaNode)pathKey.getDataChildByName("path-keys");
180 assertNotNull(pathKeys);
181 assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys"), pathKeys.getPath());
182 assertTrue(pathKeys.isAddedByUses());
183 childNodes = pathKeys.getChildNodes();
184 assertEquals(1, childNodes.size());
185 // * |-- |-- |-- |-- |-- leaf version (U)
186 version = (LeafSchemaNode)pathKeys.getDataChildByName("version");
187 assertNotNull(version);
188 assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version"), version.getPath());
189 assertTrue(version.isAddedByUses());
190 assertFalse(version.isAugmenting());
191 // * |-- |-- |-- |-- |-- leaf processing-rule (U)
192 processingRule = (LeafSchemaNode)pathKey.getDataChildByName("processing-rule");
193 assertNotNull(processingRule);
194 assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule"), processingRule.getPath());
195 assertTrue(processingRule.isAddedByUses());
196 // * |-- |-- |-- |-- |-- leaf ignore (U)
197 ignore = (LeafSchemaNode)pathKey.getDataChildByName("ignore");
198 assertNotNull(ignore);
199 assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "ignore"), ignore.getPath());
200 assertTrue(ignore.isAddedByUses());
201 // * |-- |-- container segment-computation
202 ContainerSchemaNode sc = (ContainerSchemaNode)requests.getDataChildByName("segment-computation");
204 assertEquals(createPath("pcreq", "requests", "segment-computation"), sc.getPath());
205 assertFalse(sc.isAddedByUses());
206 // * |-- |-- |-- container p2p
207 ContainerSchemaNode p2p = (ContainerSchemaNode)sc.getDataChildByName("p2p");
209 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p"), p2p.getPath());
210 assertFalse(p2p.isAddedByUses());
211 // * |-- |-- |-- |-- container endpoints
212 ContainerSchemaNode endpoints = (ContainerSchemaNode)p2p.getDataChildByName("endpoints");
213 assertNotNull(endpoints);
214 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints"), endpoints.getPath());
215 assertFalse(endpoints.isAddedByUses());
216 // * |-- |-- |-- |-- |-- leaf processing-rule (U)
217 processingRule = (LeafSchemaNode)endpoints.getDataChildByName("processing-rule");
218 assertNotNull(processingRule);
219 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "processing-rule"), processingRule.getPath());
220 assertTrue(processingRule.isAddedByUses());
221 // * |-- |-- |-- |-- |-- leaf ignore (U)
222 ignore = (LeafSchemaNode)endpoints.getDataChildByName("ignore");
223 assertNotNull(ignore);
224 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore"), ignore.getPath());
225 assertTrue(ignore.isAddedByUses());
226 // * |-- |-- |-- |-- |-- container box
227 box = (ContainerSchemaNode)endpoints.getDataChildByName("box");
229 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "box"), box.getPath());
230 assertTrue(box.isAddedByUses());
231 // * |-- |-- |-- |-- |-- choice address-family (U)
232 ChoiceNode af = (ChoiceNode)endpoints.getDataChildByName("address-family");
234 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "address-family"), af.getPath());
235 assertTrue(af.isAddedByUses());
236 // * |-- |-- |-- |-- container reported-route
237 ContainerSchemaNode reportedRoute = (ContainerSchemaNode)p2p.getDataChildByName("reported-route");
238 assertNotNull(reportedRoute);
239 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route"), reportedRoute.getPath());
240 assertFalse(reportedRoute.isAddedByUses());
241 // * |-- |-- |-- |-- |-- container bandwidth
242 ContainerSchemaNode bandwidth = (ContainerSchemaNode)reportedRoute.getDataChildByName("bandwidth");
243 assertNotNull(bandwidth);
244 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "bandwidth"), bandwidth.getPath());
245 assertFalse(bandwidth.isAddedByUses());
246 // * |-- |-- |-- |-- |-- list subobjects
247 ListSchemaNode subobjects = (ListSchemaNode)reportedRoute.getDataChildByName("subobjects");
248 assertNotNull(subobjects);
249 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "subobjects"), subobjects.getPath());
250 assertTrue(subobjects.isAddedByUses());
251 // * |-- |-- |-- |-- |-- leaf processing-rule (U)
252 processingRule = (LeafSchemaNode)reportedRoute.getDataChildByName("processing-rule");
253 assertNotNull(processingRule);
254 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "processing-rule"), processingRule.getPath());
255 assertTrue(processingRule.isAddedByUses());
256 // * |-- |-- |-- |-- |-- leaf ignore (U)
257 ignore = (LeafSchemaNode)reportedRoute.getDataChildByName("ignore");
258 assertNotNull(ignore);
259 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore"), ignore.getPath());
260 assertTrue(ignore.isAddedByUses());
261 // * |-- |-- |-- |-- container bandwidth (U)
262 bandwidth = (ContainerSchemaNode)p2p.getDataChildByName("bandwidth");
263 assertNotNull(bandwidth);
264 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth"), bandwidth.getPath());
265 assertTrue(bandwidth.isAddedByUses());
266 // * |-- |-- |-- |-- |-- container bandwidth (U)
267 ContainerSchemaNode bandwidthInner = (ContainerSchemaNode)bandwidth.getDataChildByName("bandwidth");
268 assertNotNull(bandwidthInner);
269 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "bandwidth"), bandwidthInner.getPath());
270 assertTrue(bandwidthInner.isAddedByUses());
271 // * |-- |-- |-- |-- |-- leaf processing-rule (U)
272 processingRule = (LeafSchemaNode)bandwidth.getDataChildByName("processing-rule");
273 assertNotNull(processingRule);
274 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "processing-rule"), processingRule.getPath());
275 assertTrue(processingRule.isAddedByUses());
276 // * |-- |-- |-- |-- |-- leaf ignore (U)
277 ignore = (LeafSchemaNode)bandwidth.getDataChildByName("ignore");
278 assertNotNull(ignore);
279 assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore"), ignore.getPath());
280 assertTrue(ignore.isAddedByUses());
282 ListSchemaNode svec = (ListSchemaNode)pcreq.getDataChildByName("svec");
284 assertEquals(createPath("pcreq", "svec"), svec.getPath());
285 assertFalse(svec.isAddedByUses());
286 // * |-- |-- list metric
287 ListSchemaNode metric = (ListSchemaNode)svec.getDataChildByName("metric");
288 assertNotNull(metric);
289 assertEquals(createPath("pcreq", "svec", "metric"), metric.getPath());
290 assertFalse(metric.isAddedByUses());
291 // * |-- |-- |-- leaf metric-type (U)
292 LeafSchemaNode metricType = (LeafSchemaNode)metric.getDataChildByName("metric-type");
293 assertNotNull(metricType);
294 assertEquals(createPath("pcreq", "svec", "metric", "metric-type"), metricType.getPath());
295 assertTrue(metricType.isAddedByUses());
296 // * |-- |-- |-- box (U)
297 box = (ContainerSchemaNode)metric.getDataChildByName("box");
299 assertEquals(createPath("pcreq", "svec", "metric", "box"), box.getPath());
300 assertTrue(box.isAddedByUses());
301 // * |-- |-- |-- leaf processing-rule (U)
302 processingRule = (LeafSchemaNode)metric.getDataChildByName("processing-rule");
303 assertNotNull(processingRule);
304 assertEquals(createPath("pcreq", "svec", "metric", "processing-rule"), processingRule.getPath());
305 assertTrue(processingRule.isAddedByUses());
306 // * |-- |-- |-- leaf ignore (U)
307 ignore = (LeafSchemaNode)metric.getDataChildByName("ignore");
308 assertNotNull(ignore);
309 assertEquals(createPath("pcreq", "svec", "metric", "ignore"), ignore.getPath());
310 assertTrue(ignore.isAddedByUses());
311 // * |-- |-- leaf link-diverse (U)
312 LeafSchemaNode linkDiverse = (LeafSchemaNode)svec.getDataChildByName("link-diverse");
313 assertNotNull(linkDiverse);
314 assertEquals(createPath("pcreq", "svec", "link-diverse"), linkDiverse.getPath());
315 assertTrue(linkDiverse.isAddedByUses());
316 // * |-- |-- leaf processing-rule (U)
317 processingRule = (LeafSchemaNode)svec.getDataChildByName("processing-rule");
318 assertNotNull(processingRule);
319 assertEquals(createPath("pcreq", "svec", "processing-rule"), processingRule.getPath());
320 assertTrue(processingRule.isAddedByUses());
321 // * |-- |-- leaf ignore (U)
322 ignore = (LeafSchemaNode)svec.getDataChildByName("ignore");
323 assertNotNull(ignore);
324 assertEquals(createPath("pcreq", "svec", "ignore"), ignore.getPath());
325 assertTrue(ignore.isAddedByUses());
328 private SchemaPath createPath(String... names) {
329 List<QName> path = new ArrayList<>();
330 for(String name : names) {
331 path.add(new QName(ns, rev, prefix, name));
333 return new SchemaPath(path, true);