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.impl.DefaultReactors;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
21 public class ListKeysTest {
24 public void correctListKeysTest() throws ReactorException {
25 final SchemaContext result = DefaultReactors.defaultReactor().newBuild()
26 .addSource(sourceForResource("/list-keys-test/correct-list-keys-test.yang"))
28 assertNotNull(result);
32 public void incorrectListKeysTest1() {
33 BuildAction reactor = DefaultReactors.defaultReactor().newBuild()
34 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test.yang"));
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'"));
44 public void incorrectListKeysTest2() {
45 BuildAction reactor = DefaultReactors.defaultReactor().newBuild()
46 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test2.yang"));
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'"));
56 public void incorrectListKeysTest3() {
57 BuildAction reactor = DefaultReactors.defaultReactor().newBuild()
58 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test3.yang"));
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'"));
68 public void incorrectListKeysTest4() {
69 BuildAction reactor = DefaultReactors.defaultReactor().newBuild()
70 .addSource(sourceForResource("/list-keys-test/incorrect-list-keys-test4.yang"));
72 reactor.buildEffective();
73 fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced "
75 } catch (ReactorException e) {
76 assertTrue(e.getCause().getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));