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
9 package org.opendaylight.yangtools.yang.stmt.test.key;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
13 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
14 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
15 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
18 import static org.junit.Assert.*;
20 public class KeyTest {
22 private static final TestKeySource KEY_SIMPLE = new TestKeySource("root", "key");
23 private static final TestKeySource KEY_COMP = new TestKeySource("root", "key1 key2 key3");
24 private static final TestKeySource KEY_COMP_DUPLICATE = new TestKeySource("root", "key1 key1 key2");
27 public void keySimpleTest() throws SourceException, ReactorException {
29 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
30 addSources(reactor, KEY_SIMPLE);
32 EffectiveModelContext result = reactor.build();
33 assertNotNull(result);
37 public void keyCompositeTest() throws SourceException, ReactorException {
39 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
40 addSources(reactor, KEY_COMP);
42 EffectiveModelContext result = reactor.build();
43 assertNotNull(result);
47 public void keyCompositeInvalid() throws SourceException, ReactorException {
49 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
50 addSources(reactor, KEY_COMP_DUPLICATE);
54 fail("reactor.process should fail due to duplicate name in key");
55 } catch (Exception e) {
56 assertEquals(IllegalArgumentException.class, e.getClass());
60 private void addSources(BuildAction reactor, TestKeySource... sources) {
61 for (TestKeySource source : sources) {
62 reactor.addSource(source);