Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / ListKeysTest.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.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertThrows;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18
19 public class ListKeysTest {
20     @Test
21     public void correctListKeysTest() throws Exception {
22         StmtTestUtils.parseYangSource("/list-keys-test/correct-list-keys-test.yang");
23     }
24
25     @Test
26     public void incorrectListKeysTest1() {
27         final ReactorException ex = assertThrows(ReactorException.class,
28             () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test.yang"));
29         final Throwable cause = ex.getCause();
30         assertThat(cause, instanceOf(SourceException.class));
31         assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
32     }
33
34     @Test
35     public void incorrectListKeysTest2() {
36         final ReactorException ex = assertThrows(ReactorException.class,
37             () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test2.yang"));
38         final Throwable cause = ex.getCause();
39         assertThat(cause, instanceOf(SourceException.class));
40         assertThat(cause.getMessage(), startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
41     }
42
43     @Test
44     public void incorrectListKeysTest3() {
45         final ReactorException ex = assertThrows(ReactorException.class,
46             () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test3.yang"));
47         final Throwable cause = ex.getCause();
48         assertThat(cause, instanceOf(SourceException.class));
49         assertThat(cause.getMessage(), startsWith("Key 'grp_list' misses node 'grp_list'"));
50     }
51
52     @Test
53     public void incorrectListKeysTest4()  {
54         final ReactorException ex = assertThrows(ReactorException.class,
55             () -> StmtTestUtils.parseYangSource("/list-keys-test/incorrect-list-keys-test4.yang"));
56         final Throwable cause = ex.getCause();
57         assertThat(cause, instanceOf(SourceException.class));
58         assertThat(cause.getMessage(), startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
59     }
60 }