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