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.controller.yang.parser.impl;
10 import static org.junit.Assert.*;
13 import java.util.ArrayList;
14 import java.util.Date;
15 import java.util.HashSet;
16 import java.util.List;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.controller.yang.common.QName;
23 import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
24 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
25 import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
26 import org.opendaylight.controller.yang.model.api.ChoiceNode;
27 import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
28 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
29 import org.opendaylight.controller.yang.model.api.Deviation;
30 import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
31 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
32 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
33 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
34 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
35 import org.opendaylight.controller.yang.model.api.Module;
36 import org.opendaylight.controller.yang.model.api.ModuleImport;
37 import org.opendaylight.controller.yang.model.api.MustDefinition;
38 import org.opendaylight.controller.yang.model.api.NotificationDefinition;
39 import org.opendaylight.controller.yang.model.api.RpcDefinition;
40 import org.opendaylight.controller.yang.model.api.SchemaNode;
41 import org.opendaylight.controller.yang.model.api.SchemaPath;
42 import org.opendaylight.controller.yang.model.api.Status;
43 import org.opendaylight.controller.yang.model.api.TypeDefinition;
44 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
45 import org.opendaylight.controller.yang.model.api.UsesNode;
46 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
47 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
48 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
49 import org.opendaylight.controller.yang.model.util.Decimal64;
50 import org.opendaylight.controller.yang.model.util.ExtendedType;
51 import org.opendaylight.controller.yang.model.util.Int16;
52 import org.opendaylight.controller.yang.model.util.Int32;
53 import org.opendaylight.controller.yang.model.util.StringType;
54 import org.opendaylight.controller.yang.model.util.Uint32;
55 import org.opendaylight.controller.yang.model.util.UnionType;
57 public class YangParserTest {
58 private Set<Module> modules;
62 modules = TestUtils.loadModules("src/test/resources/model");
63 assertEquals(3, modules.size());
67 public void testHeaders() {
68 Module test = TestUtils.findModule(modules, "types1");
70 assertEquals("types1", test.getName());
71 assertEquals("1", test.getYangVersion());
72 URI expectedNamespace = URI.create("urn:simple.container.demo");
73 assertEquals(expectedNamespace, test.getNamespace());
74 assertEquals("t1", test.getPrefix());
76 Set<ModuleImport> imports = test.getImports();
77 assertEquals(2, imports.size());
79 ModuleImport import2 = TestUtils.findImport(imports, "data");
80 assertEquals("types2", import2.getModuleName());
81 assertEquals(TestUtils.createDate("2013-02-27"), import2.getRevision());
83 ModuleImport import3 = TestUtils.findImport(imports, "t3");
84 assertEquals("types3", import3.getModuleName());
85 assertEquals(TestUtils.createDate("2013-02-27"), import3.getRevision());
87 assertEquals("opendaylight", test.getOrganization());
88 assertEquals("http://www.opendaylight.org/", test.getContact());
89 Date expectedRevision = TestUtils.createDate("2013-02-27");
90 assertEquals(expectedRevision, test.getRevision());
91 assertEquals(" WILL BE DEFINED LATER", test.getReference());
95 public void testParseContainer() {
96 Module test = TestUtils.findModule(modules, "types2");
97 URI expectedNamespace = URI.create("urn:simple.types.data.demo");
98 String expectedPrefix = "t2";
99 Date expectedRevision = TestUtils.createDate("2013-02-27");
101 ContainerSchemaNode interfaces = (ContainerSchemaNode) test
102 .getDataChildByName("interfaces");
103 // test SchemaNode args
104 QName expectedQName = new QName(expectedNamespace, expectedRevision,
105 expectedPrefix, "interfaces");
106 assertEquals(expectedQName, interfaces.getQName());
107 SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace,
108 expectedRevision, expectedPrefix, "interfaces");
109 assertEquals(expectedPath, interfaces.getPath());
110 assertNull(interfaces.getDescription());
111 assertNull(interfaces.getReference());
112 assertEquals(Status.CURRENT, interfaces.getStatus());
113 assertEquals(0, interfaces.getUnknownSchemaNodes().size());
114 // test DataSchemaNode args
115 assertFalse(interfaces.isAugmenting());
116 assertFalse(interfaces.isConfiguration());
117 ConstraintDefinition constraints = interfaces.getConstraints();
118 assertNull(constraints.getWhenCondition());
119 assertEquals(0, constraints.getMustConstraints().size());
120 assertFalse(constraints.isMandatory());
121 assertNull(constraints.getMinElements());
122 assertNull(constraints.getMaxElements());
123 // test AugmentationTarget args
124 assertEquals(0, interfaces.getAvailableAugmentations().size());
125 // test ContainerSchemaNode args
126 assertFalse(interfaces.isPresenceContainer());
127 // test DataNodeContainer args
128 assertEquals(0, interfaces.getTypeDefinitions().size());
129 assertEquals(1, interfaces.getChildNodes().size());
130 assertEquals(0, interfaces.getGroupings().size());
131 assertEquals(0, interfaces.getUses().size());
133 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
134 .getDataChildByName("ifEntry");
135 assertNotNull(ifEntry);
139 public void testParseList() {
140 Module test = TestUtils.findModule(modules, "types2");
141 URI expectedNamespace = URI.create("urn:simple.types.data.demo");
142 String expectedPrefix = "t2";
143 Date expectedRevision = TestUtils.createDate("2013-02-27");
145 ContainerSchemaNode interfaces = (ContainerSchemaNode) test
146 .getDataChildByName("interfaces");
148 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
149 .getDataChildByName("ifEntry");
150 // test SchemaNode args
151 QName expectedQName = new QName(expectedNamespace, expectedRevision,
152 expectedPrefix, "ifEntry");
153 assertEquals(expectedQName, ifEntry.getQName());
154 SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace,
155 expectedRevision, expectedPrefix, "interfaces", "ifEntry");
156 assertEquals(expectedPath, ifEntry.getPath());
157 assertNull(ifEntry.getDescription());
158 assertNull(ifEntry.getReference());
159 assertEquals(Status.CURRENT, ifEntry.getStatus());
160 assertEquals(0, ifEntry.getUnknownSchemaNodes().size());
161 // test DataSchemaNode args
162 assertFalse(ifEntry.isAugmenting());
163 assertFalse(ifEntry.isConfiguration());
164 ConstraintDefinition constraints = ifEntry.getConstraints();
165 assertNull(constraints.getWhenCondition());
166 assertEquals(0, constraints.getMustConstraints().size());
167 assertFalse(constraints.isMandatory());
168 assertNull(constraints.getMinElements());
169 assertNull(constraints.getMaxElements());
170 // test AugmentationTarget args
171 Set<AugmentationSchema> availableAugmentations = ifEntry
172 .getAvailableAugmentations();
173 assertEquals(2, availableAugmentations.size());
174 // test ListSchemaNode args
175 List<QName> expectedKey = new ArrayList<QName>();
176 expectedKey.add(new QName(expectedNamespace, expectedRevision,
177 expectedPrefix, "ifIndex"));
178 assertEquals(expectedKey, ifEntry.getKeyDefinition());
179 assertFalse(ifEntry.isUserOrdered());
180 // test DataNodeContainer args
181 assertEquals(0, ifEntry.getTypeDefinitions().size());
182 assertEquals(4, ifEntry.getChildNodes().size());
183 assertEquals(0, ifEntry.getGroupings().size());
184 assertEquals(0, ifEntry.getUses().size());
186 LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry
187 .getDataChildByName("ifIndex");
188 assertTrue(ifIndex.getType() instanceof Uint32);
189 LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry
190 .getDataChildByName("ifMtu");
191 assertTrue(ifMtu.getType() instanceof Int32);
195 public void testAugmentResolving() {
197 Module module1 = TestUtils.findModule(modules, "types1");
199 Set<AugmentationSchema> module1Augmentations = module1
201 AugmentationSchema augment1 = module1Augmentations.iterator().next();
202 LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1
203 .getDataChildByName("ds0ChannelNumber");
204 assertTrue(augmentedLeafDefinition.isAugmenting());
207 Module module2 = TestUtils.findModule(modules, "types2");
209 ContainerSchemaNode interfaces = (ContainerSchemaNode) module2
210 .getDataChildByName("interfaces");
211 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
212 .getDataChildByName("ifEntry");
213 ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry
214 .getDataChildByName("augment-holder");
216 // augmentation defined in testfile1 and augmentation returned from
217 // augmented container have to be same
218 Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer
219 .getAvailableAugmentations();
220 AugmentationSchema augmentDefinition = augmentedContainerAugments
222 assertEquals(augment1, augmentDefinition);
224 LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer
225 .getDataChildByName("ds0ChannelNumber");
226 assertTrue(augmentedLeaf.isAugmenting());
227 assertEquals(augmentedLeafDefinition, augmentedLeaf);
229 Set<AugmentationSchema> ifEntryAugments = ifEntry
230 .getAvailableAugmentations();
231 assertEquals(2, ifEntryAugments.size());
234 Module module3 = TestUtils.findModule(modules, "types3");
236 Set<AugmentationSchema> module3Augmentations = module3
238 assertEquals(2, module3Augmentations.size());
239 AugmentationSchema augment3 = null;
240 for (AugmentationSchema as : module3Augmentations) {
241 if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
245 ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
246 .getDataChildByName("augment-holder");
247 assertTrue(augmentedContainerDefinition.isAugmenting());
250 assertEquals(augmentedContainer, augmentedContainerDefinition);
251 assertEquals(augmentedContainerAugments.iterator().next(), augment1);
253 assertEquals(augmentedLeaf, augmentedLeafDefinition);
254 assertEquals(ifEntryAugments.iterator().next(), augment3);
258 public void testAugmentTarget() {
259 Module test = TestUtils.findModule(modules, "types2");
261 ContainerSchemaNode interfaces = (ContainerSchemaNode) test
262 .getDataChildByName("interfaces");
263 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
264 .getDataChildByName("ifEntry");
265 Set<AugmentationSchema> augmentations = ifEntry
266 .getAvailableAugmentations();
267 assertEquals(2, augmentations.size());
269 AugmentationSchema augment = null;
270 for (AugmentationSchema as : augmentations) {
271 if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
275 ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
276 .getDataChildByName("augment-holder");
277 assertNotNull(augmentHolder);
278 assertTrue(augmentHolder.isAugmenting());
279 QName augmentHolderQName = augmentHolder.getQName();
280 assertEquals("augment-holder", augmentHolderQName.getLocalName());
281 assertEquals("t3", augmentHolderQName.getPrefix());
282 assertEquals("Description for augment holder",
283 augmentHolder.getDescription());
287 public void testTypedefRangesResolving() {
288 Module testModule = TestUtils.findModule(modules, "types1");
290 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
291 .getDataChildByName("testleaf");
292 ExtendedType leafType = (ExtendedType) testleaf.getType();
293 assertEquals("my-type1", leafType.getQName().getLocalName());
294 assertEquals("t2", leafType.getQName().getPrefix());
295 ExtendedType baseType = (ExtendedType) leafType.getBaseType();
296 assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
297 assertEquals("t2", baseType.getQName().getPrefix());
299 List<RangeConstraint> ranges = leafType.getRanges();
300 assertEquals(1, ranges.size());
301 RangeConstraint range = ranges.get(0);
302 assertEquals(3L, range.getMin());
303 assertEquals(20L, range.getMax());
307 public void testTypedefPatternsResolving() {
308 Module testModule = TestUtils.findModule(modules, "types1");
310 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
311 .getDataChildByName("test-string-leaf");
312 ExtendedType testleafType = (ExtendedType) testleaf.getType();
313 QName testleafTypeQName = testleafType.getQName();
314 assertEquals("my-string-type-ext", testleafTypeQName.getLocalName());
315 assertEquals("t2", testleafTypeQName.getPrefix());
317 Set<String> expectedRegex = new HashSet<String>();
318 expectedRegex.add("[a-k]*");
319 expectedRegex.add("[b-u]*");
320 expectedRegex.add("[e-z]*");
322 Set<String> actualRegex = new HashSet<String>();
323 List<PatternConstraint> patterns = testleafType.getPatterns();
324 assertEquals(3, patterns.size());
325 for (PatternConstraint pc : patterns) {
326 actualRegex.add(pc.getRegularExpression());
328 assertEquals(expectedRegex, actualRegex);
330 TypeDefinition<?> baseType = testleafType.getBaseType();
331 assertEquals("my-string-type2", baseType.getQName().getLocalName());
333 List<LengthConstraint> lengths = testleafType.getLengths();
334 assertEquals(1, lengths.size());
336 LengthConstraint length = lengths.get(0);
337 assertEquals(5L, length.getMin());
338 assertEquals(10L, length.getMax());
342 public void testTypedefLengthsResolving() {
343 Module testModule = TestUtils.findModule(modules, "types1");
345 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
346 .getDataChildByName("leaf-with-length");
347 ExtendedType testleafType = (ExtendedType) testleaf.getType();
348 assertEquals("my-string-type", testleafType.getQName().getLocalName());
350 List<LengthConstraint> lengths = testleafType.getLengths();
351 assertEquals(1, lengths.size());
353 LengthConstraint length = lengths.get(0);
354 assertEquals(7L, length.getMin());
355 assertEquals(10L, length.getMax());
359 public void testTypeDef() {
360 Module testModule = TestUtils.findModule(modules, "types2");
362 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
363 .getDataChildByName("nested-type-leaf");
364 ExtendedType testleafType = (ExtendedType) testleaf.getType();
365 assertEquals("my-type1", testleafType.getQName().getLocalName());
367 ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
368 assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
370 Int32 int32base = (Int32) baseType.getBaseType();
371 List<RangeConstraint> ranges = int32base.getRangeStatements();
372 assertEquals(1, ranges.size());
373 RangeConstraint range = ranges.get(0);
374 assertEquals(2L, range.getMin());
375 assertEquals(20L, range.getMax());
379 public void testTypedefDecimal1() {
380 Module testModule = TestUtils.findModule(modules, "types1");
382 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
383 .getDataChildByName("test-decimal-leaf");
384 ExtendedType type = (ExtendedType) testleaf.getType();
385 assertEquals(4, (int) type.getFractionDigits());
387 Decimal64 baseType = (Decimal64) type.getBaseType();
388 assertEquals(6, (int) baseType.getFractionDigits());
392 public void testTypedefDecimal2() {
393 Module testModule = TestUtils.findModule(modules, "types1");
395 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
396 .getDataChildByName("test-decimal-leaf2");
397 TypeDefinition<?> baseType = testleaf.getType().getBaseType();
398 assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
399 Decimal64 baseTypeCast = (Decimal64) baseType;
400 assertEquals(5, (int) baseTypeCast.getFractionDigits());
404 public void testTypedefUnion() {
405 Module testModule = TestUtils.findModule(modules, "types1");
407 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
408 .getDataChildByName("union-leaf");
409 ExtendedType testleafType = (ExtendedType) testleaf.getType();
410 assertEquals("my-union-ext", testleafType.getQName().getLocalName());
412 ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
413 assertEquals("my-union", baseType.getQName().getLocalName());
415 UnionType unionBase = (UnionType) baseType.getBaseType();
417 List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
418 Int16 unionType1 = (Int16) unionTypes.get(0);
419 List<RangeConstraint> ranges = unionType1.getRangeStatements();
420 assertEquals(1, ranges.size());
421 RangeConstraint range = ranges.get(0);
422 assertEquals(1L, range.getMin());
423 assertEquals(100L, range.getMax());
425 assertTrue(unionTypes.get(0) instanceof Int16);
426 assertTrue(unionTypes.get(1) instanceof Int32);
430 public void testNestedUnionResolving1() {
431 Module testModule = TestUtils.findModule(modules, "types1");
433 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
434 .getDataChildByName("nested-union-leaf");
436 ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType();
437 assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
439 ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType();
440 assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
442 UnionType unionType1 = (UnionType) nestedUnion2.getBaseType();
443 List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
444 assertEquals(2, unionTypes.size());
445 assertTrue(unionTypes.get(0) instanceof StringType);
446 assertTrue(unionTypes.get(1) instanceof ExtendedType);
448 ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1);
449 ExtendedType extendedUnionBase = (ExtendedType) extendedUnion
451 assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
453 UnionType extendedTargetUnion = (UnionType) extendedUnionBase
455 List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion
457 assertTrue(extendedTargetTypes.get(0) instanceof Int16);
458 assertTrue(extendedTargetTypes.get(1) instanceof Int32);
460 Int16 int16 = (Int16) extendedTargetTypes.get(0);
461 List<RangeConstraint> ranges = int16.getRangeStatements();
462 assertEquals(1, ranges.size());
463 RangeConstraint range = ranges.get(0);
464 assertEquals(1L, range.getMin());
465 assertEquals(100L, range.getMax());
469 public void testNestedUnionResolving2() {
470 Module testModule = TestUtils.findModule(modules, "types1");
472 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
473 .getDataChildByName("custom-union-leaf");
475 ExtendedType testleafType = (ExtendedType) testleaf.getType();
476 QName testleafTypeQName = testleafType.getQName();
477 assertEquals(URI.create("urn:simple.container.demo.test"),
478 testleafTypeQName.getNamespace());
479 assertEquals(TestUtils.createDate("2013-02-27"),
480 testleafTypeQName.getRevision());
481 assertEquals("t3", testleafTypeQName.getPrefix());
482 assertEquals("union1", testleafTypeQName.getLocalName());
484 ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
485 QName union2QName = union2.getQName();
486 assertEquals(URI.create("urn:simple.container.demo.test"),
487 union2QName.getNamespace());
488 assertEquals(TestUtils.createDate("2013-02-27"),
489 union2QName.getRevision());
490 assertEquals("t3", union2QName.getPrefix());
491 assertEquals("union2", union2QName.getLocalName());
493 UnionType union2Base = (UnionType) union2.getBaseType();
494 List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
495 assertEquals(2, unionTypes.size());
496 assertTrue(unionTypes.get(0) instanceof Int32);
497 assertTrue(unionTypes.get(1) instanceof ExtendedType);
499 ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
500 QName nestedUnion2QName = nestedUnion2.getQName();
501 assertEquals(URI.create("urn:simple.types.data.demo"),
502 nestedUnion2QName.getNamespace());
503 assertEquals(TestUtils.createDate("2013-02-27"),
504 nestedUnion2QName.getRevision());
505 assertEquals("t2", nestedUnion2QName.getPrefix());
506 assertEquals("nested-union2", nestedUnion2QName.getLocalName());
508 UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
509 List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
510 assertEquals(2, nestedUnion2Types.size());
511 assertTrue(nestedUnion2Types.get(0) instanceof StringType);
512 assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
514 ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
515 QName myUnionExtQName = myUnionExt.getQName();
516 assertEquals(URI.create("urn:simple.types.data.demo"),
517 myUnionExtQName.getNamespace());
518 assertEquals(TestUtils.createDate("2013-02-27"),
519 myUnionExtQName.getRevision());
520 assertEquals("t2", myUnionExtQName.getPrefix());
521 assertEquals("my-union-ext", myUnionExtQName.getLocalName());
523 ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
524 QName myUnionQName = myUnion.getQName();
525 assertEquals(URI.create("urn:simple.types.data.demo"),
526 myUnionQName.getNamespace());
527 assertEquals(TestUtils.createDate("2013-02-27"),
528 myUnionQName.getRevision());
529 assertEquals("t2", myUnionQName.getPrefix());
530 assertEquals("my-union", myUnionQName.getLocalName());
532 UnionType myUnionBase = (UnionType) myUnion.getBaseType();
533 List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
534 assertEquals(2, myUnionBaseTypes.size());
535 assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
536 assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
537 Int16 int16 = (Int16) myUnionBaseTypes.get(0);
538 List<RangeConstraint> ranges = int16.getRangeStatements();
539 assertEquals(1, ranges.size());
540 RangeConstraint range = ranges.get(0);
541 assertEquals(1L, range.getMin());
542 assertEquals(100L, range.getMax());
546 public void testRefine() {
547 Module testModule = TestUtils.findModule(modules, "types2");
549 ContainerSchemaNode peer = (ContainerSchemaNode) testModule
550 .getDataChildByName("peer");
551 ContainerSchemaNode destination = (ContainerSchemaNode) peer
552 .getDataChildByName("destination");
553 Set<UsesNode> usesNodes = destination.getUses();
554 assertEquals(1, usesNodes.size());
555 UsesNode usesNode = usesNodes.iterator().next();
556 Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
557 assertEquals(2, refines.size());
559 for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
560 SchemaNode value = entry.getValue();
562 if (value instanceof LeafSchemaNode) {
563 LeafSchemaNode refineLeaf = (LeafSchemaNode) value;
564 assertNotNull(refineLeaf);
566 ContainerSchemaNode refineContainer = (ContainerSchemaNode) value;
567 Set<MustDefinition> mustConstraints = refineContainer
568 .getConstraints().getMustConstraints();
569 assertEquals(1, mustConstraints.size());
570 MustDefinition must = mustConstraints.iterator().next();
571 assertEquals("must-condition", must.toString());
572 assertEquals("An error message test", must.getErrorMessage());
573 assertEquals(("An error app tag test"), must.getErrorAppTag());
579 public void testChoice() {
580 Module testModule = TestUtils.findModule(modules, "types1");
581 ContainerSchemaNode peer = (ContainerSchemaNode) testModule
582 .getDataChildByName("transfer");
583 ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
584 Set<ChoiceCaseNode> cases = how.getCases();
585 assertEquals(3, cases.size());
589 public void testAnyXml() {
590 Module testModule = TestUtils.findModule(modules, "types1");
591 AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule
592 .getDataChildByName("data");
597 public void testDeviation() {
598 Module testModule = TestUtils.findModule(modules, "types1");
599 Set<Deviation> deviations = testModule.getDeviations();
600 assertEquals(1, deviations.size());
602 Deviation dev = deviations.iterator().next();
603 SchemaPath expectedPath = TestUtils.createPath(true, null, null,
604 "data", "system", "user");
605 assertEquals(expectedPath, dev.getTargetPath());
606 assertEquals(Deviate.ADD, dev.getDeviate());
610 public void testUnknownNode() {
611 Module testModule = TestUtils.findModule(modules, "types3");
612 ContainerSchemaNode network = (ContainerSchemaNode) testModule
613 .getDataChildByName("network");
614 List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
615 assertEquals(1, unknownNodes.size());
616 UnknownSchemaNode unknownNode = unknownNodes.get(0);
617 assertNotNull(unknownNode.getNodeType());
618 assertEquals("point", unknownNode.getNodeParameter());
622 public void testFeature() {
623 Module testModule = TestUtils.findModule(modules, "types3");
624 Set<FeatureDefinition> features = testModule.getFeatures();
625 assertEquals(1, features.size());
629 public void testExtension() {
630 Module testModule = TestUtils.findModule(modules, "types3");
631 List<ExtensionDefinition> extensions = testModule
632 .getExtensionSchemaNodes();
633 assertEquals(1, extensions.size());
634 ExtensionDefinition extension = extensions.get(0);
635 assertEquals("name", extension.getArgument());
636 assertFalse(extension.isYinElement());
640 public void testNotification() {
641 Module testModule = TestUtils.findModule(modules, "types3");
642 URI expectedNamespace = URI.create("urn:simple.container.demo.test");
643 String expectedPrefix = "t3";
644 Date expectedRevision = TestUtils.createDate("2013-02-27");
646 Set<NotificationDefinition> notifications = testModule
648 assertEquals(1, notifications.size());
650 NotificationDefinition notification = notifications.iterator().next();
651 // test SchemaNode args
652 QName expectedQName = new QName(expectedNamespace, expectedRevision,
653 expectedPrefix, "event");
654 assertEquals(expectedQName, notification.getQName());
655 SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace,
656 expectedRevision, expectedPrefix, "event");
657 assertEquals(expectedPath, notification.getPath());
658 assertNull(notification.getDescription());
659 assertNull(notification.getReference());
660 assertEquals(Status.CURRENT, notification.getStatus());
661 assertEquals(0, notification.getUnknownSchemaNodes().size());
662 // test DataNodeContainer args
663 assertEquals(0, notification.getTypeDefinitions().size());
664 assertEquals(3, notification.getChildNodes().size());
665 assertEquals(0, notification.getGroupings().size());
666 assertEquals(0, notification.getUses().size());
668 LeafSchemaNode eventClass = (LeafSchemaNode) notification
669 .getDataChildByName("event-class");
670 assertTrue(eventClass.getType() instanceof StringType);
671 AnyXmlSchemaNode reportingEntity = (AnyXmlSchemaNode) notification
672 .getDataChildByName("reporting-entity");
673 assertNotNull(reportingEntity);
674 LeafSchemaNode severity = (LeafSchemaNode) notification
675 .getDataChildByName("severity");
676 assertTrue(severity.getType() instanceof StringType);
680 public void testRpc() {
681 Module testModule = TestUtils.findModule(modules, "types3");
683 Set<RpcDefinition> rpcs = testModule.getRpcs();
684 assertEquals(1, rpcs.size());
686 RpcDefinition rpc = rpcs.iterator().next();
687 assertEquals("Retrieve all or part of a specified configuration.",
688 rpc.getDescription());
689 assertEquals("RFC 6241, Section 7.1", rpc.getReference());
691 ContainerSchemaNode input = rpc.getInput();
692 assertNotNull(input.getDataChildByName("source"));
693 assertNotNull(input.getDataChildByName("filter"));
694 ContainerSchemaNode output = rpc.getOutput();
695 assertNotNull(output.getDataChildByName("data"));