Remove unneeded throws
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / IncludeResolutionTest.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
9 package org.opendaylight.yangtools.yang.stmt;
10
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;
16
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.ReactorDeclaredModel;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 public class IncludeResolutionTest {
30
31     private static final Logger LOG = LoggerFactory.getLogger(IncludeResolutionTest.class);
32
33     private static final StatementStreamSource ROOT = sourceForResource(
34             "/semantic-statement-parser/include-arg-parsing/root-module.yang");
35     private static final StatementStreamSource SUBMODULE1 = sourceForResource(
36             "/semantic-statement-parser/include-arg-parsing/submodule-1.yang");
37     private static final StatementStreamSource SUBMODULE2 = sourceForResource(
38             "/semantic-statement-parser/include-arg-parsing/submodule-2.yang");
39     private static final StatementStreamSource ERROR_MODULE = sourceForResource(
40             "/semantic-statement-parser/include-arg-parsing/error-module.yang");
41     private static final StatementStreamSource ERROR_SUBMODULE = sourceForResource(
42             "/semantic-statement-parser/include-arg-parsing/error-submodule.yang");
43
44     private static final StatementStreamSource MISSING_PARENT_MODULE = sourceForResource(
45             "/semantic-statement-parser/include-arg-parsing/missing-parent.yang");
46
47     @Test
48     public void includeTest() throws SourceException, ReactorException {
49         ReactorDeclaredModel result = RFC7950Reactors.defaultReactor().newBuild()
50                 .addSources(ROOT, SUBMODULE1, SUBMODULE2)
51                 .build();
52         assertNotNull(result);
53     }
54
55     @Test
56     public void missingIncludedSourceTest() throws SourceException {
57         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_MODULE);
58         try {
59             reactor.build();
60             fail("reactor.process should fail due to missing included source");
61         } catch (ReactorException e) {
62             assertTrue(e instanceof SomeModifiersUnresolvedException);
63             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
64             LOG.info(e.getMessage());
65         }
66
67     }
68
69     @Test
70     public void missingIncludedSourceTest2() throws SourceException {
71         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_SUBMODULE);
72         try {
73             reactor.build();
74             fail("reactor.process should fail due to missing included source");
75         } catch (ReactorException e) {
76             assertTrue(e instanceof SomeModifiersUnresolvedException);
77             assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
78             LOG.info(e.getMessage());
79         }
80
81     }
82
83     @Test
84     public void missingIncludedSourceTest3() throws SourceException, ReactorException {
85         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(MISSING_PARENT_MODULE);
86         try {
87             reactor.build();
88             fail("reactor.process should fail due to missing belongsTo source");
89         } catch (ReactorException e) {
90             LOG.info(e.getMessage());
91         }
92
93     }
94 }