Fix checkstyle in yang-parser-impl and enable enforcement
[yangtools.git] / yang / yang-parser-impl / 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.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
21
22 public class ListKeysTest {
23
24     @Test
25     public void correctListKeysTest() throws ReactorException {
26
27         final StatementStreamSource yangFile = sourceForResource("/list-keys-test/correct-list-keys-test.yang");
28
29         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
30         reactor.addSources(yangFile);
31
32         final SchemaContext result = reactor.buildEffective();
33         assertNotNull(result);
34     }
35
36     @Test
37     public void incorrectListKeysTest1() {
38
39         final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test.yang");
40
41         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
42         reactor.addSources(yangFile);
43
44         try {
45             reactor.buildEffective();
46             fail("effective build should fail due to list instead of leaf referenced in list key");
47         } catch (ReactorException e) {
48             assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
49         }
50     }
51
52     @Test
53     public void incorrectListKeysTest2() {
54
55         final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test2.yang");
56
57         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
58         reactor.addSources(yangFile);
59
60         try {
61             reactor.buildEffective();
62             fail("effective build should fail due to missing leaf referenced in list key");
63         } catch (ReactorException e) {
64             assertTrue(e.getCause().getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
65         }
66     }
67
68     @Test
69     public void incorrectListKeysTest3() {
70
71         final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test3.yang");
72
73         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
74         reactor.addSources(yangFile);
75
76         try {
77             reactor.buildEffective();
78             fail("effective build should fail due to list instead of leaf in grouping referenced in list key");
79         } catch (ReactorException e) {
80             assertTrue(e.getCause().getMessage().startsWith("Key 'grp_list' misses node 'grp_list'"));
81         }
82     }
83
84     @Test
85     public void incorrectListKeysTest4()  {
86
87         final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test4.yang");
88
89         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
90         reactor.addSources(yangFile);
91
92         try {
93             reactor.buildEffective();
94             fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced "
95                     + "in list key");
96         } catch (ReactorException e) {
97             assertTrue(e.getCause().getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
98         }
99     }
100 }