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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
14 import java.io.FileNotFoundException;
15 import java.io.InputStream;
16 import java.net.URISyntaxException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
23 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
25 public class YangParserIdentityTest {
27 // base identity name equals identity name
28 @Test(expected = SomeModifiersUnresolvedException.class)
29 public void testParsingIdentityTestModule() throws URISyntaxException,
30 ReactorException, FileNotFoundException {
31 File yang = new File(getClass().getResource("/identity/identitytest.yang").toURI());
32 InputStream stream = new NamedFileInputStream(yang, yang.getPath());
34 TestUtils.loadModule(stream);
35 } catch (SomeModifiersUnresolvedException e) {
36 StmtTestUtils.log(e, " ");
41 // same module prefixed base identity name equals identity name
42 @Test(expected = SomeModifiersUnresolvedException.class)
43 public void testParsingPrefixIdentityTestModule() throws URISyntaxException,
44 ReactorException, FileNotFoundException {
45 File yang = new File(getClass().getResource("/identity/prefixidentitytest.yang").toURI());
46 InputStream stream = new NamedFileInputStream(yang, yang.getPath());
48 TestUtils.loadModule(stream);
49 } catch (SomeModifiersUnresolvedException e) {
50 StmtTestUtils.log(e, " ");
55 // imported module prefixed base identity name equals identity name, but
58 public void testParsingImportPrefixIdentityTestModule() throws URISyntaxException,
60 Set<Module> modules = TestUtils.loadModules(getClass().getResource("/identity/import").toURI());
61 Module module = TestUtils.findModule(modules, "prefiximportidentitytest");
62 Set<ModuleImport> imports = module.getImports();
63 assertEquals(imports.size(), 1);
64 ModuleImport dummy = TestUtils.findImport(imports, "dummy");
65 assertNotEquals(dummy.getPrefix(), module.getPrefix());