2 * Copyright (c) 2017 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
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;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 public class IdentityrefStatementTest {
30 public void testIdentityrefWithMultipleBaseIdentities() throws Exception {
31 final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang");
32 assertNotNull(schemaContext);
34 final Module foo = schemaContext.findModule("foo", QName.parseRevision("2017-01-11")).get();
35 final Set<IdentitySchemaNode> identities = foo.getIdentities();
36 assertEquals(3, identities.size());
38 final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
40 assertNotNull(idrefLeaf);
42 final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType();
43 final Set<IdentitySchemaNode> referencedIdentities = idrefType.getIdentities();
44 assertEquals(3, referencedIdentities.size());
45 assertEquals(identities, referencedIdentities);
46 assertEquals("id-a", idrefType.getIdentity().getQName().getLocalName());
50 public void testInvalidYang10() throws Exception {
52 StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo10.yang");
53 fail("Test should fail due to invalid Yang 1.0");
54 } catch (final ReactorException e) {
55 assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for TYPE is 1, detected 3."));