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