2 * Copyright (c) 2016 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.yin;
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;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.text.ParseException;
19 import java.util.Iterator;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.stmt.TestUtils;
28 import org.xml.sax.SAXException;
30 public class YinFileImportStmtTest {
32 private SchemaContext context;
35 public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
36 context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
37 assertEquals(9, context.getModules().size());
42 public void testImport() throws ParseException {
43 Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get();
44 assertNotNull(testModule);
46 Set<ModuleImport> imports = testModule.getImports();
47 assertEquals(2, imports.size());
49 Iterator<ModuleImport> importsIterator = imports.iterator();
50 ModuleImport moduleImport = importsIterator.next();
52 assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types")));
53 assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet")));
55 moduleImport = importsIterator.next();
56 assertThat(moduleImport.getModuleName(), anyOf(is("ietf-yang-types"), is("ietf-inet-types")));
57 assertThat(moduleImport.getPrefix(), anyOf(is("yang"), is("inet")));