Bug 8307: Add the option for activating deviation statements
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug4933Test.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 package org.opendaylight.yangtools.yang.stmt;
9
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
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.model.api.Deviation;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
22
23 public class Bug4933Test {
24
25     @Test
26     public void test() throws Exception {
27         SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug4933/correct");
28         assertNotNull(context);
29
30         final Module foo = context.findModuleByName("foo", null);
31
32         Set<Deviation> deviations = foo.getDeviations();
33         assertEquals(4, deviations.size());
34     }
35
36     @Test
37     public void incorrectKeywordTest() throws Exception {
38         try {
39             StmtTestUtils.parseYangSources("/bugs/bug4933/incorrect");
40             fail("ReactorException should be thrown.");
41         } catch (ReactorException e) {
42             final Throwable cause = e.getCause();
43             assertTrue(cause instanceof SourceException);
44             assertTrue(cause.getMessage().startsWith("String 'not_supported' is not valid deviate argument"));
45         }
46     }
47 }