Bug 3670 (part 1/5): Use of new statement parser in yang-maven-plugin
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / MoreRevisionsTest.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yangtools.yang.stmt.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import java.util.Set;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QNameModule;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
28
29 public class MoreRevisionsTest {
30
31     private static final YangStatementSourceImpl REVFILE = new YangStatementSourceImpl(
32             "/semantic-statement-parser/revisions/more-revisions-test.yang",
33             false);
34
35     private static final YangStatementSourceImpl TED_20130712 = new YangStatementSourceImpl(
36             "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang",
37             false);
38
39     private static final YangStatementSourceImpl TED_20131021 = new YangStatementSourceImpl(
40             "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang",
41             false);
42
43     private static final YangStatementSourceImpl IETF_TYPES = new YangStatementSourceImpl(
44             "/ietf/ietf-inet-types@2010-09-24.yang", false);
45
46     private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20130712 = new YangStatementSourceImpl(
47             "/ietf/network-topology@2013-07-12.yang", false);
48
49     private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl(
50             "/ietf/network-topology@2013-10-21.yang", false);
51
52     private static final YangStatementSourceImpl ISIS_20130712 = new YangStatementSourceImpl(
53             "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang",
54             false);
55
56     private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl(
57             "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang",
58             false);
59
60     private static final YangStatementSourceImpl L3_20130712 = new YangStatementSourceImpl(
61             "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang",
62             false);
63
64     private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl(
65             "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang",
66             false);
67
68     @Test
69     public void readAndParseYangFileTest() throws SourceException,
70             ReactorException {
71         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
72                 .newBuild();
73         reactor.addSource(REVFILE);
74         EffectiveSchemaContext result = reactor.buildEffective();
75         assertNotNull(result);
76         final Module moduleByName = result.getModules().iterator().next();
77         final QNameModule qNameModule = moduleByName.getQNameModule();
78         final String formattedRevision = qNameModule.getFormattedRevision();
79         assertEquals(formattedRevision, "2015-06-07");
80     }
81
82     @Test
83     public void twoRevisionsTest() throws SourceException, ReactorException {
84         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
85                 .newBuild();
86
87         reactor.addSources(TED_20130712, TED_20131021, IETF_TYPES);
88
89         EffectiveSchemaContext result = reactor.buildEffective();
90         assertNotNull(result);
91
92     }
93
94     @Test
95     public void twoRevisionsTest2() throws SourceException, ReactorException {
96         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
97                 .newBuild();
98
99         reactor.addSources(NETWORK_TOPOLOGY_20130712,
100                 NETWORK_TOPOLOGY_20131021, IETF_TYPES);
101
102         EffectiveSchemaContext result = reactor.buildEffective();
103         assertNotNull(result);
104         Set<Module> modules = result.getModules();
105
106         assertEquals(3, modules.size());
107         assertEquals(2, StmtTestUtils.findModules(modules, "network-topology")
108                 .size());
109     }
110
111     @Test
112     public void moreRevisionsListKeyTest() throws SourceException,
113             ReactorException {
114         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
115                 .newBuild();
116
117         reactor.addSources(TED_20130712, TED_20131021, ISIS_20130712,
118                 ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES,
119                 NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
120
121         EffectiveSchemaContext result = reactor.buildEffective();
122         assertNotNull(result);
123     }
124
125     @Test
126     public void multipleRevisionsTest() throws SourceException,
127             ReactorException, FileNotFoundException, URISyntaxException {
128         for (int i = 0; i < 25; i++) {
129             SchemaContext context = StmtTestUtils
130                     .parseYangSources("/semantic-statement-parser/multiple-revisions");
131             assertNotNull(context);
132         }
133     }
134
135 }