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 static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
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.EffectiveModelContext;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class IncludeResolutionTest {
31 private static final Logger LOG = LoggerFactory.getLogger(IncludeResolutionTest.class);
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");
44 private static final StatementStreamSource MISSING_PARENT_MODULE = sourceForResource(
45 "/semantic-statement-parser/include-arg-parsing/missing-parent.yang");
48 public void includeTest() throws SourceException, ReactorException {
49 EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
50 .addSources(ROOT, SUBMODULE1, SUBMODULE2)
52 assertNotNull(result);
56 public void missingIncludedSourceTest() throws SourceException {
57 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_MODULE);
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());
70 public void missingIncludedSourceTest2() throws SourceException {
71 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(ERROR_SUBMODULE);
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());
84 public void missingIncludedSourceTest3() throws SourceException, ReactorException {
85 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(MISSING_PARENT_MODULE);
88 fail("reactor.process should fail due to missing belongsTo source");
89 } catch (ReactorException e) {
90 LOG.info(e.getMessage());