2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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;
22 public class ListKeysTest {
25 public void correctListKeysTest() throws ReactorException {
27 final StatementStreamSource yangFile = sourceForResource("/list-keys-test/correct-list-keys-test.yang");
29 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
30 reactor.addSources(yangFile);
32 final SchemaContext result = reactor.buildEffective();
33 assertNotNull(result);
37 public void incorrectListKeysTest1() {
39 final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test.yang");
41 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
42 reactor.addSources(yangFile);
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'"));
53 public void incorrectListKeysTest2() {
55 final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test2.yang");
57 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
58 reactor.addSources(yangFile);
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'"));
69 public void incorrectListKeysTest3() {
71 final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test3.yang");
73 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
74 reactor.addSources(yangFile);
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'"));
85 public void incorrectListKeysTest4() {
87 final StatementStreamSource yangFile = sourceForResource("/list-keys-test/incorrect-list-keys-test4.yang");
89 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
90 reactor.addSources(yangFile);
93 reactor.buildEffective();
94 fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced "
96 } catch (ReactorException e) {
97 assertTrue(e.getCause().getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));