Merge "BUG-2022: String Type pattern parsing and resolving fix."
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / YangParserIdentityTest.java
1 package org.opendaylight.yangtools.yang.parser.impl;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
5
6 import java.io.File;
7 import java.io.FileInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.net.URISyntaxException;
11 import java.util.Set;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.model.api.Module;
14 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
15 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
16 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
17
18 public class YangParserIdentityTest {
19
20     // base identity name equals identity name
21     @Test(expected = YangParseException.class)
22     public void testParsingIdentityTestModuleShouldThrowYangParseException()
23             throws IOException, URISyntaxException, YangSyntaxErrorException {
24         File yang = new File(getClass().getResource(
25                 "/identity/identitytest.yang").toURI());
26         InputStream stream = new FileInputStream(yang);
27         TestUtils.loadModule(stream);
28     }
29
30     // same module prefixed base identity name equals identity name
31     @Test(expected = YangParseException.class)
32     public void testParsingPrefixIdentityTestModuleShouldThrowYangParseException()
33             throws URISyntaxException, IOException, YangSyntaxErrorException {
34         File yang = new File(getClass().getResource(
35                 "/identity/prefixidentitytest.yang").toURI());
36         InputStream stream = new FileInputStream(yang);
37         TestUtils.loadModule(stream);
38     }
39
40     // imported module prefixed base identity name equals identity name, but
41     // prefix differs
42     @Test
43     public void testParsingImportPrefixIdentityTestModuleShouldThrowYangParseException()
44             throws URISyntaxException, IOException, YangSyntaxErrorException {
45         Set<Module> modules = TestUtils.loadModules(getClass().getResource(
46                 "/identity/import").toURI());
47         Module module = TestUtils.findModule(modules,
48                 "prefiximportidentitytest");
49         Set<ModuleImport> imports = module.getImports();
50         assertEquals(imports.size(), 1);
51         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
52         assertNotEquals(dummy.getPrefix(), module.getPrefix());
53     }
54 }