b2a93ea07ec8f1749d6523788d8d51afe00c25b4
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / parser / impl / YangParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang.parser.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.net.URI;
13 import java.util.ArrayList;
14 import java.util.Date;
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19
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;
56
57 public class YangParserTest {
58     private Set<Module> modules;
59
60     @Before
61     public void init() {
62         modules = TestUtils.loadModules("src/test/resources/model");
63         assertEquals(3, modules.size());
64     }
65
66     @Test
67     public void testHeaders() {
68         Module test = TestUtils.findModule(modules, "types1");
69
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());
75
76         Set<ModuleImport> imports = test.getImports();
77         assertEquals(2, imports.size());
78
79         ModuleImport import2 = TestUtils.findImport(imports, "data");
80         assertEquals("types2", import2.getModuleName());
81         assertEquals(TestUtils.createDate("2013-02-27"), import2.getRevision());
82
83         ModuleImport import3 = TestUtils.findImport(imports, "t3");
84         assertEquals("types3", import3.getModuleName());
85         assertEquals(TestUtils.createDate("2013-02-27"), import3.getRevision());
86
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());
92     }
93
94     @Test
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");
100
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());
132
133         ListSchemaNode ifEntry = (ListSchemaNode) interfaces
134                 .getDataChildByName("ifEntry");
135         assertNotNull(ifEntry);
136     }
137
138     @Test
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");
144
145         ContainerSchemaNode interfaces = (ContainerSchemaNode) test
146                 .getDataChildByName("interfaces");
147
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());
185
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);
192     }
193
194     @Test
195     public void testAugmentResolving() {
196         // testfile1
197         Module module1 = TestUtils.findModule(modules, "types1");
198
199         Set<AugmentationSchema> module1Augmentations = module1
200                 .getAugmentations();
201         AugmentationSchema augment1 = module1Augmentations.iterator().next();
202         LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1
203                 .getDataChildByName("ds0ChannelNumber");
204         assertTrue(augmentedLeafDefinition.isAugmenting());
205
206         // testfile2
207         Module module2 = TestUtils.findModule(modules, "types2");
208
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");
215         // Set<AugmentationSchema> augmentedContainerAugments =
216         // augmentedContainer
217         // .getAvailableAugmentations();
218         LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer
219                 .getDataChildByName("ds0ChannelNumber");
220         assertTrue(augmentedLeaf.isAugmenting());
221         assertEquals(augmentedLeafDefinition, augmentedLeaf);
222
223         Set<AugmentationSchema> ifEntryAugments = ifEntry
224                 .getAvailableAugmentations();
225         assertEquals(2, ifEntryAugments.size());
226
227         // testfile3
228         Module module3 = TestUtils.findModule(modules, "types3");
229
230         Set<AugmentationSchema> module3Augmentations = module3
231                 .getAugmentations();
232         assertEquals(2, module3Augmentations.size());
233         // AugmentationSchema augment3 = module3Augmentations.iterator().next();
234         // ContainerSchemaNode augmentedContainerDefinition =
235         // (ContainerSchemaNode) augment3
236         // .getDataChildByName("augment-holder");
237         // assertTrue(augmentedContainerDefinition.isAugmenting());
238         //
239         // // check
240         // assertEquals(augmentedContainer, augmentedContainerDefinition);
241         // assertEquals(augmentedContainerAugments.iterator().next(), augment1);
242         //
243         // assertEquals(augmentedLeaf, augmentedLeafDefinition);
244         // assertEquals(ifEntryAugments.iterator().next(), augment3);
245     }
246
247     @Test
248     public void testAugmentTarget() {
249         Module test = TestUtils.findModule(modules, "types2");
250
251         ContainerSchemaNode interfaces = (ContainerSchemaNode) test
252                 .getDataChildByName("interfaces");
253         ListSchemaNode ifEntry = (ListSchemaNode) interfaces
254                 .getDataChildByName("ifEntry");
255         Set<AugmentationSchema> augmentations = ifEntry
256                 .getAvailableAugmentations();
257         assertEquals(2, augmentations.size());
258
259         // AugmentationSchema augment = augmentations.iterator().next();
260
261         // ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
262         // .getDataChildByName("augment-holder");
263         // assertNotNull(augmentHolder);
264         // assertTrue(augmentHolder.isAugmenting());
265         // QName augmentHolderQName = augmentHolder.getQName();
266         // assertEquals("augment-holder", augmentHolderQName.getLocalName());
267         // assertEquals("t3", augmentHolderQName.getPrefix());
268         // assertEquals("Description for augment holder",
269         // augmentHolder.getDescription());
270     }
271
272     @Test
273     public void testTypedefRangesResolving() {
274         Module testModule = TestUtils.findModule(modules, "types1");
275
276         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
277                 .getDataChildByName("testleaf");
278         ExtendedType leafType = (ExtendedType) testleaf.getType();
279         assertEquals("my-type1", leafType.getQName().getLocalName());
280         assertEquals("t2", leafType.getQName().getPrefix());
281         ExtendedType baseType = (ExtendedType) leafType.getBaseType();
282         assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
283         assertEquals("t2", baseType.getQName().getPrefix());
284
285         List<RangeConstraint> ranges = leafType.getRanges();
286         assertEquals(1, ranges.size());
287         RangeConstraint range = ranges.get(0);
288         assertEquals(11L, range.getMin());
289         assertEquals(20L, range.getMax());
290     }
291
292     @Test
293     public void testTypedefPatternsResolving() {
294         Module testModule = TestUtils.findModule(modules, "types1");
295
296         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
297                 .getDataChildByName("test-string-leaf");
298         ExtendedType testleafType = (ExtendedType) testleaf.getType();
299         QName testleafTypeQName = testleafType.getQName();
300         assertEquals("my-string-type-ext", testleafTypeQName.getLocalName());
301         assertEquals("t2", testleafTypeQName.getPrefix());
302
303         Set<String> expectedRegex = new HashSet<String>();
304         expectedRegex.add("[a-k]*");
305         expectedRegex.add("[b-u]*");
306         expectedRegex.add("[e-z]*");
307
308         Set<String> actualRegex = new HashSet<String>();
309         List<PatternConstraint> patterns = testleafType.getPatterns();
310         assertEquals(3, patterns.size());
311         for (PatternConstraint pc : patterns) {
312             actualRegex.add(pc.getRegularExpression());
313         }
314         assertEquals(expectedRegex, actualRegex);
315
316         TypeDefinition<?> baseType = testleafType.getBaseType();
317         assertEquals("my-string-type2", baseType.getQName().getLocalName());
318
319         List<LengthConstraint> lengths = testleafType.getLengths();
320         assertEquals(1, lengths.size());
321
322         LengthConstraint length = lengths.get(0);
323         assertEquals(5L, length.getMin());
324         assertEquals(10L, length.getMax());
325     }
326
327     @Test
328     public void testTypedefLengthsResolving() {
329         Module testModule = TestUtils.findModule(modules, "types1");
330
331         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
332                 .getDataChildByName("leaf-with-length");
333         ExtendedType testleafType = (ExtendedType) testleaf.getType();
334         assertEquals("my-string-type", testleafType.getQName().getLocalName());
335
336         List<LengthConstraint> lengths = testleafType.getLengths();
337         assertEquals(1, lengths.size());
338
339         LengthConstraint length = lengths.get(0);
340         assertEquals(7L, length.getMin());
341         assertEquals(10L, length.getMax());
342     }
343
344     @Test
345     public void testTypeDef() {
346         Module testModule = TestUtils.findModule(modules, "types2");
347
348         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
349                 .getDataChildByName("nested-type-leaf");
350         ExtendedType testleafType = (ExtendedType) testleaf.getType();
351         assertEquals("my-type1", testleafType.getQName().getLocalName());
352
353         ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
354         assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
355
356         Int32 int32base = (Int32) baseType.getBaseType();
357         List<RangeConstraint> ranges = int32base.getRangeStatements();
358         assertEquals(1, ranges.size());
359         RangeConstraint range = ranges.get(0);
360         assertEquals(2L, range.getMin());
361         assertEquals(20L, range.getMax());
362     }
363
364     @Test
365     public void testTypedefDecimal1() {
366         Module testModule = TestUtils.findModule(modules, "types1");
367
368         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
369                 .getDataChildByName("test-decimal-leaf");
370         ExtendedType type = (ExtendedType) testleaf.getType();
371         assertEquals(4, (int) type.getFractionDigits());
372
373         Decimal64 baseType = (Decimal64) type.getBaseType();
374         assertEquals(6, (int) baseType.getFractionDigits());
375     }
376
377     @Test
378     public void testTypedefDecimal2() {
379         Module testModule = TestUtils.findModule(modules, "types1");
380
381         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
382                 .getDataChildByName("test-decimal-leaf2");
383         TypeDefinition<?> baseType = testleaf.getType().getBaseType();
384         assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
385         Decimal64 baseTypeCast = (Decimal64) baseType;
386         assertEquals(5, (int) baseTypeCast.getFractionDigits());
387     }
388
389     @Test
390     public void testTypedefUnion() {
391         Module testModule = TestUtils.findModule(modules, "types1");
392
393         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
394                 .getDataChildByName("union-leaf");
395         ExtendedType testleafType = (ExtendedType) testleaf.getType();
396         assertEquals("my-union-ext", testleafType.getQName().getLocalName());
397
398         ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
399         assertEquals("my-union", baseType.getQName().getLocalName());
400
401         UnionType unionBase = (UnionType) baseType.getBaseType();
402
403         List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
404         Int16 unionType1 = (Int16) unionTypes.get(0);
405         List<RangeConstraint> ranges = unionType1.getRangeStatements();
406         assertEquals(1, ranges.size());
407         RangeConstraint range = ranges.get(0);
408         assertEquals(1L, range.getMin());
409         assertEquals(100L, range.getMax());
410
411         assertTrue(unionTypes.get(0) instanceof Int16);
412         assertTrue(unionTypes.get(1) instanceof Int32);
413     }
414
415     @Test
416     public void testNestedUnionResolving1() {
417         Module testModule = TestUtils.findModule(modules, "types1");
418
419         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
420                 .getDataChildByName("nested-union-leaf");
421
422         ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType();
423         assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
424
425         ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType();
426         assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
427
428         UnionType unionType1 = (UnionType) nestedUnion2.getBaseType();
429         List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
430         assertEquals(2, unionTypes.size());
431         assertTrue(unionTypes.get(0) instanceof StringType);
432         assertTrue(unionTypes.get(1) instanceof ExtendedType);
433
434         ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1);
435         ExtendedType extendedUnionBase = (ExtendedType) extendedUnion
436                 .getBaseType();
437         assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
438
439         UnionType extendedTargetUnion = (UnionType) extendedUnionBase
440                 .getBaseType();
441         List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion
442                 .getTypes();
443         assertTrue(extendedTargetTypes.get(0) instanceof Int16);
444         assertTrue(extendedTargetTypes.get(1) instanceof Int32);
445
446         Int16 int16 = (Int16) extendedTargetTypes.get(0);
447         List<RangeConstraint> ranges = int16.getRangeStatements();
448         assertEquals(1, ranges.size());
449         RangeConstraint range = ranges.get(0);
450         assertEquals(1L, range.getMin());
451         assertEquals(100L, range.getMax());
452     }
453
454     @Test
455     public void testNestedUnionResolving2() {
456         Module testModule = TestUtils.findModule(modules, "types1");
457
458         LeafSchemaNode testleaf = (LeafSchemaNode) testModule
459                 .getDataChildByName("custom-union-leaf");
460
461         ExtendedType testleafType = (ExtendedType) testleaf.getType();
462         QName testleafTypeQName = testleafType.getQName();
463         assertEquals(URI.create("urn:simple.container.demo.test"),
464                 testleafTypeQName.getNamespace());
465         assertEquals(TestUtils.createDate("2013-02-27"),
466                 testleafTypeQName.getRevision());
467         assertEquals("t3", testleafTypeQName.getPrefix());
468         assertEquals("union1", testleafTypeQName.getLocalName());
469
470         ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
471         QName union2QName = union2.getQName();
472         assertEquals(URI.create("urn:simple.container.demo.test"),
473                 union2QName.getNamespace());
474         assertEquals(TestUtils.createDate("2013-02-27"),
475                 union2QName.getRevision());
476         assertEquals("t3", union2QName.getPrefix());
477         assertEquals("union2", union2QName.getLocalName());
478
479         UnionType union2Base = (UnionType) union2.getBaseType();
480         List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
481         assertEquals(2, unionTypes.size());
482         assertTrue(unionTypes.get(0) instanceof Int32);
483         assertTrue(unionTypes.get(1) instanceof ExtendedType);
484
485         ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
486         QName nestedUnion2QName = nestedUnion2.getQName();
487         assertEquals(URI.create("urn:simple.types.data.demo"),
488                 nestedUnion2QName.getNamespace());
489         assertEquals(TestUtils.createDate("2013-02-27"),
490                 nestedUnion2QName.getRevision());
491         assertEquals("t2", nestedUnion2QName.getPrefix());
492         assertEquals("nested-union2", nestedUnion2QName.getLocalName());
493
494         UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
495         List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
496         assertEquals(2, nestedUnion2Types.size());
497         assertTrue(nestedUnion2Types.get(0) instanceof StringType);
498         assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
499
500         ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
501         QName myUnionExtQName = myUnionExt.getQName();
502         assertEquals(URI.create("urn:simple.types.data.demo"),
503                 myUnionExtQName.getNamespace());
504         assertEquals(TestUtils.createDate("2013-02-27"),
505                 myUnionExtQName.getRevision());
506         assertEquals("t2", myUnionExtQName.getPrefix());
507         assertEquals("my-union-ext", myUnionExtQName.getLocalName());
508
509         ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
510         QName myUnionQName = myUnion.getQName();
511         assertEquals(URI.create("urn:simple.types.data.demo"),
512                 myUnionQName.getNamespace());
513         assertEquals(TestUtils.createDate("2013-02-27"),
514                 myUnionQName.getRevision());
515         assertEquals("t2", myUnionQName.getPrefix());
516         assertEquals("my-union", myUnionQName.getLocalName());
517
518         UnionType myUnionBase = (UnionType) myUnion.getBaseType();
519         List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
520         assertEquals(2, myUnionBaseTypes.size());
521         assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
522         assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
523         Int16 int16 = (Int16) myUnionBaseTypes.get(0);
524         List<RangeConstraint> ranges = int16.getRangeStatements();
525         assertEquals(1, ranges.size());
526         RangeConstraint range = ranges.get(0);
527         assertEquals(1L, range.getMin());
528         assertEquals(100L, range.getMax());
529     }
530
531     @Test
532     public void testRefine() {
533         Module testModule = TestUtils.findModule(modules, "types2");
534
535         ContainerSchemaNode peer = (ContainerSchemaNode) testModule
536                 .getDataChildByName("peer");
537         ContainerSchemaNode destination = (ContainerSchemaNode) peer
538                 .getDataChildByName("destination");
539         Set<UsesNode> usesNodes = destination.getUses();
540         assertEquals(1, usesNodes.size());
541         UsesNode usesNode = usesNodes.iterator().next();
542         Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
543         assertEquals(2, refines.size());
544
545         for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
546             SchemaNode value = entry.getValue();
547
548             if (value instanceof LeafSchemaNode) {
549                 LeafSchemaNode refineLeaf = (LeafSchemaNode) value;
550                 assertNotNull(refineLeaf);
551             } else {
552                 ContainerSchemaNode refineContainer = (ContainerSchemaNode) value;
553                 Set<MustDefinition> mustConstraints = refineContainer
554                         .getConstraints().getMustConstraints();
555                 assertEquals(1, mustConstraints.size());
556                 MustDefinition must = mustConstraints.iterator().next();
557                 assertEquals("must-condition", must.toString());
558                 assertEquals("An error message test", must.getErrorMessage());
559                 assertEquals(("An error app tag test"), must.getErrorAppTag());
560             }
561         }
562     }
563
564     @Test
565     public void testChoice() {
566         Module testModule = TestUtils.findModule(modules, "types1");
567         ContainerSchemaNode peer = (ContainerSchemaNode) testModule
568                 .getDataChildByName("transfer");
569         ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
570         Set<ChoiceCaseNode> cases = how.getCases();
571         assertEquals(3, cases.size());
572     }
573
574     @Test
575     public void testAnyXml() {
576         Module testModule = TestUtils.findModule(modules, "types1");
577         AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule
578                 .getDataChildByName("data");
579         assertNotNull(data);
580     }
581
582     @Test
583     public void testDeviation() {
584         Module testModule = TestUtils.findModule(modules, "types1");
585         Set<Deviation> deviations = testModule.getDeviations();
586         assertEquals(1, deviations.size());
587
588         Deviation dev = deviations.iterator().next();
589         SchemaPath expectedPath = TestUtils.createPath(true, null, null,
590                 "data", "system", "user");
591         assertEquals(expectedPath, dev.getTargetPath());
592         assertEquals(Deviate.ADD, dev.getDeviate());
593     }
594
595     @Test
596     public void testUnknownNode() {
597         Module testModule = TestUtils.findModule(modules, "types3");
598         ContainerSchemaNode network = (ContainerSchemaNode) testModule
599                 .getDataChildByName("network");
600         List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
601         assertEquals(1, unknownNodes.size());
602         UnknownSchemaNode unknownNode = unknownNodes.get(0);
603         assertNotNull(unknownNode.getNodeType());
604         assertEquals("point", unknownNode.getNodeParameter());
605     }
606
607     @Test
608     public void testFeature() {
609         Module testModule = TestUtils.findModule(modules, "types3");
610         Set<FeatureDefinition> features = testModule.getFeatures();
611         assertEquals(1, features.size());
612     }
613
614     @Test
615     public void testExtension() {
616         Module testModule = TestUtils.findModule(modules, "types3");
617         List<ExtensionDefinition> extensions = testModule
618                 .getExtensionSchemaNodes();
619         assertEquals(1, extensions.size());
620         ExtensionDefinition extension = extensions.get(0);
621         assertEquals("name", extension.getArgument());
622         assertFalse(extension.isYinElement());
623     }
624
625     @Test
626     public void testNotification() {
627         Module testModule = TestUtils.findModule(modules, "types3");
628         URI expectedNamespace = URI.create("urn:simple.container.demo.test");
629         String expectedPrefix = "t3";
630         Date expectedRevision = TestUtils.createDate("2013-02-27");
631
632         Set<NotificationDefinition> notifications = testModule
633                 .getNotifications();
634         assertEquals(1, notifications.size());
635
636         NotificationDefinition notification = notifications.iterator().next();
637         // test SchemaNode args
638         QName expectedQName = new QName(expectedNamespace, expectedRevision,
639                 expectedPrefix, "event");
640         assertEquals(expectedQName, notification.getQName());
641         SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace,
642                 expectedRevision, expectedPrefix, "event");
643         assertEquals(expectedPath, notification.getPath());
644         assertNull(notification.getDescription());
645         assertNull(notification.getReference());
646         assertEquals(Status.CURRENT, notification.getStatus());
647         assertEquals(0, notification.getUnknownSchemaNodes().size());
648         // test DataNodeContainer args
649         assertEquals(0, notification.getTypeDefinitions().size());
650         assertEquals(3, notification.getChildNodes().size());
651         assertEquals(0, notification.getGroupings().size());
652         assertEquals(0, notification.getUses().size());
653
654         LeafSchemaNode eventClass = (LeafSchemaNode) notification
655                 .getDataChildByName("event-class");
656         assertTrue(eventClass.getType() instanceof StringType);
657         AnyXmlSchemaNode reportingEntity = (AnyXmlSchemaNode) notification
658                 .getDataChildByName("reporting-entity");
659         assertNotNull(reportingEntity);
660         LeafSchemaNode severity = (LeafSchemaNode) notification
661                 .getDataChildByName("severity");
662         assertTrue(severity.getType() instanceof StringType);
663     }
664
665     @Test
666     public void testRpc() {
667         Module testModule = TestUtils.findModule(modules, "types3");
668
669         Set<RpcDefinition> rpcs = testModule.getRpcs();
670         assertEquals(1, rpcs.size());
671
672         RpcDefinition rpc = rpcs.iterator().next();
673         assertEquals("Retrieve all or part of a specified configuration.",
674                 rpc.getDescription());
675         assertEquals("RFC 6241, Section 7.1", rpc.getReference());
676
677         ContainerSchemaNode input = rpc.getInput();
678         assertNotNull(input.getDataChildByName("source"));
679         assertNotNull(input.getDataChildByName("filter"));
680         ContainerSchemaNode output = rpc.getOutput();
681         assertNotNull(output.getDataChildByName("data"));
682     }
683
684 }