2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.stmt;
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 java.util.logging.Logger;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
26 public class IncludeResolutionTest {
28 private static final Logger log = Logger.getLogger(IncludeResolutionTest.class.getName());
30 private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
31 "/semantic-statement-parser/include-arg-parsing/root-module.yang", false);
32 private static final YangStatementSourceImpl SUBMODULE1 = new YangStatementSourceImpl(
33 "/semantic-statement-parser/include-arg-parsing/submodule-1.yang", false);
34 private static final YangStatementSourceImpl SUBMODULE2 = new YangStatementSourceImpl(
35 "/semantic-statement-parser/include-arg-parsing/submodule-2.yang", false);
36 private static final YangStatementSourceImpl ERROR_MODULE = new YangStatementSourceImpl(
37 "/semantic-statement-parser/include-arg-parsing/error-module.yang", false);
38 private static final YangStatementSourceImpl ERROR_SUBMODULE = new YangStatementSourceImpl(
39 "/semantic-statement-parser/include-arg-parsing/error-submodule.yang", false);
41 private static final YangStatementSourceImpl MISSING_PARENT_MODULE = new YangStatementSourceImpl(
42 "/semantic-statement-parser/include-arg-parsing/missing-parent.yang", false);
45 public void includeTest() throws SourceException, ReactorException {
46 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
47 addSources(reactor, ROOT, SUBMODULE1, SUBMODULE2);
48 EffectiveModelContext result = reactor.build();
49 assertNotNull(result);
53 public void missingIncludedSourceTest() throws SourceException {
54 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
55 addSources(reactor, ERROR_MODULE);
58 fail("reactor.process should fail due to missing included source");
59 } catch (ReactorException e) {
60 assertTrue(e instanceof SomeModifiersUnresolvedException);
61 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
62 log.info(e.getMessage());
68 public void missingIncludedSourceTest2() throws SourceException {
69 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
70 addSources(reactor, ERROR_SUBMODULE);
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());
83 public void missingIncludedSourceTest3() throws SourceException, ReactorException {
84 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
85 addSources(reactor, MISSING_PARENT_MODULE);
88 fail("reactor.process should fail due to missing belongsTo source");
89 } catch (ReactorException e) {
90 log.info(e.getMessage());
95 private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
96 for (YangStatementSourceImpl source : sources) {
97 reactor.addSource(source);