Refactor yang-model-api child traversal return types
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5942Test.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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.Matchers.instanceOf;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThat;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.Collection;
18 import java.util.Optional;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
24 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath.WithExpression;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.Status;
27 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.UsesNode;
29
30 public class Bug5942Test {
31     @Test
32     public void test() throws Exception {
33         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5942");
34         assertNotNull(schemaContext);
35
36         final DataSchemaNode root = schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"));
37         assertTrue(root instanceof ContainerSchemaNode);
38
39         final Collection<? extends UsesNode> uses = ((ContainerSchemaNode) root).getUses();
40         assertEquals(1, uses.size());
41         final UsesNode usesNode = uses.iterator().next();
42
43         assertEquals(Optional.of("uses description"), usesNode.getDescription());
44         assertEquals(Optional.of("uses reference"), usesNode.getReference());
45         assertEquals(Status.DEPRECATED, usesNode.getStatus());
46
47         final RevisionAwareXPath when = usesNode.getWhenCondition().get();
48         assertFalse(when.isAbsolute());
49         assertThat(when, instanceOf(WithExpression.class));
50         assertEquals("0!=1", when.getOriginalString());
51
52         final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = usesNode.getUnknownSchemaNodes();
53         assertEquals(1, unknownSchemaNodes.size());
54         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
55         assertEquals("argument", unknownSchemaNode.getNodeParameter());
56         assertEquals(QName.create("foo", "2016-06-02", "e"), unknownSchemaNode.getExtensionDefinition().getQName());
57     }
58 }