BUG-4638: Convert to using new types
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / YangParserWithContextTest.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.yangtools.yang.stmt.retest;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import java.io.File;
15 import java.net.URI;
16 import java.text.DateFormat;
17 import java.text.SimpleDateFormat;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import org.junit.Test;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
28 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
30 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
31 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
32 import org.opendaylight.yangtools.yang.model.api.Deviation;
33 import org.opendaylight.yangtools.yang.model.api.Deviation.Deviate;
34 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
35 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
36 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
37 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
38 import org.opendaylight.yangtools.yang.model.api.Module;
39 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
40 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
41 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
42 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
43 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
44 import org.opendaylight.yangtools.yang.model.api.UsesNode;
45 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
46 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
47 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
48 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
49 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
50 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
51 import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
52
53 public class YangParserWithContextTest {
54     private final DateFormat simpleDateFormat = new SimpleDateFormat(
55             "yyyy-MM-dd");
56     private final YangParserImpl parser = new YangParserImpl();
57
58     private static final YangStatementSourceImpl BAR = new YangStatementSourceImpl(
59             "/model/bar.yang", false);
60     private static final YangStatementSourceImpl BAZ = new YangStatementSourceImpl(
61             "/model/baz.yang", false);
62     private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl(
63             "/model/foo.yang", false);
64     private static final YangStatementSourceImpl SUBFOO = new YangStatementSourceImpl(
65             "/model/subfoo.yang", false);
66
67     private static final YangStatementSourceImpl[] IETF = new YangStatementSourceImpl[] {
68         new YangStatementSourceImpl("/ietf/iana-afn-safi@2012-06-04.yang", false),
69         new YangStatementSourceImpl("/ietf/iana-if-type@2012-06-05.yang", false),
70         new YangStatementSourceImpl("/ietf/iana-timezones@2012-07-09.yang", false),
71         new YangStatementSourceImpl("/ietf/ietf-inet-types@2010-09-24.yang", false),
72         new YangStatementSourceImpl("/ietf/ietf-yang-types@2010-09-24.yang", false),
73         new YangStatementSourceImpl("/ietf/network-topology@2013-07-12.yang", false),
74         new YangStatementSourceImpl("/ietf/network-topology@2013-10-21.yang", false)
75     };
76
77     @Test
78     public void testTypeFromContext() throws Exception {
79
80         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
81                 .newBuild();
82
83         YangStatementSourceImpl types = new YangStatementSourceImpl(
84                 "/types/custom-types-test@2012-4-4.yang", false);
85         YangStatementSourceImpl test1 = new YangStatementSourceImpl(
86                 "/context-test/test1.yang", false);
87
88         StmtTestUtils.addSources(reactor, IETF);
89         StmtTestUtils.addSources(reactor, types, test1);
90
91         SchemaContext context = reactor.buildEffective();
92
93         Module module = context.findModuleByName("test1",
94                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-06-18"));
95         assertNotNull(module);
96
97 //        String resource = "/ietf/ietf-inet-types@2010-09-24.yang";
98 //        InputStream stream = new FileInputStream(new File(getClass()
99 //                .getResource(resource).toURI()));
100 //        SchemaContext context = parser.resolveSchemaContext(TestUtils
101 //                .loadModules(Lists.newArrayList(stream)));
102 //        stream.close();
103 //
104 //        resource = "/context-test/test1.yang";
105 //        InputStream stream2 = new FileInputStream(new File(getClass()
106 //                .getResource(resource).toURI()));
107 //        Module module = TestUtils.loadModuleWithContext("test1", stream2,
108 //                context);
109 //        stream2.close();
110 //        assertNotNull(module);
111
112         LeafSchemaNode leaf = (LeafSchemaNode) module.getDataChildByName("id");
113
114         assertTrue(leaf.getType() instanceof UnsignedIntegerTypeDefinition);
115         UnsignedIntegerTypeDefinition leafType = (UnsignedIntegerTypeDefinition) leaf.getType();
116         QName qname = leafType.getQName();
117         assertEquals(URI.create("urn:simple.demo.test1"), qname.getNamespace());
118         assertEquals(simpleDateFormat.parse("2013-06-18"), qname.getRevision());
119         assertEquals("port-number", qname.getLocalName());
120
121         UnsignedIntegerTypeDefinition leafBaseType = leafType.getBaseType();
122         qname = leafBaseType.getQName();
123         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-inet-types"),
124                 qname.getNamespace());
125         assertEquals(simpleDateFormat.parse("2010-09-24"), qname.getRevision());
126         assertEquals("port-number", qname.getLocalName());
127
128         UnsignedIntegerTypeDefinition dscpExt = (UnsignedIntegerTypeDefinition) TestUtils.findTypedef(
129                 module.getTypeDefinitions(), "dscp-ext");
130         List<RangeConstraint> ranges = dscpExt.getRangeConstraints();
131         assertEquals(1, ranges.size());
132         RangeConstraint range = ranges.get(0);
133         assertEquals(0, range.getMin().intValue());
134         assertEquals(63, range.getMax().intValue());
135     }
136
137     @Test
138     public void testUsesFromContext() throws Exception {
139         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
140                 .newBuild();
141
142         YangStatementSourceImpl test2 = new YangStatementSourceImpl(
143                 "/context-test/test2.yang", false);
144         StmtTestUtils.addSources(reactor, BAZ, FOO, BAR, SUBFOO, test2);
145         SchemaContext context = reactor.buildEffective();
146
147         // Module testModule;
148         // try (InputStream stream = new FileInputStream(new
149         // File(getClass().getResource("/context-test/test2.yang")
150         // .toURI()))) {
151         // testModule = TestUtils.loadModuleWithContext("test2", stream,
152         // context);
153         // }
154         // assertNotNull(testModule);
155
156         // suffix _u = added by uses
157         // suffix _g = defined in grouping from context
158
159         // get grouping
160         Module testModule = context.findModuleByName("test2",
161                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-06-18"));
162         assertNotNull(testModule);
163
164         Module contextModule = context
165                 .findModuleByNamespace(URI.create("urn:opendaylight.baz"))
166                 .iterator().next();
167         assertNotNull(contextModule);
168         Set<GroupingDefinition> groupings = contextModule.getGroupings();
169         assertEquals(1, groupings.size());
170         GroupingDefinition grouping = groupings.iterator().next();
171
172         // get node containing uses
173         ContainerSchemaNode peer = (ContainerSchemaNode) testModule
174                 .getDataChildByName("peer");
175         ContainerSchemaNode destination = (ContainerSchemaNode) peer
176                 .getDataChildByName("destination");
177
178         // check uses
179         Set<UsesNode> uses = destination.getUses();
180         assertEquals(1, uses.size());
181
182         // check uses process
183         AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination
184                 .getDataChildByName("data");
185         assertNotNull(data_u);
186         assertTrue(data_u.isAddedByUses());
187
188         AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping
189                 .getDataChildByName("data");
190         assertNotNull(data_g);
191         assertFalse(data_g.isAddedByUses());
192         assertFalse(data_u.equals(data_g));
193
194         ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination
195                 .getDataChildByName("how");
196         assertNotNull(how_u);
197         assertTrue(how_u.isAddedByUses());
198
199         ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping
200                 .getDataChildByName("how");
201         assertNotNull(how_g);
202         assertFalse(how_g.isAddedByUses());
203         assertFalse(how_u.equals(how_g));
204
205         LeafSchemaNode address_u = (LeafSchemaNode) destination
206                 .getDataChildByName("address");
207         assertNotNull(address_u);
208         assertTrue(address_u.isAddedByUses());
209
210         LeafSchemaNode address_g = (LeafSchemaNode) grouping
211                 .getDataChildByName("address");
212         assertNotNull(address_g);
213         assertFalse(address_g.isAddedByUses());
214         assertFalse(address_u.equals(address_g));
215
216         ContainerSchemaNode port_u = (ContainerSchemaNode) destination
217                 .getDataChildByName("port");
218         assertNotNull(port_u);
219         assertTrue(port_u.isAddedByUses());
220
221         ContainerSchemaNode port_g = (ContainerSchemaNode) grouping
222                 .getDataChildByName("port");
223         assertNotNull(port_g);
224         assertFalse(port_g.isAddedByUses());
225         assertFalse(port_u.equals(port_g));
226
227         ListSchemaNode addresses_u = (ListSchemaNode) destination
228                 .getDataChildByName("addresses");
229         assertNotNull(addresses_u);
230         assertTrue(addresses_u.isAddedByUses());
231
232         ListSchemaNode addresses_g = (ListSchemaNode) grouping
233                 .getDataChildByName("addresses");
234         assertNotNull(addresses_g);
235         assertFalse(addresses_g.isAddedByUses());
236         assertFalse(addresses_u.equals(addresses_g));
237
238         // grouping defined by 'uses'
239         Set<GroupingDefinition> groupings_u = destination.getGroupings();
240         assertEquals(1, groupings_u.size());
241         GroupingDefinition grouping_u = groupings_u.iterator().next();
242         assertTrue(grouping_u.isAddedByUses());
243
244         // grouping defined in 'grouping' node
245         Set<GroupingDefinition> groupings_g = grouping.getGroupings();
246         assertEquals(1, groupings_g.size());
247         GroupingDefinition grouping_g = groupings_g.iterator().next();
248         assertFalse(grouping_g.isAddedByUses());
249         assertFalse(grouping_u.equals(grouping_g));
250
251         List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
252         assertEquals(1, nodes_u.size());
253         UnknownSchemaNode node_u = nodes_u.get(0);
254         assertTrue(node_u.isAddedByUses());
255
256         List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
257         assertEquals(1, nodes_g.size());
258         UnknownSchemaNode node_g = nodes_g.get(0);
259         assertFalse(node_g.isAddedByUses());
260         assertFalse(node_u.equals(node_g));
261     }
262
263     @Test
264     public void testUsesRefineFromContext() throws Exception {
265
266         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
267                 .newBuild();
268
269         YangStatementSourceImpl test2 = new YangStatementSourceImpl(
270                 "/context-test/test2.yang", false);
271         StmtTestUtils.addSources(reactor, BAZ, FOO, BAR, SUBFOO, test2);
272         SchemaContext context = reactor.buildEffective();
273
274         // Module module;
275         // try (InputStream stream = new FileInputStream(new
276         // File(getClass().getResource("/context-test/test2.yang")
277         // .toURI()))) {
278         // module = TestUtils.loadModuleWithContext("test2", stream, context);
279         // }
280         // assertNotNull(module);
281
282         Module module = context.findModuleByName("test2",
283                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-06-18"));
284         assertNotNull(module);
285         ContainerSchemaNode peer = (ContainerSchemaNode) module
286                 .getDataChildByName("peer");
287         ContainerSchemaNode destination = (ContainerSchemaNode) peer
288                 .getDataChildByName("destination");
289         Set<UsesNode> usesNodes = destination.getUses();
290         assertEquals(1, usesNodes.size());
291         UsesNode usesNode = usesNodes.iterator().next();
292
293         // test grouping path
294         List<QName> path = new ArrayList<>();
295         QName qname = QName.create(URI.create("urn:opendaylight.baz"),
296                 simpleDateFormat.parse("2013-02-27"), "target");
297         path.add(qname);
298         SchemaPath expectedPath = SchemaPath.create(path, true);
299         assertEquals(expectedPath, usesNode.getGroupingPath());
300
301         // test refine
302         Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
303         assertEquals(3, refines.size());
304
305         LeafSchemaNode refineLeaf = null;
306         ContainerSchemaNode refineContainer = null;
307         ListSchemaNode refineList = null;
308         for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
309             SchemaNode value = entry.getValue();
310             if (value instanceof LeafSchemaNode) {
311                 refineLeaf = (LeafSchemaNode) value;
312             } else if (value instanceof ContainerSchemaNode) {
313                 refineContainer = (ContainerSchemaNode) value;
314             } else if (value instanceof ListSchemaNode) {
315                 refineList = (ListSchemaNode) value;
316             }
317         }
318
319         // leaf address
320         assertNotNull(refineLeaf);
321         assertEquals("address", refineLeaf.getQName().getLocalName());
322         assertEquals("description of address defined by refine",
323                 refineLeaf.getDescription());
324         assertEquals("address reference added by refine",
325                 refineLeaf.getReference());
326         assertFalse(refineLeaf.isConfiguration());
327         assertTrue(refineLeaf.getConstraints().isMandatory());
328         Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints()
329                 .getMustConstraints();
330         assertEquals(1, leafMustConstraints.size());
331         MustDefinition leafMust = leafMustConstraints.iterator().next();
332         assertEquals(
333                 "ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)",
334                 leafMust.toString());
335
336         // container port
337         assertNotNull(refineContainer);
338         Set<MustDefinition> mustConstraints = refineContainer.getConstraints()
339                 .getMustConstraints();
340         assertTrue(mustConstraints.isEmpty());
341         assertEquals("description of port defined by refine",
342                 refineContainer.getDescription());
343         assertEquals("port reference added by refine",
344                 refineContainer.getReference());
345         assertFalse(refineContainer.isConfiguration());
346         assertTrue(refineContainer.isPresenceContainer());
347
348         // list addresses
349         assertNotNull(refineList);
350         assertEquals("description of addresses defined by refine",
351                 refineList.getDescription());
352         assertEquals("addresses reference added by refine",
353                 refineList.getReference());
354         assertFalse(refineList.isConfiguration());
355         assertEquals(2, (int) refineList.getConstraints().getMinElements());
356         assertEquals(12, (int) refineList.getConstraints().getMaxElements());
357     }
358
359     @Test
360     public void testIdentity() throws Exception {
361
362         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
363                 .newBuild();
364
365         YangStatementSourceImpl types = new YangStatementSourceImpl(
366                 "/types/custom-types-test@2012-4-4.yang", false);
367         YangStatementSourceImpl test3 = new YangStatementSourceImpl(
368                 "/context-test/test3.yang", false);
369
370         StmtTestUtils.addSources(reactor, IETF);
371         StmtTestUtils.addSources(reactor, types, test3);
372         SchemaContext context = reactor.buildEffective();
373
374         Module module = context.findModuleByName("test3",
375                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-06-18"));
376         assertNotNull(module);
377
378 //        SchemaContext context;
379 //        File yangFile = new File(getClass().getResource(
380 //                "/types/custom-types-test@2012-4-4.yang").toURI());
381 //        File dependenciesDir = new File(getClass().getResource("/ietf").toURI());
382 //        YangContextParser parser = new YangParserImpl();
383 //        context = parser.parseFile(yangFile, dependenciesDir);
384 //
385 //        Module module;
386 //        try (InputStream stream = new FileInputStream(new File(getClass()
387 //                .getResource("/context-test/test3.yang").toURI()))) {
388 //            module = TestUtils.loadModuleWithContext("test3", stream, context);
389 //        }
390 //        assertNotNull(module);
391
392         Set<IdentitySchemaNode> identities = module.getIdentities();
393         assertEquals(1, identities.size());
394
395         IdentitySchemaNode identity = identities.iterator().next();
396         QName idQName = identity.getQName();
397         assertEquals(URI.create("urn:simple.demo.test3"),
398                 idQName.getNamespace());
399         assertEquals(simpleDateFormat.parse("2013-06-18"),
400                 idQName.getRevision());
401         assertEquals("pt", idQName.getLocalName());
402
403         IdentitySchemaNode baseIdentity = identity.getBaseIdentity();
404         QName idBaseQName = baseIdentity.getQName();
405         assertEquals(URI.create("urn:custom.types.demo"),
406                 idBaseQName.getNamespace());
407         assertEquals(simpleDateFormat.parse("2012-04-16"),
408                 idBaseQName.getRevision());
409         assertEquals("service-type", idBaseQName.getLocalName());
410     }
411
412     @Test
413     public void testUnknownNodes() throws Exception {
414
415         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
416                 .newBuild();
417
418         YangStatementSourceImpl types = new YangStatementSourceImpl(
419                 "/types/custom-types-test@2012-4-4.yang", false);
420         YangStatementSourceImpl test3 = new YangStatementSourceImpl(
421                 "/context-test/test3.yang", false);
422
423         StmtTestUtils.addSources(reactor, IETF);
424         StmtTestUtils.addSources(reactor, types, test3);
425
426         SchemaContext context = reactor.buildEffective();
427
428         Module module = context.findModuleByName("test3",
429                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-06-18"));
430         assertNotNull(module);
431
432 //        SchemaContext context;
433 //        File yangFile = new File(getClass().getResource(
434 //                "/types/custom-types-test@2012-4-4.yang").toURI());
435 //        File dependenciesDir = new File(getClass().getResource("/ietf").toURI());
436 //        YangContextParser parser = new YangParserImpl();
437 //        context = parser.parseFile(yangFile, dependenciesDir);
438 //
439 //        Module module;
440 //        try (InputStream stream = new FileInputStream(new File(getClass()
441 //                .getResource("/context-test/test3.yang").toURI()))) {
442 //            module = TestUtils.loadModuleWithContext("test3", stream, context);
443 //        }
444
445         ContainerSchemaNode network = (ContainerSchemaNode) module
446                 .getDataChildByName("network");
447         List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
448         assertEquals(1, unknownNodes.size());
449
450         UnknownSchemaNode un = unknownNodes.get(0);
451         QName unType = un.getNodeType();
452         assertEquals(URI.create("urn:custom.types.demo"), unType.getNamespace());
453         assertEquals(simpleDateFormat.parse("2012-04-16"), unType.getRevision());
454         assertEquals("mountpoint", unType.getLocalName());
455         assertEquals("point", un.getNodeParameter());
456         assertNotNull(un.getExtensionDefinition());
457     }
458
459     @Test
460     public void testAugment() throws Exception {
461         // load first module
462         String resource = "/context-augment-test/test4.yang";
463         SchemaContext context = parser.parseFiles(Collections
464                 .singleton(new File(getClass().getResource(resource).toURI())));
465
466         // load another modules and parse them against already existing context
467         File test1 = new File(getClass().getResource(
468                 "/context-augment-test/test1.yang").toURI());
469         File test2 = new File(getClass().getResource(
470                 "/context-augment-test/test2.yang").toURI());
471         File test3 = new File(getClass().getResource(
472                 "/context-augment-test/test3.yang").toURI());
473         Set<Module> modules = parser.parseFiles(
474                 Arrays.asList(test1, test2, test3), context).getModules();
475         assertNotNull(modules);
476
477         Module t4 = TestUtils.findModule(modules, "test4");
478         ContainerSchemaNode interfaces = (ContainerSchemaNode) t4
479                 .getDataChildByName("interfaces");
480         ListSchemaNode ifEntry = (ListSchemaNode) interfaces
481                 .getDataChildByName("ifEntry");
482
483         // test augmentation process
484         ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry
485                 .getDataChildByName("augment-holder");
486         assertNotNull(augmentHolder);
487         DataSchemaNode ds0 = augmentHolder
488                 .getDataChildByName("ds0ChannelNumber");
489         assertNotNull(ds0);
490         DataSchemaNode interfaceId = augmentHolder
491                 .getDataChildByName("interface-id");
492         assertNotNull(interfaceId);
493         DataSchemaNode higherLayerIf = augmentHolder
494                 .getDataChildByName("higher-layer-if");
495         assertNotNull(higherLayerIf);
496         ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder
497                 .getDataChildByName("schemas");
498         assertNotNull(schemas);
499         assertNotNull(schemas.getDataChildByName("id"));
500
501         // test augment target after augmentation: check if it is same instance
502         ListSchemaNode ifEntryAfterAugment = (ListSchemaNode) interfaces
503                 .getDataChildByName("ifEntry");
504         assertTrue(ifEntry == ifEntryAfterAugment);
505     }
506
507     @Test
508     public void testDeviation() throws Exception {
509
510         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
511                 .newBuild();
512
513         YangStatementSourceImpl bar = new YangStatementSourceImpl(
514                 "/model/bar.yang", false);
515         YangStatementSourceImpl deviationTest = new YangStatementSourceImpl(
516                 "/context-test/deviation-test.yang", false);
517
518         StmtTestUtils.addSources(reactor, bar, deviationTest);
519         SchemaContext context = reactor.buildEffective();
520
521         Module testModule = context.findModuleByName("deviation-test",
522                 SimpleDateFormatUtil.getRevisionFormat().parse("2013-02-27"));
523         assertNotNull(testModule);
524
525         // load first module
526 //        SchemaContext context;
527 //        String resource = "/model/bar.yang";
528 //
529 //        try (InputStream stream = new FileInputStream(new File(getClass()
530 //                .getResource(resource).toURI()))) {
531 //            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists
532 //                    .newArrayList(stream)));
533 //        }
534
535         // load another modules and parse them against already existing context
536 //        Set<Module> modules;
537 //        try (InputStream stream = new FileInputStream(new File(getClass()
538 //                .getResource("/context-test/deviation-test.yang").toURI()))) {
539 //            List<InputStream> input = Lists.newArrayList(stream);
540 //            modules = TestUtils.loadModulesWithContext(input, context);
541 //        }
542 //        assertNotNull(modules);
543
544         // test deviation
545         //Module testModule = TestUtils.findModule(modules, "deviation-test");
546
547
548         Set<Deviation> deviations = testModule.getDeviations();
549         assertEquals(1, deviations.size());
550         Deviation dev = deviations.iterator().next();
551
552         assertEquals("system/user ref", dev.getReference());
553
554         URI expectedNS = URI.create("urn:opendaylight.bar");
555         DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
556         Date expectedRev = simpleDateFormat.parse("2013-07-03");
557         List<QName> path = new ArrayList<>();
558         path.add(QName.create(expectedNS, expectedRev, "interfaces"));
559         path.add(QName.create(expectedNS, expectedRev, "ifEntry"));
560         SchemaPath expectedPath = SchemaPath.create(path, true);
561
562         assertEquals(expectedPath, dev.getTargetPath());
563         assertEquals(Deviate.ADD, dev.getDeviate());
564     }
565
566 }