Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug4933Test.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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.hamcrest.Matchers.isA;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertThat;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
16
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.Module;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24
25 public class Bug4933Test {
26
27     @Test
28     public void test() throws Exception {
29         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4933/correct");
30         assertNotNull(context);
31
32         final Module foo = context.findModules("foo").iterator().next();
33         Set<Deviation> deviations = foo.getDeviations();
34         assertEquals(4, deviations.size());
35     }
36
37     @Test
38     public void incorrectKeywordTest() throws Exception {
39         try {
40             StmtTestUtils.parseYangSources("/bugs/bug4933/incorrect");
41             fail("ReactorException should be thrown.");
42         } catch (ReactorException e) {
43             final Throwable cause = e.getCause();
44             assertThat(cause, isA(SourceException.class));
45             assertTrue(cause.getMessage().startsWith("String 'not_supported' is not valid deviate argument"));
46         }
47     }
48 }