2 * Copyright (c) 2016 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;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
26 public class IncludeRevisionsTest {
28 private static final YangStatementSourceImpl EQUAL_ROOT = new YangStatementSourceImpl("/revisions/equal-root.yang",
30 private static final YangStatementSourceImpl EQUAL_REV = new YangStatementSourceImpl("/revisions/equal-rev.yang",
32 private static final YangStatementSourceImpl UNEQUAL_ROOT = new YangStatementSourceImpl(
33 "/revisions/unequal-root.yang", false);
34 private static final YangStatementSourceImpl UNEQUAL_REV = new YangStatementSourceImpl(
35 "/revisions/unequal-rev.yang", false);
36 private static final YangStatementSourceImpl SUBMOD_ONLY_ROOT = new YangStatementSourceImpl(
37 "/revisions/submod-only-root.yang", false);
38 private static final YangStatementSourceImpl SUBMOD_ONLY_REV = new YangStatementSourceImpl(
39 "/revisions/submod-only-rev.yang", false);
40 private static final YangStatementSourceImpl MOD_ONLY_ROOT = new YangStatementSourceImpl(
41 "/revisions/mod-only-root.yang", false);
42 private static final YangStatementSourceImpl MOD_ONLY_REV = new YangStatementSourceImpl(
43 "/revisions/mod-only-rev.yang", false);
44 private static final YangStatementSourceImpl MOD_ONLY_1970_ROOT = new YangStatementSourceImpl(
45 "/revisions/mod-1970-root.yang", false);
46 private static final YangStatementSourceImpl MOD_ONLY_1970_REV = new YangStatementSourceImpl(
47 "/revisions/mod-1970-rev.yang", false);
48 private static final YangStatementSourceImpl NOWHERE_ROOT = new YangStatementSourceImpl(
49 "/revisions/nowhere-root.yang", false);
50 private static final YangStatementSourceImpl NOWHERE_REV = new YangStatementSourceImpl(
51 "/revisions/nowhere-rev.yang", false);
54 public void revsEqualTest() throws SourceException, ReactorException {
56 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57 addSources(reactor, EQUAL_REV, EQUAL_ROOT);
59 EffectiveModelContext result = reactor.build();
60 assertNotNull(result);
64 public void revsUnequalTest() throws SourceException, ReactorException {
66 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
67 addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
71 fail("reactor.process should fail due to unequal revisions in include and submodule");
72 } catch (ReactorException e) {
73 assertTrue(e instanceof SomeModifiersUnresolvedException);
74 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
79 public void revIncludeOnly() throws SourceException, ReactorException {
81 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
82 addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
84 EffectiveModelContext result = reactor.build();
85 assertNotNull(result);
89 public void revInModuleOnly() throws SourceException, ReactorException {
91 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
92 addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
96 fail("reactor.process should fail due to missing revision in included submodule");
97 } catch (ReactorException e) {
98 assertTrue(e instanceof SomeModifiersUnresolvedException);
99 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
104 public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
106 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
107 addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
109 EffectiveModelContext result = reactor.build();
110 assertNotNull(result);
114 public void revNowhereTest() throws SourceException, ReactorException {
116 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
117 addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
119 EffectiveModelContext result = reactor.build();
120 assertNotNull(result);
123 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
124 for (StatementStreamSource source : sources) {
125 reactor.addSource(source);