2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt.yin;
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.assertThat;
15 import static org.junit.Assert.assertTrue;
17 import java.io.IOException;
18 import java.net.URISyntaxException;
19 import java.util.Iterator;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.stmt.TestUtils;
28 import org.xml.sax.SAXException;
30 public class YinFileIdentityStmtTest {
32 private SchemaContext context;
35 public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
36 context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
37 assertEquals(9, context.getModules().size());
41 public void testIdentity() throws URISyntaxException {
42 Module testModule = TestUtils.findModule(context, "config").get();
43 assertNotNull(testModule);
45 Set<IdentitySchemaNode> identities = testModule.getIdentities();
46 assertEquals(2, identities.size());
48 Iterator<IdentitySchemaNode> idIterator = identities.iterator();
49 IdentitySchemaNode id = idIterator.next();
51 assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type")));
52 assertTrue(id.getBaseIdentities().isEmpty());
54 id = idIterator.next();
55 assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type")));
56 assertTrue(id.getBaseIdentities().isEmpty());