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 java.util.logging.Logger;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors;
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;
28 public class IncludeResolutionTest {
30 private static final Logger LOG = Logger.getLogger(IncludeResolutionTest.class.getName());
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");
43 private static final StatementStreamSource MISSING_PARENT_MODULE = sourceForResource(
44 "/semantic-statement-parser/include-arg-parsing/missing-parent.yang");
47 public void includeTest() throws SourceException, ReactorException {
48 EffectiveModelContext result = DefaultReactors.defaultReactor().newBuild()
49 .addSources(ROOT, SUBMODULE1, SUBMODULE2)
51 assertNotNull(result);
55 public void missingIncludedSourceTest() throws SourceException {
56 BuildAction reactor = DefaultReactors.defaultReactor().newBuild().addSource(ERROR_MODULE);
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());
69 public void missingIncludedSourceTest2() throws SourceException {
70 BuildAction reactor = DefaultReactors.defaultReactor().newBuild().addSource(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 = DefaultReactors.defaultReactor().newBuild().addSource(MISSING_PARENT_MODULE);
87 fail("reactor.process should fail due to missing belongsTo source");
88 } catch (ReactorException e) {
89 LOG.info(e.getMessage());