2 * Copyright (c) 2015 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.test;
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;
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;
25 public class ImportResolutionBasicTest {
27 private static final ImportBasicTestStatementSource ROOT_WITHOUT_IMPORT = new ImportBasicTestStatementSource("nature");
28 private static final ImportBasicTestStatementSource IMPORT_ROOT = new ImportBasicTestStatementSource("mammal","nature");
29 private static final ImportBasicTestStatementSource IMPORT_DERIVED = new ImportBasicTestStatementSource("human", "mammal");
30 private static final ImportBasicTestStatementSource IMPORT_SELF = new ImportBasicTestStatementSource("egocentric", "egocentric");
31 private static final ImportBasicTestStatementSource CICLE_YIN = new ImportBasicTestStatementSource("cycle-yin", "cycle-yang");
32 private static final ImportBasicTestStatementSource CICLE_YANG = new ImportBasicTestStatementSource("cycle-yang", "cycle-yin");
36 public void inImportOrderTest() throws SourceException, ReactorException {
37 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
38 addSources(reactor,ROOT_WITHOUT_IMPORT,IMPORT_ROOT,IMPORT_DERIVED);
39 EffectiveModelContext result = reactor.build();
40 assertNotNull(result);
44 public void inInverseOfImportOrderTest() throws SourceException, ReactorException {
45 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46 addSources(reactor,IMPORT_DERIVED,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
47 EffectiveModelContext result = reactor.build();
48 assertNotNull(result);
52 public void missingImportedSourceTest() throws SourceException {
53 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
54 addSources(reactor,IMPORT_DERIVED,ROOT_WITHOUT_IMPORT);
57 fail("reactor.process should fail doe to misssing imported source");
58 } catch (ReactorException e) {
59 assertTrue(e instanceof SomeModifiersUnresolvedException);
60 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
66 public void circularImportsTest() throws SourceException {
67 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
68 addSources(reactor,CICLE_YIN,CICLE_YANG);
71 fail("reactor.process should fail doe to circular import");
72 } catch (ReactorException e) {
73 assertTrue(e instanceof SomeModifiersUnresolvedException);
74 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
79 public void selfImportTest() throws SourceException {
80 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
81 addSources(reactor,IMPORT_SELF,IMPORT_ROOT,ROOT_WITHOUT_IMPORT);
84 fail("reactor.process should fail doe to self import");
85 } catch (ReactorException e) {
86 assertTrue(e instanceof SomeModifiersUnresolvedException);
87 assertEquals(ModelProcessingPhase.SOURCE_LINKAGE,e.getPhase());
92 private void addSources(BuildAction reactor, ImportBasicTestStatementSource... sources) {
93 for(ImportBasicTestStatementSource source : sources) {
94 reactor.addSource(source);