4d956a5bdc2eb0fc57ee8b69e675c58ec435c945
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileIdentityStmtTest.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.yin;
9
10 import static org.hamcrest.CoreMatchers.anyOf;
11 import static org.hamcrest.core.Is.is;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertThat;
16
17 import java.net.URISyntaxException;
18 import java.util.Iterator;
19 import java.util.Set;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.stmt.TestUtils;
26
27 public class YinFileIdentityStmtTest {
28
29     private Set<Module> modules;
30
31     @Before
32     public void init() throws URISyntaxException, ReactorException {
33         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
34         assertEquals(9, modules.size());
35     }
36
37     @Test
38     public void testIdentity() throws URISyntaxException {
39         Module testModule = TestUtils.findModule(modules, "config");
40         assertNotNull(testModule);
41
42         Set<IdentitySchemaNode> identities = testModule.getIdentities();
43         assertEquals(2, identities.size());
44
45         Iterator<IdentitySchemaNode> idIterator = identities.iterator();
46         IdentitySchemaNode id = idIterator.next();
47
48         assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type")));
49         assertNull(id.getBaseIdentity());
50
51         id = idIterator.next();
52         assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type")));
53         assertNull(id.getBaseIdentity());
54
55     }
56 }