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