84578c794ab5a3e83e23a9c3c12a4bb886935a8a
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5712Test.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19
20 public class Bug5712Test {
21
22     @Test
23     public void testTypedefWithNewStatementParser() throws Exception {
24         SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5712");
25         assertNotNull(schemaContext);
26
27         Module badModule = schemaContext.findModules("bad").iterator().next();
28         assertNotNull(badModule);
29         checkThing2TypeDef(badModule);
30     }
31
32     private static void checkThing2TypeDef(final Module badModule) {
33         TypeDefinition<?> thing2 = null;
34         for (TypeDefinition<?> typeDef : badModule.getTypeDefinitions()) {
35             if (typeDef.getQName().getLocalName().equals("thing2")) {
36                 thing2 = typeDef;
37                 break;
38             }
39         }
40
41         assertNotNull(thing2);
42         TypeDefinition<?> baseType = thing2.getBaseType();
43         assertEquals(QName.create("urn:opendaylight:bad", "2016-04-11", "thing"), baseType.getQName());
44     }
45 }