Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / stmt / rfc7950 / Bug6878Test.java
1 /*
2  * Copyright (c) 2017 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.parser.stmt.rfc7950;
10
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.io.ByteArrayOutputStream;
16 import java.io.PrintStream;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
20
21 public class Bug6878Test {
22
23     @Test
24     @SuppressWarnings("checkstyle:regexpSinglelineJava")
25     public void testParsingXPathWithYang11Functions() throws Exception {
26         final PrintStream stdout = System.out;
27         final ByteArrayOutputStream output = new ByteArrayOutputStream();
28         final String testLog;
29
30         System.setOut(new PrintStream(output, true, "UTF-8"));
31
32         final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo.yang");
33         assertNotNull(schemaContext);
34
35         testLog = output.toString();
36         assertFalse(testLog.contains("Could not find function: "));
37         System.setOut(stdout);
38     }
39
40     @Test
41     @SuppressWarnings("checkstyle:regexpSinglelineJava")
42     public void shouldLogInvalidYang10XPath() throws Exception {
43         final PrintStream stdout = System.out;
44         final ByteArrayOutputStream output = new ByteArrayOutputStream();
45         final String testLog;
46
47         System.setOut(new PrintStream(output, true, "UTF-8"));
48
49         StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo10-invalid.yang");
50
51         testLog = output.toString();
52         assertTrue(testLog.contains("Could not find function: re-match"));
53         System.setOut(stdout);
54     }
55
56     @Test
57     @SuppressWarnings("checkstyle:regexpSinglelineJava")
58     public void shouldLogInvalidYang10XPath2() throws Exception {
59         final PrintStream stdout = System.out;
60         final ByteArrayOutputStream output = new ByteArrayOutputStream();
61         final String testLog;
62
63         System.setOut(new PrintStream(output, true, "UTF-8"));
64
65         StmtTestUtils.parseYangSource("/rfc7950/bug6878/foo10-invalid-2.yang");
66
67         testLog = output.toString();
68         assertTrue(testLog.contains("Could not find function: deref"));
69         System.setOut(stdout);
70     }
71 }