Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / Bug2219Test.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.retest;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
17 import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils;
18 import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
19 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
20
21 /**
22  * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder.
23  * NPE occours in private getData method in CopyUtils.java during QName.create.
24  *
25  * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName()
26  * by implementation returns always null.
27  *
28  */
29 public class Bug2219Test {
30
31     private ModuleBuilder moduleBuilder;
32
33     @Before
34     public void init() {
35         moduleBuilder = new ModuleBuilder("test-module", "somePath");
36     }
37
38     @Test
39     public void testCopyIdentityrefTypeBuilder() {
40         final String typedefLocalName = "identity-ref-test-type";
41         final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName);
42         final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
43         final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12,
44             "base:parent-identity", typedefPath);
45
46         final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true);
47         assertNotNull(copy);
48     }
49 }