2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertSame;
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;
22 public class Bug9242Test extends AbstractYangTest {
24 public void testDeviateReplaceWithUserDefinedTypes() {
25 final var schemaContext = assertEffectiveModelDir("/bugs/bug9242/");
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();
31 TypeDefinition<?> deviatedMyLeafType = null;
32 TypeDefinition<?> deviatedMyLeaf2Type = null;
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();
40 if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf-2"))) {
41 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
45 assertNotNull(deviatedMyLeafType);
46 assertNotNull(deviatedMyLeaf2Type);
48 final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
49 impModule.getQNameModule(), "my-leaf"));
50 assertSame(deviatedMyLeafType, myLeaf.getType());
52 final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
53 impModule.getQNameModule(), "my-leaf-2"));
54 assertSame(deviatedMyLeaf2Type, myLeaf2.getType());