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