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.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
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.StatementStreamSource;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
27 public class ImportResolutionBasicTest {
29 private static final StatementStreamSource ROOT_WITHOUT_IMPORT = sourceForResource(
30 "/semantic-statement-parser/import-arg-parsing/nature.yang");
31 private static final StatementStreamSource IMPORT_ROOT = sourceForResource(
32 "/semantic-statement-parser/import-arg-parsing/mammal.yang");
33 private static final StatementStreamSource IMPORT_DERIVED = sourceForResource(
34 "/semantic-statement-parser/import-arg-parsing/human.yang");
35 private static final StatementStreamSource IMPORT_SELF = sourceForResource(
36 "/semantic-statement-parser/import-arg-parsing/egocentric.yang");
37 private static final StatementStreamSource CYCLE_YIN = sourceForResource(
38 "/semantic-statement-parser/import-arg-parsing/cycle-yin.yang");
39 private static final StatementStreamSource CYCLE_YANG = sourceForResource(
40 "/semantic-statement-parser/import-arg-parsing/cycle-yang.yang");
41 private static final StatementStreamSource FOO = sourceForResource(
42 "/semantic-statement-parser/bug2649/foo.yang");
43 private static final StatementStreamSource IMPORT = sourceForResource(
44 "/semantic-statement-parser/bug2649/import-module.yang");
48 public void inImportOrderTest() throws ReactorException {
49 EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
50 .addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED)
52 assertNotNull(result);
56 public void inInverseOfImportOrderTest() throws ReactorException {
57 EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
58 .addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT)
60 assertNotNull(result);
64 public void missingImportedSourceTest() {
65 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
66 .addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
69 fail("reactor.process should fail due to missing imported source");
70 } catch (ReactorException e) {
71 assertTrue(e instanceof SomeModifiersUnresolvedException);
72 assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
78 public void circularImportsTest() {
79 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSources(CYCLE_YIN, CYCLE_YANG);
82 fail("reactor.process should fail due to circular import");
83 } catch (ReactorException e) {
84 assertTrue(e instanceof SomeModifiersUnresolvedException);
85 assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
90 public void selfImportTest() {
91 BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
92 .addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
95 fail("reactor.process should fail due to self import");
96 } catch (ReactorException e) {
97 assertTrue(e instanceof SomeModifiersUnresolvedException);
98 assertEquals(ModelProcessingPhase.SOURCE_PRE_LINKAGE, e.getPhase());
103 public void bug2649Test() throws ReactorException {
104 SchemaContext buildEffective = RFC7950Reactors.defaultReactor().newBuild()
105 .addSources(FOO, IMPORT)
107 assertNotNull(buildEffective);