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.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.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
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 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
49 reactor.addSources(ROOT, SUBMODULE1, SUBMODULE2);
50 EffectiveModelContext result = reactor.build();
51 assertNotNull(result);
55 public void missingIncludedSourceTest() throws SourceException {
56 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57 reactor.addSources(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 = YangInferencePipeline.RFC6020_REACTOR.newBuild();
72 reactor.addSources(ERROR_SUBMODULE);
75 fail("reactor.process should fail due to missing included source");
76 } catch (ReactorException e) {
77 assertTrue(e instanceof SomeModifiersUnresolvedException);
78 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE, e.getPhase());
79 log.info(e.getMessage());
85 public void missingIncludedSourceTest3() throws SourceException, ReactorException {
86 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
87 reactor.addSources(MISSING_PARENT_MODULE);
90 fail("reactor.process should fail due to missing belongsTo source");
91 } catch (ReactorException e) {
92 log.info(e.getMessage());