Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6883Test.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.Iterables;
17 import java.util.Optional;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AnyDataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
26 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
27
28 public class Bug6883Test {
29     private static final String FOO_NS = "foo";
30
31     @Test
32     public void test() throws Exception {
33         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/rfc7950/bug6883");
34         assertNotNull(schemaContext);
35
36         final AnyDataSchemaNode topAnyData = assertAnyData(schemaContext, ImmutableList.of("top"));
37         assertEquals(Status.DEPRECATED, topAnyData.getStatus());
38         assertEquals(Optional.of("top anydata"), topAnyData.getDescription());
39
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"));
45
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"));
49
50         assertAnyData(schemaContext, ImmutableList.of("my-choice", "one", "case-anydata"));
51         assertAnyData(schemaContext, ImmutableList.of("my-choice", "case-shorthand-anydata", "case-shorthand-anydata"));
52     }
53
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, localName));
57         final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
58                 SchemaPath.create(qNames, true));
59         assertTrue(findDataSchemaNode instanceof AnyDataSchemaNode);
60         return (AnyDataSchemaNode) findDataSchemaNode;
61     }
62 }