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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
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;
23 public class Bug9242Test {
26 public void testDeviateReplaceWithUserDefinedTypes() throws Exception {
27 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9242/");
28 assertNotNull(schemaContext);
30 final Date revision = QName.parseRevision("2017-10-13");
32 final Module rootModule = schemaContext.findModule("root-module", revision).get();
33 final Module impModule = schemaContext.findModule("imp-module", revision).get();
35 TypeDefinition<?> deviatedMyLeafType = null;
36 TypeDefinition<?> deviatedMyLeaf2Type = null;
38 for (final Deviation deviation : rootModule.getDeviations()) {
39 if (deviation.getTargetPath().getLastComponent().equals(QName.create(
40 impModule.getQNameModule(), "my-leaf"))) {
41 deviatedMyLeafType = deviation.getDeviates().iterator().next().getDeviatedType();
44 if (deviation.getTargetPath().getLastComponent().equals(QName.create(
45 impModule.getQNameModule(), "my-leaf-2"))) {
46 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
50 assertNotNull(deviatedMyLeafType);
51 assertNotNull(deviatedMyLeaf2Type);
53 final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
54 impModule.getQNameModule(), "my-leaf"));
55 assertSame(deviatedMyLeafType, myLeaf.getType());
57 final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
58 impModule.getQNameModule(), "my-leaf-2"));
59 assertSame(deviatedMyLeaf2Type, myLeaf2.getType());