Yet another round of Sonar issue fixes
[yangtools.git] / parser / 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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertThrows;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20
21 class IncludeRevisionsTest {
22     private static final StatementStreamSource EQUAL_ROOT = sourceForResource("/revisions/equal-root.yang");
23     private static final StatementStreamSource EQUAL_REV = sourceForResource("/revisions/equal-rev.yang");
24     private static final StatementStreamSource UNEQUAL_ROOT = sourceForResource("/revisions/unequal-root.yang");
25     private static final StatementStreamSource UNEQUAL_REV = sourceForResource("/revisions/unequal-rev.yang");
26     private static final StatementStreamSource SUBMOD_ONLY_ROOT = sourceForResource("/revisions/submod-only-root.yang");
27     private static final StatementStreamSource SUBMOD_ONLY_REV = sourceForResource("/revisions/submod-only-rev.yang");
28     private static final StatementStreamSource MOD_ONLY_ROOT = sourceForResource("/revisions/mod-only-root.yang");
29     private static final StatementStreamSource MOD_ONLY_REV = sourceForResource("/revisions/mod-only-rev.yang");
30     private static final StatementStreamSource NOWHERE_ROOT = sourceForResource("/revisions/nowhere-root.yang");
31     private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
32
33     @Test
34     void revsEqualTest() throws Exception {
35         var result = RFC7950Reactors.defaultReactor().newBuild()
36             .addSources(EQUAL_REV, EQUAL_ROOT)
37             .build();
38         assertNotNull(result);
39     }
40
41     @Test
42     void revsUnequalTest() {
43         var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(UNEQUAL_REV, UNEQUAL_ROOT);
44         var ex = assertThrows(SomeModifiersUnresolvedException.class, reactor::build);
45         assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
46     }
47
48     @Test
49     void revIncludeOnly() throws Exception {
50         var result = RFC7950Reactors.defaultReactor().newBuild()
51             .addSources(SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT)
52             .build();
53         assertNotNull(result);
54     }
55
56     @Test
57     void revInModuleOnly() {
58         var reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(MOD_ONLY_REV, MOD_ONLY_ROOT);
59         var ex = assertThrows(SomeModifiersUnresolvedException.class, reactor::build);
60         assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, ex.getPhase());
61     }
62
63     @Test
64     void revNowhereTest() throws Exception {
65         var result = RFC7950Reactors.defaultReactor().newBuild()
66             .addSources(NOWHERE_REV, NOWHERE_ROOT)
67             .build();
68         assertNotNull(result);
69     }
70 }