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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10 import static org.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
13 import static org.junit.jupiter.api.Assertions.assertEquals;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.Revision;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
21 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
23 class IdentityrefStatementTest extends AbstractYangTest {
26 void testIdentityrefWithMultipleBaseIdentities() {
27 final var context = assertEffectiveModel("/rfc7950/identityref-stmt/foo.yang");
29 final Module foo = context.findModule("foo", Revision.of("2017-01-11")).get();
30 final var identities = foo.getIdentities();
31 assertEquals(3, identities.size());
33 final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
35 final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType();
36 final var referencedIdentities = idrefType.getIdentities();
37 assertEquals(3, referencedIdentities.size());
38 assertThat(referencedIdentities, containsInAnyOrder(identities.toArray()));
39 assertEquals("id-a", idrefType.getIdentities().iterator().next().getQName().getLocalName());
43 void testInvalidYang10() {
44 assertInvalidSubstatementException(startsWith("Maximal count of BASE for TYPE is 1, detected 3."),
45 "/rfc7950/identityref-stmt/foo10.yang");