2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.stmt.test;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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;
29 public class MoreRevisionsTest {
31 private static final YangStatementSourceImpl REVFILE = new YangStatementSourceImpl(
32 "/semantic-statement-parser/revisions/more-revisions-test.yang",
35 private static final YangStatementSourceImpl TED_20130712 = new YangStatementSourceImpl(
36 "/semantic-statement-parser/two-revisions/ted@2013-07-12.yang",
39 private static final YangStatementSourceImpl TED_20131021 = new YangStatementSourceImpl(
40 "/semantic-statement-parser/two-revisions/ted@2013-10-21.yang",
43 private static final YangStatementSourceImpl IETF_TYPES = new YangStatementSourceImpl(
44 "/ietf/ietf-inet-types@2010-09-24.yang", false);
46 private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20130712 = new YangStatementSourceImpl(
47 "/ietf/network-topology@2013-07-12.yang", false);
49 private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl(
50 "/ietf/network-topology@2013-10-21.yang", false);
52 private static final YangStatementSourceImpl ISIS_20130712 = new YangStatementSourceImpl(
53 "/semantic-statement-parser/two-revisions/isis-topology@2013-07-12.yang",
56 private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl(
57 "/semantic-statement-parser/two-revisions/isis-topology@2013-10-21.yang",
60 private static final YangStatementSourceImpl L3_20130712 = new YangStatementSourceImpl(
61 "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-07-12.yang",
64 private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl(
65 "/semantic-statement-parser/two-revisions/l3-unicast-igp-topology@2013-10-21.yang",
69 public void readAndParseYangFileTest() throws SourceException,
71 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
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");
83 public void twoRevisionsTest() throws SourceException, ReactorException {
84 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
87 reactor.addSources(TED_20130712, TED_20131021, IETF_TYPES);
89 EffectiveSchemaContext result = reactor.buildEffective();
90 assertNotNull(result);
95 public void twoRevisionsTest2() throws SourceException, ReactorException {
96 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
99 reactor.addSources(NETWORK_TOPOLOGY_20130712,
100 NETWORK_TOPOLOGY_20131021, IETF_TYPES);
102 EffectiveSchemaContext result = reactor.buildEffective();
103 assertNotNull(result);
104 Set<Module> modules = result.getModules();
106 assertEquals(3, modules.size());
107 assertEquals(2, StmtTestUtils.findModules(modules, "network-topology")
112 public void moreRevisionsListKeyTest() throws SourceException,
114 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
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);
121 EffectiveSchemaContext result = reactor.buildEffective();
122 assertNotNull(result);
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);