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.findModuleByName("root-module", revision);
33 final Module impModule = schemaContext.findModuleByName("imp-module", revision);
34 assertNotNull(impModule);
36 TypeDefinition<?> deviatedMyLeafType = null;
37 TypeDefinition<?> deviatedMyLeaf2Type = null;
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();
45 if (deviation.getTargetPath().getLastComponent().equals(QName.create(
46 impModule.getQNameModule(), "my-leaf-2"))) {
47 deviatedMyLeaf2Type = deviation.getDeviates().iterator().next().getDeviatedType();
51 assertNotNull(deviatedMyLeafType);
52 assertNotNull(deviatedMyLeaf2Type);
54 final LeafSchemaNode myLeaf = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
55 impModule.getQNameModule(), "my-leaf"));
56 assertSame(deviatedMyLeafType, myLeaf.getType());
58 final LeafSchemaNode myLeaf2 = (LeafSchemaNode) impModule.getDataChildByName(QName.create(
59 impModule.getQNameModule(), "my-leaf-2"));
60 assertSame(deviatedMyLeaf2Type, myLeaf2.getType());