Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / YangFileStmtTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt.test;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
14 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
15 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
16 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
17 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
21
22 public class YangFileStmtTest {
23     //basic statements to parse and write
24     private static final YangStatementSourceImpl YANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/test.yang", false);
25     private static final YangStatementSourceImpl IMPORTEDYANGFILE = new YangStatementSourceImpl("/semantic-statement-parser/importedtest.yang", false);
26     private static final YangStatementSourceImpl SIMPLENODES = new YangStatementSourceImpl("/semantic-statement-parser/simple-nodes-semantic.yang", false);
27     private static final YangStatementSourceImpl FOOBAR = new YangStatementSourceImpl("/semantic-statement-parser/foobar.yang", false);
28     //extension statement to parse and write
29     private static final YangStatementSourceImpl EXTFILE = new YangStatementSourceImpl("/semantic-statement-parser/ext-typedef.yang", false);
30     private static final YangStatementSourceImpl EXTUSE = new YangStatementSourceImpl("/semantic-statement-parser/ext-use.yang", false);
31
32
33     private static final YangStatementSourceImpl BAR = new YangStatementSourceImpl("/model-new/bar.yang", false);
34     private static final YangStatementSourceImpl BAZ = new YangStatementSourceImpl("/model-new/baz.yang", false);
35     private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl("/model-new/foo.yang", false);
36     private static final YangStatementSourceImpl SUBFOO = new YangStatementSourceImpl("/model-new/subfoo.yang", false);
37
38     private static final YangStatementSourceImpl BAR2 = new YangStatementSourceImpl("/model/bar.yang",false);
39     private static final YangStatementSourceImpl BAZ2 = new YangStatementSourceImpl("/model/baz.yang",false);
40     private static final YangStatementSourceImpl FOO2 = new YangStatementSourceImpl("/model/foo.yang",false);
41     private static final YangStatementSourceImpl SUBFOO2 = new YangStatementSourceImpl("/model/subfoo.yang",false);
42
43     @Test
44     public void readAndParseYangFileTestModel() throws SourceException, ReactorException {
45         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46
47         addSources(reactor, BAZ,FOO,BAR,SUBFOO);
48         EffectiveModelContext result = reactor.build();
49         assertNotNull(result);
50     }
51
52     @Test
53     public void readAndParseYangFileTestModel2() throws SourceException, ReactorException {
54         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
55
56         addSources(reactor, BAZ2,FOO2,BAR2,SUBFOO2);
57         EffectiveModelContext result = reactor.build();
58         assertNotNull(result);
59     }
60
61     @Test
62     public void readAndParseYangFileTest() throws SourceException, ReactorException {
63         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
64         addSources(reactor, YANGFILE, SIMPLENODES, IMPORTEDYANGFILE, FOOBAR);
65         addSources(reactor, EXTFILE, EXTUSE);
66         EffectiveSchemaContext result = reactor.buildEffective();
67         assertNotNull(result);
68     }
69
70     private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
71         for (StatementStreamSource source : sources) {
72             reactor.addSource(source);
73         }
74     }
75 }