694fc7e173d8721cee689e66e80163db549c29c8
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / IncludeRevisionsTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
15
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
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.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
24
25 public class IncludeRevisionsTest {
26
27     private static final StatementStreamSource EQUAL_ROOT = sourceForResource("/revisions/equal-root.yang");
28     private static final StatementStreamSource EQUAL_REV = sourceForResource("/revisions/equal-rev.yang");
29     private static final StatementStreamSource UNEQUAL_ROOT = sourceForResource("/revisions/unequal-root.yang");
30     private static final StatementStreamSource UNEQUAL_REV = sourceForResource("/revisions/unequal-rev.yang");
31     private static final StatementStreamSource SUBMOD_ONLY_ROOT = sourceForResource("/revisions/submod-only-root.yang");
32     private static final StatementStreamSource SUBMOD_ONLY_REV = sourceForResource("/revisions/submod-only-rev.yang");
33     private static final StatementStreamSource MOD_ONLY_ROOT = sourceForResource("/revisions/mod-only-root.yang");
34     private static final StatementStreamSource MOD_ONLY_REV = sourceForResource("/revisions/mod-only-rev.yang");
35     private static final StatementStreamSource NOWHERE_ROOT = sourceForResource("/revisions/nowhere-root.yang");
36     private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
37
38     @Test
39     public void revsEqualTest() throws ReactorException {
40         ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
41                 .addSources(EQUAL_REV, EQUAL_ROOT)
42                 .build();
43         assertNotNull(result);
44     }
45
46     @Test
47     public void revsUnequalTest() throws ReactorException {
48         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(UNEQUAL_REV, UNEQUAL_ROOT);
49         try {
50             reactor.build();
51             fail("reactor.process should fail due to unequal revisions in include and submodule");
52         } catch (ReactorException e) {
53             assertTrue(e instanceof SomeModifiersUnresolvedException);
54             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
55         }
56     }
57
58     @Test
59     public void revIncludeOnly() throws ReactorException {
60         ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
61                 .addSources(SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT)
62                 .build();
63         assertNotNull(result);
64     }
65
66     @Test
67     public void revInModuleOnly() throws ReactorException {
68         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(MOD_ONLY_REV, MOD_ONLY_ROOT);
69         try {
70             reactor.build();
71             fail("reactor.process should fail due to missing revision in included submodule");
72         } catch (ReactorException e) {
73             assertTrue(e instanceof SomeModifiersUnresolvedException);
74             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
75         }
76     }
77
78     @Test
79     public void revNowhereTest() throws ReactorException {
80         ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
81                 .addSources(NOWHERE_REV, NOWHERE_ROOT)
82                 .build();
83         assertNotNull(result);
84     }
85 }