Further cleanups of code
[yangtools.git] / yang / yang-parser-impl / 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 import java.io.FileNotFoundException;
14 import java.net.URISyntaxException;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22
23 public class Bug5712Test {
24
25     @Test
26     public void testTypedefWithNewStatementParser() throws ReactorException, SourceException, FileNotFoundException,
27             URISyntaxException {
28         SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug5712");
29         assertNotNull(schemaContext);
30
31         Module badModule = schemaContext.findModuleByName("bad", null);
32         assertNotNull(badModule);
33
34         checkThing2TypeDef(badModule);
35     }
36
37     private static void checkThing2TypeDef(final Module badModule) {
38         TypeDefinition<?> thing2 = null;
39         for (TypeDefinition<?> typeDef : badModule.getTypeDefinitions()) {
40             if (typeDef.getQName().getLocalName().equals("thing2")) {
41                 thing2 = typeDef;
42                 break;
43             }
44         }
45
46         assertNotNull(thing2);
47         TypeDefinition<?> baseType = thing2.getBaseType();
48         assertEquals(QName.create("urn:opendaylight:bad", "2016-04-11", "thing"), baseType.getQName());
49     }
50 }