1 package org.opendaylight.yangtools.yang.stmt.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
7 import java.util.logging.Logger;
9 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
10 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
11 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
12 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
13 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
14 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
15 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
16 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
18 public class IncludeResolutionTest {
20 private static final Logger log = Logger.getLogger(IncludeResolutionTest.class.getName());
22 private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
23 "/semantic-statement-parser/include-arg-parsing/root-module.yang", false);
24 private static final YangStatementSourceImpl SUBMODULE1 = new YangStatementSourceImpl(
25 "/semantic-statement-parser/include-arg-parsing/submodule-1.yang", false);
26 private static final YangStatementSourceImpl SUBMODULE2 = new YangStatementSourceImpl(
27 "/semantic-statement-parser/include-arg-parsing/submodule-2.yang", false);
28 private static final YangStatementSourceImpl ERROR_MODULE = new YangStatementSourceImpl(
29 "/semantic-statement-parser/include-arg-parsing/error-module.yang", false);
30 private static final YangStatementSourceImpl ERROR_SUBMODULE = new YangStatementSourceImpl(
31 "/semantic-statement-parser/include-arg-parsing/error-submodule.yang", false);
33 private static final YangStatementSourceImpl MISSING_PARENT_MODULE = new YangStatementSourceImpl(
34 "/semantic-statement-parser/include-arg-parsing/missing-parent.yang", false);
37 public void includeTest() throws SourceException, ReactorException {
38 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
39 addSources(reactor, ROOT, SUBMODULE1, SUBMODULE2);
40 EffectiveModelContext result = reactor.build();
41 assertNotNull(result);
45 public void missingIncludedSourceTest() throws SourceException {
46 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
47 addSources(reactor, ERROR_MODULE);
50 fail("reactor.process should fail due to missing included source");
51 } catch (ReactorException e) {
52 assertTrue(e instanceof SomeModifiersUnresolvedException);
53 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
54 log.info(e.getMessage());
60 public void missingIncludedSourceTest2() throws SourceException {
61 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
62 addSources(reactor, ERROR_SUBMODULE);
65 fail("reactor.process should fail due to missing included source");
66 } catch (ReactorException e) {
67 assertTrue(e instanceof SomeModifiersUnresolvedException);
68 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
69 log.info(e.getMessage());
75 public void missingIncludedSourceTest3() throws SourceException, ReactorException {
76 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
77 addSources(reactor, MISSING_PARENT_MODULE);
80 fail("reactor.process should fail due to missing belongsTo source");
81 } catch (ReactorException e) {
82 log.info(e.getMessage());
87 private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
88 for (YangStatementSourceImpl source : sources) {
89 reactor.addSource(source);