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.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 public class Bug9242Test {
25 public void testDeviateReplaceWithUserDefinedTypes() throws Exception {
26 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9242/");
27 assertNotNull(schemaContext);
29 final Revision revision = Revision.of("2017-10-13");
30 final Module rootModule = schemaContext.findModule("root-module", revision).get();
31 final Module impModule = schemaContext.findModule("imp-module", revision).get();
33 TypeDefinition<?> deviatedMyLeafType = null;
34 TypeDefinition<?> deviatedMyLeaf2Type = null;
36 for (final Deviation deviation : rootModule.getDeviations()) {
37 final QName last = Iterables.getLast(deviation.getTargetPath().getNodeIdentifiers());
38 if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf"))) {
39 deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
42 if (last.equals(QName.create(impModule.getQNameModule(), "my-leaf-2"))) {
43 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
47 assertNotNull(deviatedMyLeafType);
48 assertNotNull(deviatedMyLeaf2Type);
50 final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
51 impModule.getQNameModule(), "my-leaf"));
52 assertSame(deviatedMyLeafType, myLeaf.getType());
54 final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
55 impModule.getQNameModule(), "my-leaf-2"));
56 assertSame(deviatedMyLeaf2Type, myLeaf2.getType());