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
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;
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.Iterables;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
25 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27 public class Bug6883Test {
28 private static final String FOO_NS = "foo";
29 private static final String FOO_REV = "1970-01-01";
32 public void test() throws Exception {
33 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6883");
34 assertNotNull(schemaContext);
36 final AnyDataSchemaNode topAnyData = assertAnyData(schemaContext, ImmutableList.of("top"));
37 assertEquals(Status.DEPRECATED, topAnyData.getStatus());
38 assertEquals("top anydata", topAnyData.getDescription());
40 assertAnyData(schemaContext, ImmutableList.of("root", "root-anydata"));
41 assertAnyData(schemaContext, ImmutableList.of("root", "aug-anydata"));
42 assertAnyData(schemaContext, ImmutableList.of("root", "grp-anydata"));
43 assertAnyData(schemaContext, ImmutableList.of("my-list", "list-anydata"));
44 assertAnyData(schemaContext, ImmutableList.of("sub-data"));
46 assertAnyData(schemaContext, ImmutableList.of("my-rpc", "input", "input-anydata"));
47 assertAnyData(schemaContext, ImmutableList.of("my-rpc", "output", "output-anydata"));
48 assertAnyData(schemaContext, ImmutableList.of("my-notification", "notification-anydata"));
50 assertAnyData(schemaContext, ImmutableList.of("my-choice", "one", "case-anydata"));
51 assertAnyData(schemaContext, ImmutableList.of("my-choice", "case-shorthand-anydata", "case-shorthand-anydata"));
54 private static AnyDataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) {
55 final Iterable<QName> qNames = Iterables.transform(localNamesPath,
56 localName -> QName.create(FOO_NS, FOO_REV, localName));
57 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
58 SchemaPath.create(qNames, true));
59 assertTrue(findDataSchemaNode instanceof AnyDataSchemaNode);
60 return (AnyDataSchemaNode) findDataSchemaNode;