f6dde62889e037a3ff9aa8f9a5cbf0d88cc70517
[yangtools.git] / parser / 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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12
13 import java.util.Collection;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
18
19 public class YangParserIdentityTest {
20
21     // base identity name equals identity name
22     @Test(expected = SomeModifiersUnresolvedException.class)
23     public void testParsingIdentityTestModule() throws Exception {
24         try {
25             StmtTestUtils.parseYangSource("/identity/identitytest.yang");
26         } catch (SomeModifiersUnresolvedException e) {
27             StmtTestUtils.log(e, "      ");
28             throw e;
29         }
30     }
31
32     // same module prefixed base identity name equals identity name
33     @Test(expected = SomeModifiersUnresolvedException.class)
34     public void testParsingPrefixIdentityTestModule() throws Exception {
35         try {
36             StmtTestUtils.parseYangSource("/identity/prefixidentitytest.yang");
37         } catch (SomeModifiersUnresolvedException e) {
38             StmtTestUtils.log(e, "      ");
39             throw e;
40         }
41     }
42
43     // imported module prefixed base identity name equals identity name, but
44     // prefix differs
45     @Test
46     public void testParsingImportPrefixIdentityTestModule() throws Exception {
47         Module module = StmtTestUtils.parseYangSources("/identity/import").findModules("prefiximportidentitytest")
48             .iterator().next();
49         Collection<? extends ModuleImport> imports = module.getImports();
50         assertEquals(imports.size(), 1);
51         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
52         assertNotEquals(dummy.getPrefix(), module.getPrefix());
53     }
54 }