Further cleanup of tests
[yangtools.git] / parser / 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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertSame;
12
13 import com.google.common.collect.Iterables;
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.TypeDefinition;
21
22 public class Bug9242Test extends AbstractYangTest {
23     @Test
24     public void testDeviateReplaceWithUserDefinedTypes() {
25         final var schemaContext = assertEffectiveModelDir("/bugs/bug9242/");
26
27         final Revision revision = Revision.of("2017-10-13");
28         final Module rootModule = schemaContext.findModule("root-module", revision).orElseThrow();
29         final Module impModule = schemaContext.findModule("imp-module", revision).orElseThrow();
30
31         TypeDefinition<?> deviatedMyLeafType = null;
32         TypeDefinition<?> deviatedMyLeaf2Type = null;
33
34         for (final Deviation deviation : rootModule.getDeviations()) {
35             final QName last = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers());
36             if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf"))) {
37                 deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
38             }
39
40             if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf-2"))) {
41                 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
42             }
43         }
44
45         assertNotNull(deviatedMyLeafType);
46         assertNotNull(deviatedMyLeaf2Type);
47
48         final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
49                 impModule.getQNameModule(), "my-leaf"));
50         assertSame(deviatedMyLeafType, myLeaf.getType());
51
52         final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
53                 impModule.getQNameModule(), "my-leaf-2"));
54         assertSame(deviatedMyLeaf2Type, myLeaf2.getType());
55     }
56 }