Use local variable type inference
[yangtools.git] / parser / 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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.Optional;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Status;
19 import org.opendaylight.yangtools.yang.model.api.UsesNode;
20 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
21
22 public class Bug5942Test extends AbstractYangTest {
23     @Test
24     public void test() {
25         final var schemaContext = assertEffectiveModelDir("/bugs/bug5942");
26
27         final DataSchemaNode root = schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"));
28         assertTrue(root instanceof ContainerSchemaNode);
29
30         final var uses = ((ContainerSchemaNode) root).getUses();
31         assertEquals(1, uses.size());
32         final UsesNode usesNode = uses.iterator().next();
33
34         assertEquals(Optional.of("uses description"), usesNode.getDescription());
35         assertEquals(Optional.of("uses reference"), usesNode.getReference());
36         assertEquals(Status.DEPRECATED, usesNode.getStatus());
37
38         assertEquals("0!=1", usesNode.getWhenCondition().orElseThrow().toString());
39
40         final UnrecognizedStatement unknownSchemaNode = usesNode.asEffectiveStatement().getDeclared()
41             .findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
42
43         assertEquals("argument", unknownSchemaNode.argument());
44         assertEquals(QName.create("foo", "2016-06-02", "e"),
45             unknownSchemaNode.statementDefinition().getStatementName());
46     }
47 }