Replace calls of StmtTestUtils.parseYangSource(String)
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / IdentityrefStatementTest.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.hamcrest.CoreMatchers.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
13 import static org.junit.Assert.assertEquals;
14
15 import java.util.Collection;
16 import java.util.Set;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
24 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
25
26 public class IdentityrefStatementTest extends AbstractYangTest {
27
28     @Test
29     public void testIdentityrefWithMultipleBaseIdentities() {
30         final var context = assertEffectiveModel("/rfc7950/identityref-stmt/foo.yang");
31
32         final Module foo = context.findModule("foo", Revision.of("2017-01-11")).get();
33         final Collection<? extends IdentitySchemaNode> identities = foo.getIdentities();
34         assertEquals(3, identities.size());
35
36         final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
37                 "idref-leaf"));
38         final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType();
39         final Set<? extends IdentitySchemaNode> referencedIdentities = idrefType.getIdentities();
40         assertEquals(3, referencedIdentities.size());
41         assertThat(referencedIdentities, containsInAnyOrder(identities.toArray()));
42         assertEquals("id-a", idrefType.getIdentities().iterator().next().getQName().getLocalName());
43     }
44
45     @Test
46     public void testInvalidYang10() {
47         assertInvalidSubstatementException(startsWith("Maximal count of BASE for TYPE is 1, detected 3."),
48                 "/rfc7950/identityref-stmt/foo10.yang");
49     }
50 }