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;
16 import java.util.Date;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
21 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
29 public class IdentityrefStatementTest {
32 public void testIdentityrefWithMultipleBaseIdentities() throws Exception {
33 final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang");
34 assertNotNull(schemaContext);
36 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-01-11");
38 final Module foo = schemaContext.findModuleByName("foo", revision);
41 final Set<IdentitySchemaNode> identities = foo.getIdentities();
42 assertEquals(3, identities.size());
44 final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
46 assertNotNull(idrefLeaf);
48 final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType();
49 final Set<IdentitySchemaNode> referencedIdentities = idrefType.getIdentities();
50 assertEquals(3, referencedIdentities.size());
51 assertEquals(identities, referencedIdentities);
52 assertEquals("id-a", idrefType.getIdentity().getQName().getLocalName());
56 public void testInvalidYang10() throws Exception {
58 StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo10.yang");
59 fail("Test should fail due to invalid Yang 1.0");
60 } catch (final ReactorException e) {
61 assertTrue(e.getCause().getMessage().startsWith("Maximal count of BASE for TYPE is 1, detected 3."));