50eba7c013744c147a9057bf3c21529589f5a510
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileImportStmtTest.java
1 /*
2  * Copyright (c) 2016 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.yin;
9
10 import static org.hamcrest.CoreMatchers.anyOf;
11 import static org.hamcrest.core.Is.is;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThat;
15
16 import java.net.URISyntaxException;
17 import java.text.ParseException;
18 import java.util.Iterator;
19 import java.util.Set;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.stmt.TestUtils;
26
27 public class YinFileImportStmtTest {
28
29     private Set<Module> modules;
30
31     @Before
32     public void init() throws URISyntaxException, ReactorException {
33         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
34         assertEquals(9, modules.size());
35
36     }
37
38     @Test
39     public void testImport() throws ParseException {
40         Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring");
41         assertNotNull(testModule);
42
43         Set<ModuleImport> imports = testModule.getImports();
44         assertEquals(2, imports.size());
45
46         Iterator<ModuleImport> importsIterator = imports.iterator();
47         ModuleImport moduleImport = importsIterator.next();
48
49         assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types")));
50         assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet")));
51
52         moduleImport = importsIterator.next();
53         assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types")));
54         assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet")));
55     }
56 }