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
8 package org.opendaylight.yangtools.yang.stmt.test.yin;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import java.net.URISyntaxException;
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;
28 public class YinFileStmtTest {
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);
41 private Set<Module> modules;
44 public void init() throws URISyntaxException, ReactorException {
45 modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
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);
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);
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);
75 public void testModulesSize() {
76 assertEquals(modules.size(), 9);
79 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final
80 StatementStreamSource... sources) {
81 for (StatementStreamSource source : sources) {
82 reactor.addSource(source);