1 package org.opendaylight.yangtools.yang.stmt.test;
4 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
5 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
6 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
7 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
8 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
9 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
10 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
11 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
12 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
19 public class IncludeRevisionsTest {
21 private static final YangStatementSourceImpl EQUAL_ROOT = new YangStatementSourceImpl("/revisions/equal-root.yang");
22 private static final YangStatementSourceImpl EQUAL_REV = new YangStatementSourceImpl("/revisions/equal-rev.yang");
23 private static final YangStatementSourceImpl UNEQUAL_ROOT = new YangStatementSourceImpl("/revisions/unequal-root.yang");
24 private static final YangStatementSourceImpl UNEQUAL_REV = new YangStatementSourceImpl("/revisions/unequal-rev.yang");
25 private static final YangStatementSourceImpl SUBMOD_ONLY_ROOT = new YangStatementSourceImpl("/revisions/submod-only-root.yang");
26 private static final YangStatementSourceImpl SUBMOD_ONLY_REV = new YangStatementSourceImpl("/revisions/submod-only-rev.yang");
27 private static final YangStatementSourceImpl MOD_ONLY_ROOT = new YangStatementSourceImpl("/revisions/mod-only-root.yang");
28 private static final YangStatementSourceImpl MOD_ONLY_REV = new YangStatementSourceImpl("/revisions/mod-only-rev.yang");
29 private static final YangStatementSourceImpl MOD_ONLY_1970_ROOT = new YangStatementSourceImpl("/revisions/mod-1970-root.yang");
30 private static final YangStatementSourceImpl MOD_ONLY_1970_REV = new YangStatementSourceImpl("/revisions/mod-1970-rev.yang");
31 private static final YangStatementSourceImpl NOWHERE_ROOT = new YangStatementSourceImpl("/revisions/nowhere-root.yang");
32 private static final YangStatementSourceImpl NOWHERE_REV = new YangStatementSourceImpl("/revisions/nowhere-rev.yang");
36 public void revsEqualTest() throws SourceException, ReactorException {
38 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
39 addSources(reactor, EQUAL_REV, EQUAL_ROOT);
41 EffectiveModelContext result = reactor.build();
42 assertNotNull(result);
46 public void revsUnequalTest() throws SourceException, ReactorException {
48 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
49 addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
53 fail("reactor.process should fail due to unequal revisions in include and submodule");
54 } catch (ReactorException e) {
55 assertTrue(e instanceof SomeModifiersUnresolvedException);
56 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
61 public void revIncludeOnly() throws SourceException, ReactorException {
63 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
64 addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
66 EffectiveModelContext result = reactor.build();
67 assertNotNull(result);
71 public void revInModuleOnly() throws SourceException, ReactorException {
73 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
74 addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
78 fail("reactor.process should fail due to missing revision in included submodule");
79 } catch (ReactorException e) {
80 assertTrue(e instanceof SomeModifiersUnresolvedException);
81 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
87 public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
89 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
90 addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
92 EffectiveModelContext result = reactor.build();
93 assertNotNull(result);
97 public void revNowhereTest() throws SourceException, ReactorException {
99 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
100 addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
102 EffectiveModelContext result = reactor.build();
103 assertNotNull(result);
106 private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
107 for (StatementStreamSource source : sources) {
108 reactor.addSource(source);