Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / yin / YinFileStmtTest.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.yin;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.net.URISyntaxException;
14 import java.util.Set;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.Module;
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.spi.source.StatementStreamSource;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
26 import org.opendaylight.yangtools.yang.stmt.retest.TestUtils;
27
28 public class YinFileStmtTest {
29
30     private static final YinStatementSourceImpl YIN_FILE = new YinStatementSourceImpl
31             ("/semantic-statement-parser/yin/test.xml", false);
32     private static final YinStatementSourceImpl EXT_FILE = new YinStatementSourceImpl
33             ("/semantic-statement-parser/yin/extension.xml", false);
34     private static final YinStatementSourceImpl EXT_USE_FILE = new YinStatementSourceImpl
35             ("/semantic-statement-parser/yin/extension-use.xml", false);
36     private static final YinStatementSourceImpl INVALID_YIN_FILE = new YinStatementSourceImpl
37             ("/semantic-statement-parser/yin/incorrect-foo.xml", false);
38     private static final YinStatementSourceImpl INVALID_YIN_FILE_2 = new YinStatementSourceImpl
39             ("/semantic-statement-parser/yin/incorrect-bar.xml", false);
40
41     private Set<Module> modules;
42
43     @Before
44     public void init() throws URISyntaxException, ReactorException {
45         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
46     }
47
48     @Test
49     public void readAndParseYinFileTestModel() throws SourceException, ReactorException {
50         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
51         addSources(reactor, YIN_FILE, EXT_FILE, EXT_USE_FILE);
52         EffectiveSchemaContext result = reactor.buildEffective();
53         assertNotNull(result);
54     }
55
56     // parsing yin file whose import statement references a module which does not exist
57     @Test(expected = SomeModifiersUnresolvedException.class)
58     public void readAndParseInvalidYinFileTest() throws ReactorException {
59         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
60         addSources(reactor, INVALID_YIN_FILE);
61         EffectiveSchemaContext result = reactor.buildEffective();
62         assertNotNull(result);
63     }
64
65     // parsing yin file with duplicate key name in a list statement
66     @Test(expected = IllegalArgumentException.class)
67     public void readAndParseInvalidYinFileTest2() throws ReactorException {
68         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
69         addSources(reactor, INVALID_YIN_FILE_2);
70         EffectiveSchemaContext result = reactor.buildEffective();
71         assertNotNull(result);
72     }
73
74     @Test
75     public void testModulesSize() {
76         assertEquals(modules.size(), 9);
77     }
78
79     private static void addSources(final CrossSourceStatementReactor.BuildAction reactor,  final
80     StatementStreamSource... sources) {
81         for (StatementStreamSource source : sources) {
82             reactor.addSource(source);
83         }
84     }
85
86 }