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