2 * Copyright (c) 2016 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.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertFalse;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
18 import com.google.common.collect.ImmutableSet;
19 import java.util.Collection;
20 import java.util.HashSet;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
26 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.Module;
29 import org.opendaylight.yangtools.yang.stmt.AbstractYangTest;
30 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
32 public class Bug6869Test extends AbstractYangTest {
33 private static final QName ROOT = QName.create("foo", "root");
34 private static final QName GRP_LEAF = QName.create("foo", "grp-leaf");
37 public void identityNoFeaureTest() throws Exception {
38 final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
40 assertNotNull(schemaContext);
42 final Collection<? extends IdentitySchemaNode> identities = getIdentities(schemaContext);
43 assertEquals(0, identities.size());
45 final DataSchemaNode findNode = schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElse(null);
46 assertThat(findNode, instanceOf(LeafSchemaNode.class));
47 final LeafSchemaNode grpLeaf = (LeafSchemaNode) findNode;
48 assertFalse(grpLeaf.isMandatory());
52 public void identityAllFeauresTest() throws Exception {
53 final EffectiveModelContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6869/foo.yang",
54 createFeaturesSet("identity-feature", "mandatory-leaf", "tls", "ssh", "two", "three"));
55 assertNotNull(schemaContext);
57 final Collection<? extends IdentitySchemaNode> identities = getIdentities(schemaContext);
58 assertEquals(1, identities.size());
60 final DataSchemaNode findNode = schemaContext.findDataTreeChild(ROOT, GRP_LEAF).orElse(null);
61 assertThat(findNode, instanceOf(LeafSchemaNode.class));
62 final LeafSchemaNode grpLeaf = (LeafSchemaNode) findNode;
63 assertTrue(grpLeaf.isMandatory());
66 private static Collection<? extends IdentitySchemaNode> getIdentities(final EffectiveModelContext schemaContext) {
67 final Collection<? extends Module> modules = schemaContext.getModules();
68 assertEquals(1, modules.size());
69 final Module module = modules.iterator().next();
70 return module.getIdentities();
73 private static Set<QName> createFeaturesSet(final String... featureNames) {
74 final Set<QName> supportedFeatures = new HashSet<>();
75 for (final String featureName : featureNames) {
76 supportedFeatures.add(QName.create("foo", featureName));
79 return ImmutableSet.copyOf(supportedFeatures);
83 public void invalidYang10Test() {
84 assertInvalidSubstatementException(startsWith("IF_FEATURE is not valid for IDENTITY"),
85 "/rfc7950/bug6869/invalid10.yang");