Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-rfc7950 / 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 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950;
9
10 import static org.hamcrest.Matchers.containsString;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertThat;
13
14 import java.io.ByteArrayOutputStream;
15 import java.io.PrintStream;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
18
19 public class Bug6878Test {
20
21     @Test
22     public void testParsingXPathWithYang11Functions() throws Exception {
23         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo.yang");
24         assertFalse(testLog.contains("Could not find function: "));
25     }
26
27     @Test
28     public void shouldLogInvalidYang10XPath() throws Exception {
29         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid.yang");
30         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
31     }
32
33     @Test
34     public void shouldLogInvalidYang10XPath2() throws Exception {
35         final String testLog = parseAndcaptureLog("/rfc7950/bug6878/foo10-invalid-2.yang");
36         assertThat(testLog, containsString("RFC7950 features required in RFC6020 context to parse expression "));
37     }
38
39     @SuppressWarnings("checkstyle:regexpSinglelineJava")
40     private static String parseAndcaptureLog(final String yangFile) throws Exception {
41         final PrintStream stdout = System.out;
42         final ByteArrayOutputStream output = new ByteArrayOutputStream();
43
44         try (PrintStream out = new PrintStream(output, true, "UTF-8")) {
45             System.setOut(out);
46             StmtTestUtils.parseYangSource(yangFile);
47         } finally {
48             System.setOut(stdout);
49         }
50
51         return output.toString();
52     }
53 }