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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
24 public class KeyTest {
26 private static final StatementStreamSource KEY_SIMPLE_AND_COMP = sourceForResource(
27 "/semantic-statement-parser/key-arg-parsing/key-simple-and-comp.yang");
28 private static final StatementStreamSource KEY_COMP_DUPLICATE = sourceForResource(
29 "/semantic-statement-parser/key-arg-parsing/key-comp-duplicate.yang");
32 public void keySimpleTest() throws ReactorException {
34 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
35 reactor.addSources(KEY_SIMPLE_AND_COMP);
37 EffectiveModelContext result = reactor.build();
38 assertNotNull(result);
42 public void keyCompositeInvalid() {
44 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
45 reactor.addSources(KEY_COMP_DUPLICATE);
49 fail("reactor.process should fail due to duplicate name in key");
50 } catch (ReactorException e) {
51 final Throwable cause = e.getCause();
52 assertTrue(cause instanceof SourceException);
53 assertTrue(cause.getMessage().startsWith("Key argument 'key1 key2 key2' contains duplicates"));