2 * Copyright (c) 2015 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.retest;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
24 public class ListKeysTest {
27 public void correctListKeysTest() throws ReactorException {
29 final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
30 "/list-keys-test/correct-list-keys-test.yang", false);
32 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
33 addSources(reactor, yangFile);
35 final EffectiveSchemaContext result = reactor.buildEffective();
36 assertNotNull(result);
40 public void incorrectListKeysTest1() throws IOException, YangSyntaxErrorException, URISyntaxException {
42 final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
43 "/list-keys-test/incorrect-list-keys-test.yang", false);
45 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46 addSources(reactor, yangFile);
49 reactor.buildEffective();
50 fail("effective build should fail due to list instead of leaf referenced in list key");
51 } catch (Exception e) {
52 assertEquals(IllegalArgumentException.class, e.getClass());
53 assertTrue(e.getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
58 public void incorrectListKeysTest2() throws IOException, YangSyntaxErrorException, URISyntaxException {
60 final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
61 "/list-keys-test/incorrect-list-keys-test2.yang", false);
63 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
64 addSources(reactor, yangFile);
67 reactor.buildEffective();
68 fail("effective build should fail due to missing leaf referenced in list key");
69 } catch (Exception e) {
70 assertEquals(IllegalArgumentException.class, e.getClass());
71 assertTrue(e.getMessage().startsWith("Key 'test1_key1 test1_key2' misses node 'test1_key2'"));
76 public void incorrectListKeysTest3() throws IOException, YangSyntaxErrorException, URISyntaxException {
78 final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
79 "/list-keys-test/incorrect-list-keys-test3.yang", false);
81 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
82 addSources(reactor, yangFile);
85 reactor.buildEffective();
86 fail("effective build should fail due to list instead of leaf in grouping referenced in list key");
87 } catch (Exception e) {
88 assertEquals(IllegalArgumentException.class, e.getClass());
89 assertTrue(e.getMessage().startsWith("Key 'grp_list' misses node 'grp_list'"));
94 public void incorrectListKeysTest4() throws IOException, YangSyntaxErrorException, URISyntaxException {
96 final YangStatementSourceImpl yangFile = new YangStatementSourceImpl(
97 "/list-keys-test/incorrect-list-keys-test4.yang", false);
99 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
100 addSources(reactor, yangFile);
103 reactor.buildEffective();
104 fail("effective build should fail due to list instead of leaf in grouping augmented to list referenced in list key");
105 } catch (Exception e) {
106 assertEquals(IllegalArgumentException.class, e.getClass());
107 assertTrue(e.getMessage().startsWith("Key 'grp_leaf' misses node 'grp_leaf'"));
111 private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final YangStatementSourceImpl... sources) {
112 for (YangStatementSourceImpl source : sources) {
113 reactor.addSource(source);