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