YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug9242Test.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies 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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Revision;
17 import org.opendaylight.yangtools.yang.model.api.Deviation;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22
23 public class Bug9242Test {
24
25     @Test
26     public void testDeviateReplaceWithUserDefinedTypes() throws Exception {
27         final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9242/");
28         assertNotNull(schemaContext);
29
30         final Revision revision = Revision.of("2017-10-13");
31         final Module rootModule = schemaContext.findModule("root-module", revision).get();
32         final Module impModule = schemaContext.findModule("imp-module", revision).get();
33
34         TypeDefinition<?> deviatedMyLeafType = null;
35         TypeDefinition<?> deviatedMyLeaf2Type = null;
36
37         for (final Deviation deviation : rootModule.getDeviations()) {
38             if (deviation.getTargetPath().getLastComponent().equals(QName.create(
39                     impModule.getQNameModule(), "my-leaf"))) {
40                 deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
41             }
42
43             if (deviation.getTargetPath().getLastComponent().equals(QName.create(
44                     impModule.getQNameModule(), "my-leaf-2"))) {
45                 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
46             }
47         }
48
49         assertNotNull(deviatedMyLeafType);
50         assertNotNull(deviatedMyLeaf2Type);
51
52         final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
53                 impModule.getQNameModule(), "my-leaf"));
54         assertSame(deviatedMyLeafType, myLeaf.getType());
55
56         final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
57                 impModule.getQNameModule(), "my-leaf-2"));
58         assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
59     }
60 }