662022dbabc22114e2e20f5783daa83043067825
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / YangParserIdentityTest.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
9 package org.opendaylight.yangtools.yang.stmt.retest;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13 import java.io.File;
14 import java.io.FileNotFoundException;
15 import java.io.InputStream;
16 import java.net.URISyntaxException;
17 import java.util.Set;
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;
24 import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
25
26 public class YangParserIdentityTest {
27
28     // base identity name equals identity name
29     @Test(expected = SomeModifiersUnresolvedException.class)
30     public void testParsingIdentityTestModule() throws URISyntaxException,
31             ReactorException, FileNotFoundException {
32         File yang = new File(getClass().getResource("/identity/identitytest.yang").toURI());
33         InputStream stream = new NamedFileInputStream(yang, yang.getPath());
34         try {
35             TestUtils.loadModule(stream);
36         } catch (SomeModifiersUnresolvedException e) {
37             StmtTestUtils.log(e, "      ");
38             throw e;
39         }
40     }
41
42     // same module prefixed base identity name equals identity name
43     @Test(expected = SomeModifiersUnresolvedException.class)
44     public void testParsingPrefixIdentityTestModule() throws URISyntaxException,
45             ReactorException, FileNotFoundException {
46         File yang = new File(getClass().getResource("/identity/prefixidentitytest.yang").toURI());
47         InputStream stream = new NamedFileInputStream(yang, yang.getPath());
48         try {
49             TestUtils.loadModule(stream);
50         } catch (SomeModifiersUnresolvedException e) {
51             StmtTestUtils.log(e, "      ");
52             throw e;
53         }
54     }
55
56     // imported module prefixed base identity name equals identity name, but
57     // prefix differs
58     @Test
59     public void testParsingImportPrefixIdentityTestModule() throws URISyntaxException,
60             ReactorException {
61         Set<Module> modules = TestUtils.loadModules(getClass().getResource("/identity/import").toURI());
62         Module module = TestUtils.findModule(modules, "prefiximportidentitytest");
63         Set<ModuleImport> imports = module.getImports();
64         assertEquals(imports.size(), 1);
65         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
66         assertNotEquals(dummy.getPrefix(), module.getPrefix());
67     }
68 }