d5b95791f9f550a0e37020a7c81bd287f94548c9
[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.hamcrest.CoreMatchers.startsWith;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13
14 import java.util.Collection;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
18
19 public class YangParserIdentityTest extends AbstractYangTest {
20
21     // base identity name equals identity name
22     @Test
23     public void testParsingIdentityTestModule() {
24         assertInferenceException(startsWith("Unable to resolve identity (urn:test.identitytest?revision="
25                 + "2014-09-17)test and base identity"), "/identity/identitytest.yang");
26     }
27
28     // same module prefixed base identity name equals identity name
29     @Test
30     public void testParsingPrefixIdentityTestModule() {
31         assertInferenceException(startsWith("Unable to resolve identity (urn:test.prefixidentitytest?revision="
32                 + "2014-09-24)prefixtest and base identity"), "/identity/prefixidentitytest.yang");
33     }
34
35     // imported module prefixed base identity name equals identity name, but
36     // prefix differs
37     @Test
38     public void testParsingImportPrefixIdentityTestModule() throws Exception {
39         Module module = StmtTestUtils.parseYangSources("/identity/import").findModules("prefiximportidentitytest")
40             .iterator().next();
41         Collection<? extends ModuleImport> imports = module.getImports();
42         assertEquals(imports.size(), 1);
43         ModuleImport dummy = TestUtils.findImport(imports, "dummy");
44         assertNotEquals(dummy.getPrefix(), module.getPrefix());
45     }
46 }