Merge "Refactored ModuleBuilder to avoid name conflicts. Fixed implementation of...
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / parser / impl / YangParserNegativeTest.java
1 /*
2  * Copyright (c) 2013 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.controller.yang.parser.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.io.IOException;
13
14 import org.junit.Test;
15 import org.opendaylight.controller.yang.parser.util.YangParseException;
16 import org.opendaylight.controller.yang.parser.util.YangValidationException;
17
18 public class YangParserNegativeTest {
19
20     @Test
21     public void testInvalidImport() throws IOException {
22         try {
23             TestUtils.loadModule("/negative-scenario/testfile1.yang");
24             fail("ValidationException should by thrown");
25         } catch(YangValidationException e) {
26             assertTrue(e.getMessage().contains("Not existing module imported"));
27         }
28     }
29
30     @Test
31     public void testTypeNotFound() throws IOException {
32         try {
33             TestUtils.loadModule("/negative-scenario/testfile2.yang");
34             fail("YangParseException should by thrown");
35         } catch(YangParseException e) {
36             assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found."));
37         }
38     }
39
40     @Test
41     public void testInvalidAugmentTarget() throws IOException {
42         try {
43             TestUtils.loadModules("/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
44             fail("YangParseException should by thrown");
45         } catch(YangParseException e) {
46             assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'."));
47         }
48     }
49
50     @Test
51     public void testInvalidRefine() throws IOException {
52         try {
53             TestUtils.loadModule("/negative-scenario/testfile4.yang");
54             fail("YangParseException should by thrown");
55         } catch(YangParseException e) {
56             assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'."));
57         }
58     }
59
60 }