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 static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
27 public class IncludeRevisionsTest {
29 private static final StatementStreamSource EQUAL_ROOT = sourceForResource("/revisions/equal-root.yang");
30 private static final StatementStreamSource EQUAL_REV = sourceForResource("/revisions/equal-rev.yang");
31 private static final StatementStreamSource UNEQUAL_ROOT = sourceForResource("/revisions/unequal-root.yang");
32 private static final StatementStreamSource UNEQUAL_REV = sourceForResource("/revisions/unequal-rev.yang");
33 private static final StatementStreamSource SUBMOD_ONLY_ROOT = sourceForResource("/revisions/submod-only-root.yang");
34 private static final StatementStreamSource SUBMOD_ONLY_REV = sourceForResource("/revisions/submod-only-rev.yang");
35 private static final StatementStreamSource MOD_ONLY_ROOT = sourceForResource("/revisions/mod-only-root.yang");
36 private static final StatementStreamSource MOD_ONLY_REV = sourceForResource("/revisions/mod-only-rev.yang");
37 private static final StatementStreamSource MOD_ONLY_1970_ROOT = sourceForResource("/revisions/mod-1970-root.yang");
38 private static final StatementStreamSource MOD_ONLY_1970_REV = sourceForResource("/revisions/mod-1970-rev.yang");
39 private static final StatementStreamSource NOWHERE_ROOT = sourceForResource("/revisions/nowhere-root.yang");
40 private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
43 public void revsEqualTest() throws SourceException, ReactorException {
45 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46 addSources(reactor, EQUAL_REV, EQUAL_ROOT);
48 EffectiveModelContext result = reactor.build();
49 assertNotNull(result);
53 public void revsUnequalTest() throws SourceException, ReactorException {
55 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
56 addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
60 fail("reactor.process should fail due to unequal revisions in include and submodule");
61 } catch (ReactorException e) {
62 assertTrue(e instanceof SomeModifiersUnresolvedException);
63 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
68 public void revIncludeOnly() throws SourceException, ReactorException {
70 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
71 addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
73 EffectiveModelContext result = reactor.build();
74 assertNotNull(result);
78 public void revInModuleOnly() throws SourceException, ReactorException {
80 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
81 addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
85 fail("reactor.process should fail due to missing revision in included submodule");
86 } catch (ReactorException e) {
87 assertTrue(e instanceof SomeModifiersUnresolvedException);
88 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
93 public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
95 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
96 addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
98 EffectiveModelContext result = reactor.build();
99 assertNotNull(result);
103 public void revNowhereTest() throws SourceException, ReactorException {
105 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
106 addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
108 EffectiveModelContext result = reactor.build();
109 assertNotNull(result);
112 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
113 for (StatementStreamSource source : sources) {
114 reactor.addSource(source);