94cc63d7c694609ef2aef3b0735280bcd57f0241
[yangtools.git] / yang / yang-parser-impl / 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 java.util.Date;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
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 Date revision = QName.parseRevision("2017-10-13");
31
32         final Module rootModule = schemaContext.findModuleByName("root-module", revision);
33         final Module impModule = schemaContext.findModuleByName("imp-module", revision);
34         assertNotNull(impModule);
35
36         TypeDefinition<?> deviatedMyLeafType = null;
37         TypeDefinition<?> deviatedMyLeaf2Type = null;
38
39         for (final Deviation deviation : rootModule.getDeviations()) {
40             if (deviation.getTargetPath().getLastComponent().equals(QName.create(
41                     impModule.getQNameModule(), "my-leaf"))) {
42                 deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
43             }
44
45             if (deviation.getTargetPath().getLastComponent().equals(QName.create(
46                     impModule.getQNameModule(), "my-leaf-2"))) {
47                 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
48             }
49         }
50
51         assertNotNull(deviatedMyLeafType);
52         assertNotNull(deviatedMyLeaf2Type);
53
54         final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
55                 impModule.getQNameModule(), "my-leaf"));
56         assertSame(deviatedMyLeafType, myLeaf.getType());
57
58         final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
59                 impModule.getQNameModule(), "my-leaf-2"));
60         assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
61     }
62 }