1 package org.opendaylight.yangtools.yang.parser.impl;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotEquals;
7 import java.io.FileInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.net.URISyntaxException;
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;
18 public class YangParserIdentityTest {
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);
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);
40 // imported module prefixed base identity name equals identity name, but
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());