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