1 package org.opendaylight.yangtools.yang.stmt.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
8 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
9 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
10 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
11 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
12 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
13 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
14 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
15 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
16 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
18 public class IncludeRevisionsTest {
20 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",
24 private static final YangStatementSourceImpl UNEQUAL_ROOT = new YangStatementSourceImpl(
25 "/revisions/unequal-root.yang", false);
26 private static final YangStatementSourceImpl UNEQUAL_REV = new YangStatementSourceImpl(
27 "/revisions/unequal-rev.yang", false);
28 private static final YangStatementSourceImpl SUBMOD_ONLY_ROOT = new YangStatementSourceImpl(
29 "/revisions/submod-only-root.yang", false);
30 private static final YangStatementSourceImpl SUBMOD_ONLY_REV = new YangStatementSourceImpl(
31 "/revisions/submod-only-rev.yang", false);
32 private static final YangStatementSourceImpl MOD_ONLY_ROOT = new YangStatementSourceImpl(
33 "/revisions/mod-only-root.yang", false);
34 private static final YangStatementSourceImpl MOD_ONLY_REV = new YangStatementSourceImpl(
35 "/revisions/mod-only-rev.yang", false);
36 private static final YangStatementSourceImpl MOD_ONLY_1970_ROOT = new YangStatementSourceImpl(
37 "/revisions/mod-1970-root.yang", false);
38 private static final YangStatementSourceImpl MOD_ONLY_1970_REV = new YangStatementSourceImpl(
39 "/revisions/mod-1970-rev.yang", false);
40 private static final YangStatementSourceImpl NOWHERE_ROOT = new YangStatementSourceImpl(
41 "/revisions/nowhere-root.yang", false);
42 private static final YangStatementSourceImpl NOWHERE_REV = new YangStatementSourceImpl(
43 "/revisions/nowhere-rev.yang", false);
46 public void revsEqualTest() throws SourceException, ReactorException {
48 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
49 addSources(reactor, EQUAL_REV, EQUAL_ROOT);
51 EffectiveModelContext result = reactor.build();
52 assertNotNull(result);
56 public void revsUnequalTest() throws SourceException, ReactorException {
58 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
59 addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
63 fail("reactor.process should fail due to unequal revisions in include and submodule");
64 } catch (ReactorException e) {
65 assertTrue(e instanceof SomeModifiersUnresolvedException);
66 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
71 public void revIncludeOnly() throws SourceException, ReactorException {
73 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
74 addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
76 EffectiveModelContext result = reactor.build();
77 assertNotNull(result);
81 public void revInModuleOnly() throws SourceException, ReactorException {
83 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
84 addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
88 fail("reactor.process should fail due to missing revision in included submodule");
89 } catch (ReactorException e) {
90 assertTrue(e instanceof SomeModifiersUnresolvedException);
91 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
96 public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
98 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
99 addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
101 EffectiveModelContext result = reactor.build();
102 assertNotNull(result);
106 public void revNowhereTest() throws SourceException, ReactorException {
108 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
109 addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
111 EffectiveModelContext result = reactor.build();
112 assertNotNull(result);
115 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
116 for (StatementStreamSource source : sources) {
117 reactor.addSource(source);