Merge branch 'master' of ../controller
[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.List;
18 import java.util.Optional;
19 import java.util.Set;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
25 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath.WithExpression;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.api.Status;
28 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.UsesNode;
30
31 public class Bug5942Test {
32     @Test
33     public void test() throws Exception {
34         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5942");
35         assertNotNull(schemaContext);
36
37         final DataSchemaNode root = schemaContext.getDataChildByName(QName.create("foo", "2016-06-02", "root"));
38         assertTrue(root instanceof ContainerSchemaNode);
39
40         final Set<UsesNode> uses = ((ContainerSchemaNode) root).getUses();
41         assertEquals(1, uses.size());
42         final UsesNode usesNode = uses.iterator().next();
43
44         assertEquals(Optional.of("uses description"), usesNode.getDescription());
45         assertEquals(Optional.of("uses reference"), usesNode.getReference());
46         assertEquals(Status.DEPRECATED, usesNode.getStatus());
47
48         final RevisionAwareXPath when = usesNode.getWhenCondition().get();
49         assertFalse(when.isAbsolute());
50         assertThat(when, instanceOf(WithExpression.class));
51         assertEquals("0!=1", when.getOriginalString());
52
53         final List<UnknownSchemaNode> unknownSchemaNodes = usesNode.getUnknownSchemaNodes();
54         assertEquals(1, unknownSchemaNodes.size());
55         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next();
56         assertEquals("argument", unknownSchemaNode.getNodeParameter());
57         assertEquals(QName.create("foo", "2016-06-02", "e"), unknownSchemaNode.getExtensionDefinition().getQName());
58     }
59 }