604084d73df6dba60e647a6c5d1d204e3f0a614f
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug5693Test.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.File;
15 import java.io.FileNotFoundException;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
21
22 public class Bug5693Test {
23
24     private final String pathToModuleFoo = getClass().getResource("/bugs/bug5693/foo.yin").getPath();
25     private Module foo;
26
27     /**
28      * Use input stream to load Yin module.
29      */
30     @Before
31     public void initTest() throws FileNotFoundException, ReactorException {
32         foo = TestUtils.loadYinModule(new NamedFileInputStream(new File(pathToModuleFoo), pathToModuleFoo));
33         assertNotNull(foo);
34     }
35
36     /**
37      * Test presence of testing feature (parsed in the last phase), if it is present then parsing was successful.
38      * Meaning that stream was not closed after the first parsing phase.
39      */
40     @Test
41     public void bug5693Test() {
42         assertNotNull(foo.getFeatures());
43         assertEquals("Module should has exactly one feature", 1, foo.getFeatures().size());
44         assertEquals("Present feature should has expected local name", "test-input-stream-not-closed",
45                 foo.getFeatures().iterator().next().getQName().getLocalName());
46     }
47 }