Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / KeyTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt;
10
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;
15
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
22 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
23
24 public class KeyTest {
25
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");
30
31     @Test
32     public void keySimpleTest() throws ReactorException {
33         EffectiveModelContext result = RFC7950Reactors.defaultReactor().newBuild()
34                 .addSource(KEY_SIMPLE_AND_COMP)
35                 .build();
36         assertNotNull(result);
37     }
38
39     @Test
40     public void keyCompositeInvalid() {
41         BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild().addSource(KEY_COMP_DUPLICATE);
42         try {
43             reactor.build();
44             fail("reactor.process should fail due to duplicate name in key");
45         } catch (ReactorException e) {
46             final Throwable cause = e.getCause();
47             assertTrue(cause instanceof SourceException);
48             assertTrue(cause.getMessage().startsWith("Key argument 'key1 key2 key2' contains duplicates"));
49         }
50     }
51 }