8bce589e228d3e45822831f1ff51a5333be9eeb9
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / IdentityStatementTest.java
1 /*
2  * Copyright (c) 2017 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.parser.stmt.rfc7950;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import java.util.Collection;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
23
24 public class IdentityStatementTest {
25
26     @Test
27     public void testMultipleBaseIdentities() throws Exception {
28         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo.yang");
29         assertNotNull(schemaContext);
30
31         final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-21")).get();
32         for (final IdentitySchemaNode identity : foo.getIdentities()) {
33             if ("derived-id".equals(identity.getQName().getLocalName())) {
34                 final Collection<? extends IdentitySchemaNode> baseIdentities = identity.getBaseIdentities();
35                 assertEquals(3, baseIdentities.size());
36             }
37         }
38     }
39
40     @Test
41     public void testInvalidYang10() throws Exception {
42         try {
43             StmtTestUtils.parseYangSource("/rfc7950/identity-stmt/foo10.yang");
44             fail("Test should fail due to invalid Yang 1.0");
45         } catch (final ReactorException e) {
46             assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for IDENTITY is 1, detected 3."));
47         }
48     }
49 }