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.model.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 YangModelParserTest {
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 AugmentationSchema augment = availableAugmentations.iterator().next();
175 ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
176 .getDataChildByName("augment-holder");
177 assertNotNull(augmentHolder);
178 // test ListSchemaNode args
179 List<QName> expectedKey = new ArrayList<QName>();
180 expectedKey.add(new QName(expectedNamespace, expectedRevision,
181 expectedPrefix, "ifIndex"));
182 assertEquals(expectedKey, ifEntry.getKeyDefinition());
183 assertFalse(ifEntry.isUserOrdered());
184 // test DataNodeContainer args
185 assertEquals(0, ifEntry.getTypeDefinitions().size());
186 assertEquals(4, ifEntry.getChildNodes().size());
187 assertEquals(0, ifEntry.getGroupings().size());
188 assertEquals(0, ifEntry.getUses().size());
190 LeafSchemaNode ifIndex = (LeafSchemaNode) ifEntry
191 .getDataChildByName("ifIndex");
192 assertTrue(ifIndex.getType() instanceof Uint32);
193 LeafSchemaNode ifMtu = (LeafSchemaNode) ifEntry
194 .getDataChildByName("ifMtu");
195 assertTrue(ifMtu.getType() instanceof Int32);
199 public void testAugmentResolving() {
201 Module module1 = TestUtils.findModule(modules, "types1");
203 Set<AugmentationSchema> module1Augmentations = module1
205 AugmentationSchema augment1 = module1Augmentations.iterator().next();
206 LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1
207 .getDataChildByName("ds0ChannelNumber");
208 assertTrue(augmentedLeafDefinition.isAugmenting());
211 Module module2 = TestUtils.findModule(modules, "types2");
213 ContainerSchemaNode interfaces = (ContainerSchemaNode) module2
214 .getDataChildByName("interfaces");
215 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
216 .getDataChildByName("ifEntry");
217 ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry
218 .getDataChildByName("augment-holder");
219 Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer
220 .getAvailableAugmentations();
221 LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer
222 .getDataChildByName("ds0ChannelNumber");
223 assertTrue(augmentedLeaf.isAugmenting());
224 assertEquals(augmentedLeafDefinition, augmentedLeaf);
226 Set<AugmentationSchema> ifEntryAugments = ifEntry
227 .getAvailableAugmentations();
228 assertEquals(2, ifEntryAugments.size());
231 Module module3 = TestUtils.findModule(modules, "types3");
233 Set<AugmentationSchema> module3Augmentations = module3
235 assertEquals(2, module3Augmentations.size());
236 AugmentationSchema augment3 = module3Augmentations.iterator().next();
237 ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
238 .getDataChildByName("augment-holder");
239 assertTrue(augmentedContainerDefinition.isAugmenting());
242 assertEquals(augmentedContainer, augmentedContainerDefinition);
243 assertEquals(augmentedContainerAugments.iterator().next(), augment1);
245 assertEquals(augmentedLeaf, augmentedLeafDefinition);
246 assertEquals(ifEntryAugments.iterator().next(), augment3);
250 public void testAugmentTarget() {
251 Module test = TestUtils.findModule(modules, "types2");
253 ContainerSchemaNode interfaces = (ContainerSchemaNode) test
254 .getDataChildByName("interfaces");
255 ListSchemaNode ifEntry = (ListSchemaNode) interfaces
256 .getDataChildByName("ifEntry");
257 Set<AugmentationSchema> augmentations = ifEntry
258 .getAvailableAugmentations();
259 assertEquals(2, augmentations.size());
261 AugmentationSchema augment = augmentations.iterator().next();
263 ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
264 .getDataChildByName("augment-holder");
265 assertNotNull(augmentHolder);
266 assertTrue(augmentHolder.isAugmenting());
267 QName augmentHolderQName = augmentHolder.getQName();
268 assertEquals("augment-holder", augmentHolderQName.getLocalName());
269 assertEquals("t3", augmentHolderQName.getPrefix());
270 assertEquals("Description for augment holder",
271 augmentHolder.getDescription());
275 public void testTypedefRangesResolving() {
276 Module testModule = TestUtils.findModule(modules, "types1");
278 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
279 .getDataChildByName("testleaf");
280 ExtendedType leafType = (ExtendedType) testleaf.getType();
281 assertEquals("my-type1", leafType.getQName().getLocalName());
282 assertEquals("t2", leafType.getQName().getPrefix());
283 ExtendedType baseType = (ExtendedType) leafType.getBaseType();
284 assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
285 assertEquals("t2", baseType.getQName().getPrefix());
287 List<RangeConstraint> ranges = leafType.getRanges();
288 assertEquals(1, ranges.size());
289 RangeConstraint range = ranges.get(0);
290 assertEquals(11L, range.getMin());
291 assertEquals(20L, range.getMax());
295 public void testTypedefPatternsResolving() {
296 Module testModule = TestUtils.findModule(modules, "types1");
298 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
299 .getDataChildByName("test-string-leaf");
300 ExtendedType testleafType = (ExtendedType) testleaf.getType();
301 QName testleafTypeQName = testleafType.getQName();
302 assertEquals("my-string-type-ext", testleafTypeQName.getLocalName());
303 assertEquals("t2", testleafTypeQName.getPrefix());
305 Set<String> expectedRegex = new HashSet<String>();
306 expectedRegex.add("[a-k]*");
307 expectedRegex.add("[b-u]*");
308 expectedRegex.add("[e-z]*");
310 Set<String> actualRegex = new HashSet<String>();
311 List<PatternConstraint> patterns = testleafType.getPatterns();
312 assertEquals(3, patterns.size());
313 for (PatternConstraint pc : patterns) {
314 actualRegex.add(pc.getRegularExpression());
316 assertEquals(expectedRegex, actualRegex);
318 TypeDefinition<?> baseType = testleafType.getBaseType();
319 assertEquals("my-string-type2", baseType.getQName().getLocalName());
321 List<LengthConstraint> lengths = testleafType.getLengths();
322 assertEquals(1, lengths.size());
324 LengthConstraint length = lengths.get(0);
325 assertEquals(5L, length.getMin());
326 assertEquals(10L, length.getMax());
330 public void testTypedefLengthsResolving() {
331 Module testModule = TestUtils.findModule(modules, "types1");
333 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
334 .getDataChildByName("leaf-with-length");
335 ExtendedType testleafType = (ExtendedType) testleaf.getType();
336 assertEquals("my-string-type", testleafType.getQName().getLocalName());
338 List<LengthConstraint> lengths = testleafType.getLengths();
339 assertEquals(1, lengths.size());
341 LengthConstraint length = lengths.get(0);
342 assertEquals(7L, length.getMin());
343 assertEquals(10L, length.getMax());
347 public void testTypeDef() {
348 Module testModule = TestUtils.findModule(modules, "types2");
350 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
351 .getDataChildByName("nested-type-leaf");
352 ExtendedType testleafType = (ExtendedType) testleaf.getType();
353 assertEquals("my-type1", testleafType.getQName().getLocalName());
355 ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
356 assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
358 Int32 int32base = (Int32) baseType.getBaseType();
359 List<RangeConstraint> ranges = int32base.getRangeStatements();
360 assertEquals(1, ranges.size());
361 RangeConstraint range = ranges.get(0);
362 assertEquals(2L, range.getMin());
363 assertEquals(20L, range.getMax());
367 public void testTypedefDecimal1() {
368 Module testModule = TestUtils.findModule(modules, "types1");
370 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
371 .getDataChildByName("test-decimal-leaf");
372 ExtendedType type = (ExtendedType) testleaf.getType();
373 assertEquals(4, (int)type.getFractionDigits());
375 Decimal64 baseType = (Decimal64) type.getBaseType();
376 assertEquals(6, (int) baseType.getFractionDigits());
380 public void testTypedefDecimal2() {
381 Module testModule = TestUtils.findModule(modules, "types1");
383 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
384 .getDataChildByName("test-decimal-leaf2");
385 TypeDefinition<?> baseType = testleaf.getType().getBaseType();
386 assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
387 Decimal64 baseTypeCast = (Decimal64) baseType;
388 assertEquals(5, (int) baseTypeCast.getFractionDigits());
392 public void testTypedefUnion() {
393 Module testModule = TestUtils.findModule(modules, "types1");
395 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
396 .getDataChildByName("union-leaf");
397 ExtendedType testleafType = (ExtendedType) testleaf.getType();
398 assertEquals("my-union-ext", testleafType.getQName().getLocalName());
400 ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
401 assertEquals("my-union", baseType.getQName().getLocalName());
403 UnionType unionBase = (UnionType) baseType.getBaseType();
405 List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
406 Int16 unionType1 = (Int16) unionTypes.get(0);
407 List<RangeConstraint> ranges = unionType1.getRangeStatements();
408 assertEquals(1, ranges.size());
409 RangeConstraint range = ranges.get(0);
410 assertEquals(1L, range.getMin());
411 assertEquals(100L, range.getMax());
413 assertTrue(unionTypes.get(0) instanceof Int16);
414 assertTrue(unionTypes.get(1) instanceof Int32);
418 public void testNestedUnionResolving1() {
419 Module testModule = TestUtils.findModule(modules, "types1");
421 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
422 .getDataChildByName("nested-union-leaf");
424 ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType();
425 assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
427 ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType();
428 assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
430 UnionType unionType1 = (UnionType) nestedUnion2.getBaseType();
431 List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
432 assertEquals(2, unionTypes.size());
433 assertTrue(unionTypes.get(0) instanceof StringType);
434 assertTrue(unionTypes.get(1) instanceof ExtendedType);
436 ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1);
437 ExtendedType extendedUnionBase = (ExtendedType) extendedUnion
439 assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
441 UnionType extendedTargetUnion = (UnionType) extendedUnionBase
443 List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion
445 assertTrue(extendedTargetTypes.get(0) instanceof Int16);
446 assertTrue(extendedTargetTypes.get(1) instanceof Int32);
448 Int16 int16 = (Int16) extendedTargetTypes.get(0);
449 List<RangeConstraint> ranges = int16.getRangeStatements();
450 assertEquals(1, ranges.size());
451 RangeConstraint range = ranges.get(0);
452 assertEquals(1L, range.getMin());
453 assertEquals(100L, range.getMax());
457 public void testNestedUnionResolving2() {
458 Module testModule = TestUtils.findModule(modules, "types1");
460 LeafSchemaNode testleaf = (LeafSchemaNode) testModule
461 .getDataChildByName("custom-union-leaf");
463 ExtendedType testleafType = (ExtendedType) testleaf.getType();
464 QName testleafTypeQName = testleafType.getQName();
465 assertEquals(URI.create("urn:simple.container.demo.test"),
466 testleafTypeQName.getNamespace());
467 assertEquals(TestUtils.createDate("2013-02-27"),
468 testleafTypeQName.getRevision());
469 assertEquals("t3", testleafTypeQName.getPrefix());
470 assertEquals("union1", testleafTypeQName.getLocalName());
472 ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
473 QName union2QName = union2.getQName();
474 assertEquals(URI.create("urn:simple.container.demo.test"),
475 union2QName.getNamespace());
476 assertEquals(TestUtils.createDate("2013-02-27"),
477 union2QName.getRevision());
478 assertEquals("t3", union2QName.getPrefix());
479 assertEquals("union2", union2QName.getLocalName());
481 UnionType union2Base = (UnionType) union2.getBaseType();
482 List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
483 assertEquals(2, unionTypes.size());
484 assertTrue(unionTypes.get(0) instanceof Int32);
485 assertTrue(unionTypes.get(1) instanceof ExtendedType);
487 ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
488 QName nestedUnion2QName = nestedUnion2.getQName();
489 assertEquals(URI.create("urn:simple.types.data.demo"),
490 nestedUnion2QName.getNamespace());
491 assertEquals(TestUtils.createDate("2013-02-27"),
492 nestedUnion2QName.getRevision());
493 assertEquals("t2", nestedUnion2QName.getPrefix());
494 assertEquals("nested-union2", nestedUnion2QName.getLocalName());
496 UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
497 List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
498 assertEquals(2, nestedUnion2Types.size());
499 assertTrue(nestedUnion2Types.get(0) instanceof StringType);
500 assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
502 ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
503 QName myUnionExtQName = myUnionExt.getQName();
504 assertEquals(URI.create("urn:simple.types.data.demo"),
505 myUnionExtQName.getNamespace());
506 assertEquals(TestUtils.createDate("2013-02-27"),
507 myUnionExtQName.getRevision());
508 assertEquals("t2", myUnionExtQName.getPrefix());
509 assertEquals("my-union-ext", myUnionExtQName.getLocalName());
511 ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
512 QName myUnionQName = myUnion.getQName();
513 assertEquals(URI.create("urn:simple.types.data.demo"),
514 myUnionQName.getNamespace());
515 assertEquals(TestUtils.createDate("2013-02-27"),
516 myUnionQName.getRevision());
517 assertEquals("t2", myUnionQName.getPrefix());
518 assertEquals("my-union", myUnionQName.getLocalName());
520 UnionType myUnionBase = (UnionType) myUnion.getBaseType();
521 List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
522 assertEquals(2, myUnionBaseTypes.size());
523 assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
524 assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
525 Int16 int16 = (Int16) myUnionBaseTypes.get(0);
526 List<RangeConstraint> ranges = int16.getRangeStatements();
527 assertEquals(1, ranges.size());
528 RangeConstraint range = ranges.get(0);
529 assertEquals(1L, range.getMin());
530 assertEquals(100L, range.getMax());
534 public void testRefine() {
535 Module testModule = TestUtils.findModule(modules, "types2");
537 ContainerSchemaNode peer = (ContainerSchemaNode) testModule
538 .getDataChildByName("peer");
539 ContainerSchemaNode destination = (ContainerSchemaNode) peer
540 .getDataChildByName("destination");
541 Set<UsesNode> usesNodes = destination.getUses();
542 assertEquals(1, usesNodes.size());
543 UsesNode usesNode = usesNodes.iterator().next();
544 Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
545 assertEquals(2, refines.size());
547 for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
548 SchemaNode value = entry.getValue();
550 if (value instanceof LeafSchemaNode) {
551 LeafSchemaNode refineLeaf = (LeafSchemaNode) value;
552 assertNotNull(refineLeaf);
554 ContainerSchemaNode refineContainer = (ContainerSchemaNode) value;
555 Set<MustDefinition> mustConstraints = refineContainer
556 .getConstraints().getMustConstraints();
557 assertEquals(1, mustConstraints.size());
558 MustDefinition must = mustConstraints.iterator().next();
559 assertEquals("must-condition", must.toString());
560 assertEquals("An error message test", must.getErrorMessage());
561 assertEquals(("An error app tag test"), must.getErrorAppTag());
567 public void testChoice() {
568 Module testModule = TestUtils.findModule(modules, "types1");
569 ContainerSchemaNode peer = (ContainerSchemaNode) testModule
570 .getDataChildByName("transfer");
571 ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
572 Set<ChoiceCaseNode> cases = how.getCases();
573 assertEquals(3, cases.size());
577 public void testAnyXml() {
578 Module testModule = TestUtils.findModule(modules, "types1");
579 AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule
580 .getDataChildByName("data");
585 public void testDeviation() {
586 Module testModule = TestUtils.findModule(modules, "types1");
587 Set<Deviation> deviations = testModule.getDeviations();
588 assertEquals(1, deviations.size());
590 Deviation dev = deviations.iterator().next();
591 SchemaPath expectedPath = TestUtils.createPath(true,
594 assertEquals(expectedPath, dev.getTargetPath());
595 assertEquals(Deviate.ADD, dev.getDeviate());
599 public void testUnknownNode() {
600 Module testModule = TestUtils.findModule(modules, "types3");
601 ContainerSchemaNode network = (ContainerSchemaNode)testModule.getDataChildByName("network");
602 List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
603 assertEquals(1, unknownNodes.size());
607 public void testFeature() {
608 Module testModule = TestUtils.findModule(modules, "types3");
609 Set<FeatureDefinition> features = testModule.getFeatures();
610 assertEquals(1, features.size());
614 public void testExtension() {
615 Module testModule = TestUtils.findModule(modules, "types3");
616 List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
617 assertEquals(1, extensions.size());
618 ExtensionDefinition extension = extensions.get(0);
619 assertEquals("name", extension.getArgument());
620 assertFalse(extension.isYinElement());
624 public void testNotification() {
625 Module testModule = TestUtils.findModule(modules, "types3");
626 URI expectedNamespace = URI.create("urn:simple.container.demo.test");
627 String expectedPrefix = "t3";
628 Date expectedRevision = TestUtils.createDate("2013-02-27");
630 Set<NotificationDefinition> notifications = testModule.getNotifications();
631 assertEquals(1, notifications.size());
633 NotificationDefinition notification = notifications.iterator().next();
634 // test SchemaNode args
635 QName expectedQName = new QName(expectedNamespace, expectedRevision,
636 expectedPrefix, "event");
637 assertEquals(expectedQName, notification.getQName());
638 SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace,
639 expectedRevision, expectedPrefix, "event");
640 assertEquals(expectedPath, notification.getPath());
641 assertNull(notification.getDescription());
642 assertNull(notification.getReference());
643 assertEquals(Status.CURRENT, notification.getStatus());
644 assertEquals(0, notification.getUnknownSchemaNodes().size());
645 // test DataNodeContainer args
646 assertEquals(0, notification.getTypeDefinitions().size());
647 assertEquals(3, notification.getChildNodes().size());
648 assertEquals(0, notification.getGroupings().size());
649 assertEquals(0, notification.getUses().size());
651 LeafSchemaNode eventClass = (LeafSchemaNode) notification
652 .getDataChildByName("event-class");
653 assertTrue(eventClass.getType() instanceof StringType);
654 AnyXmlSchemaNode reportingEntity = (AnyXmlSchemaNode) notification
655 .getDataChildByName("reporting-entity");
656 assertNotNull(reportingEntity);
657 LeafSchemaNode severity = (LeafSchemaNode) notification
658 .getDataChildByName("severity");
659 assertTrue(severity.getType() instanceof StringType);
663 public void testRpc() {
664 Module testModule = TestUtils.findModule(modules, "types3");
666 Set<RpcDefinition> rpcs = testModule.getRpcs();
667 assertEquals(1, rpcs.size());
669 RpcDefinition rpc = rpcs.iterator().next();
670 assertEquals("Retrieve all or part of a specified configuration.", rpc.getDescription());
671 assertEquals("RFC 6241, Section 7.1", rpc.getReference());
673 ContainerSchemaNode input = rpc.getInput();
674 assertNotNull(input.getDataChildByName("source"));
675 assertNotNull(input.getDataChildByName("filter"));
676 ContainerSchemaNode output = rpc.getOutput();
677 assertNotNull(output.getDataChildByName("data"));