Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / SameQNamesInChoiceTest.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 java.io.File;
13 import java.net.URI;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.rules.ExpectedException;
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.parser.api.YangContextParser;
20 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
21 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
22
23 public class SameQNamesInChoiceTest {
24
25     @Rule
26     public ExpectedException thrown = ExpectedException.none();
27
28     @Test
29     public void testSameQNameInChoice() throws Exception {
30         thrown.expect(YangParseException.class);
31         thrown.expectMessage("Choice has two nodes case with same qnames");
32
33         SchemaContext context;
34         File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice/two-same-nodes-in-choice-case.yang").toURI());
35         File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice").toURI());
36         YangContextParser parser = new YangParserImpl();
37         context = parser.parseFile(yangFile, dependenciesDir);
38
39         Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:same-nodes-in-choice-case")).iterator().next();
40         assertNotNull(testModule);
41     }
42
43
44     @Test
45     public void testAugmentedNodeIntoChoiceCase() throws Exception {
46         thrown.expect(YangParseException.class);
47         thrown.expectMessage("Choice has two nodes case with same qnames");
48
49         SchemaContext context;
50         File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/augment/two-cases.yang").toURI());
51         File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/augment").toURI());
52         YangContextParser parser = new YangParserImpl();
53         context = parser.parseFile(yangFile, dependenciesDir);
54
55         Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:cases")).iterator().next();
56         assertNotNull(testModule);
57     }
58 }