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