Merge "Parents pom distribution"
[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.FileInputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.junit.Test;
19 import org.opendaylight.controller.yang.parser.util.YangParseException;
20 import org.opendaylight.controller.yang.parser.util.YangValidationException;
21
22 public class YangParserNegativeTest {
23
24     @Test
25     public void testInvalidImport() throws IOException {
26         try {
27             try (InputStream stream = new FileInputStream(getClass().getResource
28                     ("/negative-scenario/testfile1.yang").getPath())) {
29                 TestUtils.loadModule(stream);
30                 fail("ValidationException should by thrown");
31             }
32         } catch(YangValidationException e) {
33             assertTrue(e.getMessage().contains("Not existing module imported"));
34         }
35     }
36
37     @Test
38     public void testTypeNotFound() throws IOException {
39         try {
40             try (InputStream stream = new FileInputStream(getClass().getResource
41                     ("/negative-scenario/testfile2.yang").getPath())) {
42                 TestUtils.loadModule(stream);
43                 fail("YangParseException should by thrown");
44             }
45         } catch(YangParseException e) {
46             assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found."));
47         }
48     }
49
50     @Test
51     public void testInvalidAugmentTarget() throws IOException {
52         try {
53             final List<InputStream> streams = new ArrayList<>(2);
54             try (InputStream testFile0 = new FileInputStream(getClass().getResource
55                     ("/negative-scenario/testfile0.yang").getPath())) {
56                 streams.add(testFile0);
57                 try (InputStream testFile3 = new FileInputStream(getClass().getResource
58                         ("/negative-scenario/testfile3.yang").getPath())) {
59                     streams.add(testFile3);
60                     assertEquals("Expected loaded files count is 2", 2,
61                             streams.size());
62                     TestUtils.loadModules(streams);
63                     fail("YangParseException should by thrown");
64                 }
65             }
66         } catch(YangParseException e) {
67             assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'."));
68         }
69     }
70
71     @Test
72     public void testInvalidRefine() throws IOException {
73         try {
74             try (InputStream stream = new FileInputStream(getClass().getResource
75                     ("/negative-scenario/testfile4.yang").getPath())) {
76                 TestUtils.loadModule(stream);
77                 fail("YangParseException should by thrown");
78             }
79         } catch(YangParseException e) {
80             assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'."));
81         }
82     }
83
84 }