Migrate assertThat() import
[yangtools.git] / yang / yang-model-util-ut / src / test / java / org / opendaylight / yangtools / yang / model / util / ut / YT1050Test.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.model.util.ut;
9
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertSame;
13
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
25 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27
28 public class YT1050Test {
29     private static final QName SECONDARY = QName.create("yt1050", "secondary");
30     private static final QName TYPE = QName.create(SECONDARY, "type");
31     private static final QName GRP_USES = QName.create(SECONDARY, "grp-uses");
32
33     private EffectiveModelContext context;
34     private LeafSchemaNode secondaryType;
35     private LeafSchemaNode primaryType;
36     private Module module;
37
38     @Before
39     public void before() {
40         context = YangParserTestUtils.parseYangResource("/yt1050.yang");
41         module = context.getModules().iterator().next();
42
43         final ListSchemaNode grpUses = (ListSchemaNode) module.findDataChildByName(GRP_USES).get();
44         primaryType = (LeafSchemaNode) grpUses.findDataChildByName(TYPE).get();
45
46         final GroupingDefinition grp = module.getGroupings().iterator().next();
47         secondaryType = (LeafSchemaNode) ((ListSchemaNode) grp.findDataChildByName(SECONDARY).get())
48                 .findDataChildByName(TYPE).get();
49     }
50
51     @Test
52     public void testFindDataSchemaNodeForRelativeXPathWithDeref() {
53         final TypeDefinition<?> typeNodeType = secondaryType.getType();
54         assertThat(typeNodeType, isA(LeafrefTypeDefinition.class));
55
56         final SchemaNode found =  SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, secondaryType,
57             ((LeafrefTypeDefinition) typeNodeType).getPathStatement());
58         assertSame(primaryType, found);
59     }
60 }