YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / 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.IOException;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
19 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
22
23 public class YangParserIdentityTest {
24
25     // base identity name equals identity name
26     @Test(expected = SomeModifiersUnresolvedException.class)
27     public void testParsingIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
28         try {
29             TestUtils.loadModuleResources(getClass(), "/identity/identitytest.yang");
30         } catch (SomeModifiersUnresolvedException e) {
31             StmtTestUtils.log(e, "      ");
32             throw e;
33         }
34     }
35
36     // same module prefixed base identity name equals identity name
37     @Test(expected = SomeModifiersUnresolvedException.class)
38     public void testParsingPrefixIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException  {
39         try {
40             TestUtils.loadModuleResources(getClass(), "/identity/prefixidentitytest.yang");
41         } catch (SomeModifiersUnresolvedException e) {
42             StmtTestUtils.log(e, "      ");
43             throw e;
44         }
45     }
46
47     // imported module prefixed base identity name equals identity name, but
48     // prefix differs
49     @Test
50     public void testParsingImportPrefixIdentityTestModule() throws Exception {
51         Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()),
52             "prefiximportidentitytest").get();
53         Set<ModuleImport> imports = module.getImports();
54         assertEquals(imports.size(), 1);
55         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
56         assertNotEquals(dummy.getPrefix(), module.getPrefix());
57     }
58 }