YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / 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.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
20
21 public class ListKeysTest {
22
23     @Test
24     public void correctListKeysTest() throws ReactorException {
25         final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
26                 .addSource(sourceForResource("/list-keys-test/correct-list-keys-test.yang"))
27                 .buildEffective();
28         assertNotNull(result);
29     }
30
31     @Test
32     public void incorrectListKeysTest1() {
33         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
34                 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test.yang"));
35         try {
36             reactor.buildEffective();
37             fail("effective build should fail due to list instead of leaf referenced in list key");
38         } catch (ReactorException e) {
39             assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
40         }
41     }
42
43     @Test
44     public void incorrectListKeysTest2() {
45         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
46                 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test2.yang"));
47         try {
48             reactor.buildEffective();
49             fail("effective build should fail due to missing leaf referenced in list key");
50         } catch (ReactorException e) {
51             assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
52         }
53     }
54
55     @Test
56     public void incorrectListKeysTest3() {
57         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
58                 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test3.yang"));
59         try {
60             reactor.buildEffective();
61             fail("effective build should fail due to list instead of leaf in grouping referenced in list key");
62         } catch (ReactorException e) {
63             assertTrue(e.getCause().getMessage().startsWith("Key 'grp_list' misses node 'grp_list'"));
64         }
65     }
66
67     @Test
68     public void incorrectListKeysTest4()  {
69         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
70                 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test4.yang"));
71         try {
72             reactor.buildEffective();
73             fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced "
74                     + "in list key");
75         } catch (ReactorException e) {
76             assertTrue(e.getCause().getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
77         }
78     }
79 }