Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / Bug4933Test.java
1 /*
2  * Copyright (c) 2015 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.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
17 import java.util.Set;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.model.api.Deviation;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23
24 public class Bug4933Test {
25
26     @Test
27     public void test() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
28         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4933/correct");
29         assertNotNull(context);
30
31         Set<Deviation> deviations = context.getModules().iterator().next().getDeviations();
32         assertEquals(4, deviations.size());
33     }
34
35     @Test
36     public void incorrectKeywordTest() throws SourceException, ReactorException, FileNotFoundException,
37             URISyntaxException {
38         try {
39             StmtTestUtils.parseYangSources("/bugs/bug4933/incorrect");
40             fail("NullPointerException should be thrown.");
41         } catch (NullPointerException e) {
42             assertTrue(e.getMessage().startsWith("String 'not_supported' is not valid deviate argument. Statement source at"));
43         }
44     }
45 }